Zipper

public final class Zipper<A> : ZipperOf<A>

A Zipper is an array of elements focused on a specific element, which lets us move the focus around the array, and retrieve the elements to the left and right of the focus.

  • Undocumented

    Declaration

    Swift

    public let left: [A]
  • Undocumented

    Declaration

    Swift

    public let focus: A
  • Undocumented

    Declaration

    Swift

    public let right: [A]
  • Safe downcast.

    Declaration

    Swift

    public static func fix(_ value: ZipperOf<A>) -> Zipper<A>

    Parameters

    value

    Value in the higher-kind form.

    Return Value

    Value cast to Zipper.

  • Initializes a Zipper.

    Declaration

    Swift

    public init(left: [A], focus: A, right: [A])

    Parameters

    left

    Elements to the left of the focus.

    focus

    Focused element.

    right

    Elements to the right of the focus.

  • Initializes a Zipper from a NonEmptyArray, focused on the head of the array.

    Declaration

    Swift

    public init(fromNEA array: NonEmptyArray<A>)

    Parameters

    array

    NonEmptyArray to initialize the Zipper.

  • Initializes a Zipper form an Array, focused on the head of the array. If the array is empty, the result will be nil.

    Declaration

    Swift

    public convenience init?(fromArray array: [A])

    Parameters

    array

    Array to initialize the Zipper.

  • Moves the focus one step to the left. If it is already in the leftmost position, it does nothing.

    Declaration

    Swift

    public func moveLeft() -> Zipper<A>

    Return Value

    A Zipper that is focused on one element to the left of the current focus.

  • Moves the focus one step to the right. If it is already in the rightmost position, it does nothing.

    Declaration

    Swift

    public func moveRight() -> Zipper<A>

    Return Value

    A Zipper that is focused on one element to the right of the current focus.

  • Moves the focus to the leftmost position.

    Declaration

    Swift

    public func moveToFirst() -> Zipper<A>

    Return Value

    A Zipper that is focused on the leftmost position.

  • Moves the focus to the rightmost position.

    Declaration

    Swift

    public func moveToLast() -> Zipper<A>

    Return Value

    A Zipper that is focused on the rightmost position.

  • Converts this Zipper to an Array.

    Declaration

    Swift

    public func asArray() -> [A]

    Return Value

    An array with the contents of this Zipper.

  • Checks if the focus is at the leftmost position.

    Declaration

    Swift

    public func isBeginning() -> Bool

    Return Value

    True if the focus is at the leftmost position; false, otherwise.

  • Checks if the focus is at the rightmost position.

    Declaration

    Swift

    public func isEnding() -> Bool

    Return Value

    True if the focus is at the rightmost position; false, otherwise.

  • Declaration

    Swift

    public var description: String { get }