NonEmptyArray

public final class NonEmptyArray<A> : NonEmptyArrayOf<A>

A NonEmptyArray is an array of elements that guarantees to have at least one element.

  • First element of the array.

    Declaration

    Swift

    public let head: A
  • Elements of the array, excluding the firs one.

    Declaration

    Swift

    public let tail: [A]
  • Concatenates two non-empty arrays.

    Declaration

    Swift

    public static func + (lhs: NonEmptyArray<A>, rhs: NonEmptyArray<A>) -> NonEmptyArray<A>

    Parameters

    lhs

    Left hand side of the concatenation.

    rhs

    Right hand side of the concatenation.

    Return Value

    A non-empty array that contains the elements of the two arguments in the same order.

  • Concatenates a non-empty array with a Swift array.

    Declaration

    Swift

    public static func + (lhs: NonEmptyArray<A>, rhs: [A]) -> NonEmptyArray<A>

    Parameters

    lhs

    A non-empty array.

    rhs

    A Swift array.

    Return Value

    A non-empty array that contains the elements of the two arguments in the same order.

  • Appends an element to a non-empty array.

    Declaration

    Swift

    public static func + (lhs: NonEmptyArray<A>, rhs: A) -> NonEmptyArray<A>

    Parameters

    lhs

    A non-empty array.

    rhs

    An element.

    Return Value

    A non-empty array that has the new element at the end.

  • Creates a non-empty array from several values.

    Declaration

    Swift

    public static func of(_ head: A, _ tail: A...) -> NonEmptyArray<A>

    Parameters

    head

    First element for the non-empty array.

    tail

    Variable number of values for the rest of the non-empty array.

    Return Value

    A non-empty array that contains all elements in the specified order.

  • Creates a non-empty array from a Swift array.

    Declaration

    Swift

    public static func fromArray(_ array: [A]) -> Option<NonEmptyArray<A>>

    Parameters

    array

    A Swift array.

    Return Value

    An optional non-empty array with the contents of the argument, or Option.none if it was empty.

  • Unsafely creates a non-empty array from a Swift array.

    This function may cause a fatal error if the argument is an empty error.

    Declaration

    Swift

    public static func fromArrayUnsafe(_ array: [A]) -> NonEmptyArray<A>

    Parameters

    array

    A Swift array.

    Return Value

    A non-empty array with the contents of the argument.

  • Safe downcast.

    Declaration

    Swift

    public static func fix(_ fa: NonEmptyArrayOf<A>) -> NonEmptyArray<A>

    Parameters

    fa

    Value in higher-kind form.

    Return Value

    Value cast to NonEmptyArray.

  • Initializes a non-empty array.

    Declaration

    Swift

    public init(head: A, tail: [A])

    Parameters

    head

    First element for the array.

    tail

    An array with the rest of elements.

  • Obtains a Swift array with the elements in this value.

    Declaration

    Swift

    public func all() -> [A]

    Return Value

    A Swift array with the elements in this value.

  • Obtains an element from its position in this non-empty array.

    Declaration

    Swift

    public func getOrNone(_ i: Int) -> Option<A>

    Parameters

    i

    Index of the object to obtain.

    Return Value

    An optional value with the object at the indicated position, if any.

  • Obtains an element from its position in this non-empty array.

    Declaration

    Swift

    public subscript(index: Int) -> Option<A> { get }

    Parameters

    index

    Index of the object to obtain.

  • Provides an Iso to go from/to this type to its Kind version.

    Declaration

    Swift

    static var fixIso: Iso<NEA<A>, NonEmptyArrayOf<A>> { get }
  • Provides a Fold based on the Foldable instance of this type.

    Declaration

    Swift

    static var fold: Fold<NEA<A>, A> { get }
  • Provides a Traversal based on the Traverse instance of this type.

    Declaration

    Swift

    static var traversal: Traversal<NEA<A>, A> { get }
  • Undocumented

    Declaration

    Swift

    public typealias EachFoci = A
  • Declaration

    Swift

    public static var each: Traversal<NonEmptyArray<A>, A> { get }
  • Undocumented

    Declaration

    Swift

    public typealias IndexType = Int
  • Undocumented

    Declaration

    Swift

    public typealias IndexFoci = A
  • Declaration

    Swift

    public static func index(_ i: Int) -> AffineTraversal<NonEmptyArray<A>, A>
  • Undocumented

    Declaration

    Swift

    public typealias FilterIndexType = Int
  • Undocumented

    Declaration

    Swift

    public typealias FilterIndexFoci = A
  • Declaration

    Swift

    public static func filter(_ predicate: @escaping (Int) -> Bool) -> Traversal<NonEmptyArray<A>, A>
  • Provides a lens between a NonEmptyArray and its head.

    Declaration

    Swift

    static var headLens: Lens<NonEmptyArray<A>, A> { get }
  • Provides a lens between a NonEmptyArray and its tail.

    Declaration

    Swift

    static var tailLens: Lens<NonEmptyArray<A>, [A]> { get }
  • Checks if an element appears in this array.

    Declaration

    Swift

    func contains(element: A) -> Bool

    Parameters

    element

    Element to look for in the array.

    Return Value

    Boolean value indicating if the element appears in the array or not.

  • Checks if all the elements of an array appear in this array.

    Declaration

    Swift

    func containsAll(elements: [A]) -> Bool

    Parameters

    elements

    Elements to look for in the array.

    Return Value

    Boolean value indicating if all elements appear in the array or not.

  • Declaration

    Swift

    public var description: String { get }
  • Declaration

    Swift

    public func combine(_ other: NonEmptyArray<A>) -> NonEmptyArray<A>