Cons

public protocol Cons

Cons provides a Prism between this structure and a pair containing its first element and its tail. It provides a convenient way to attach or detach elements to the left side of a structure.

  • Undocumented

    Declaration

    Swift

    associatedtype First
  • Provides a Prism between this structure and its first element and tail.

    Declaration

    Swift

    static var cons: Prism<Self, (First, Self)> { get }
  • firstOption Extension method

    Provides an Optional between this structure and its first element.

    Declaration

    Swift

    static var firstOption: Optional<Self, First> { get }
  • tailOption Extension method

    Provides an Optional between this structure and its tail.

    Declaration

    Swift

    static var tailOption: Optional<Self, Self> { get }
  • cons(_:) Extension method

    Pre-composes the cons Prism with a given isomorphism.

    Declaration

    Swift

    static func cons<B>(_ iso: Iso<B, Self>) -> Prism<B, (First, B)>

    Parameters

    iso

    An isomorphism.

    Return Value

    A prism that provides the first element and tail in another structure resulting from transforming this structure with the provided isomorphism.

  • cons(_:) Extension method

    Post-composes the cons `Prismp with a given isomorphism.

    Declaration

    Swift

    static func cons<B>(_ iso: Iso<First, B>) -> Prism<Self, (B, Self)>

    Parameters

    iso

    An isomorphism.

    Return Value

    A prism that provides the first element and tail of this structure, where the element has been transformed with the provided isomorphism.

  • prepend(_:) Extension method

    Prepends an element at the left of this structure.

    Declaration

    Swift

    func prepend(_ a: First) -> Self

    Parameters

    a

    Element to prepend.

    Return Value

    A new structure where the provided element is at the initial position.

  • uncons Extension method

    Deconstructs this structure into an optional tuple of its first element and its tail.

    Declaration

    Swift

    var uncons: Option<(First, Self)> { get }