Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is because Swift is quite low-level when it comes to storage etc., so [0..<n] returns an ArraySlice.

However, this has nothing to do with generics.If you're willing to sacrifice performance, you could easily write

  extension Array {
      func take(_ n: Int) -> [Element] {
          Array(self[0..<n])
      }
  }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: