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.

  • Undocumented

    Declaration

    Swift

    public static func head() -> Lens<NonEmptyArray<A>, A>
  • Undocumented

    Declaration

    Swift

    public static func tail() -> Lens<NonEmptyArray<A>, [A]>
  • Checks if an element appears in this array.

    Declaration

    Swift

    public 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

    public 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>