Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

array-first (Swift)

Get the first element or first n elements of an array. Swift port of js-array-first-clone.

Usage

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"]

API

  • first<T>(_ array: [T]) -> T? — Returns the first element, or nil if empty.
  • first<T>(_ array: [T], n: Int) -> [T]? — Returns the first n elements (single element in array if n is 1). Returns nil if array is empty.

Running tests

swift test

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages