Get the first element or first n elements of an array. Swift port of js-array-first-clone.
import ArrayFirst
let arr = ["a", "b", "c", "d", "e", "f"]
ArrayFirst.first(arr)
// => "a"
ArrayFirst.first(arr, n: 1)
// => ["a"]
ArrayFirst.first(arr, n: 3)
// => ["a", "b", "c"]first<T>(_ array: [T]) -> T?— Returns the first element, ornilif empty.first<T>(_ array: [T], n: Int) -> [T]?— Returns the firstnelements (single element in array if n is 1). Returnsnilif array is empty.
swift testMIT