← Back

Source

zipper

Applicative1<URI> & Foldable2v1<URI> & Traversable2v1<URI> & Comonad1<URI>

Added in v1.9.0 (instance)

Zipper

constructor(readonly lefts: Array<A>, readonly focus: A, readonly rights: Array<A>) {
    this.length = lefts.length + 1 + rights.length
  }

Added in v1.9.0 (data)

Provides a pointed array, which is a non-empty zipper-like array structure that tracks an index (focus) position in an array. Focus can be moved forward and backwards through the array.

The array [1, 2, 3, 4] with focus on 3 is represented by new Zipper([1, 2], 3, [4])

ap

<B>(fab: Zipper<(a: A) => B>): Zipper<B>

Added in v1.9.0 (method)

deleteLeft

(): Option<Zipper<A>>

Added in v1.9.0 (method)

Deletes the element at focus and moves the focus to the left. If there is no element on the left, focus is moved to the right.

deleteRight

(): Option<Zipper<A>>

Added in v1.9.0 (method)

Deletes the element at focus and moves the focus to the right. If there is no element on the right, focus is moved to the left.

down

(): Option<Zipper<A>>

Added in v1.9.0 (method)

end

(): Zipper<A>

Added in v1.9.0 (method)

Moves focus to the end of the zipper.

insertLeft

(a: A): Zipper<A>

Added in v1.9.0 (method)

Inserts an element to the left of focus and focuses on the new element.

insertRight

(a: A): Zipper<A>

Added in v1.9.0 (method)

Inserts an element to the right of focus and focuses on the new element.

inspect

(): string

Added in v1.9.0 (method)

isOutOfBound

(index: number): boolean

Added in v1.9.0 (method)

map

<B>(f: (a: A) => B): Zipper<B>

Added in v1.9.0 (method)

modify

(f: (a: A) => A): Zipper<A>

Added in v1.9.0 (method)

Apply f to the focus and update with the result.

move

(f: (currentIndex: number) => number): Option<Zipper<A>>

Added in v1.9.0 (method)

Moves focus in the zipper, or None if there is no such element.

reduce

<B>(b: B, f: (b: B, a: A) => B): B

Added in v1.9.0 (method)

start

(): Zipper<A>

Added in v1.9.0 (method)

Moves focus to the start of the zipper.

toArray

(): Array<A>

Added in v1.9.0 (method)

toString

(): string

Added in v1.9.0 (method)

up

(): Option<Zipper<A>>

Added in v1.9.0 (method)

update

(a: A): Zipper<A>

Added in v1.9.0 (method)

Update the focus in this zipper.

fromArray

<A>(as: Array<A>, focusIndex: number = 0): Option<Zipper<A>>

Added in v1.9.0 (function)

fromNonEmptyArray

<A>(nea: NonEmptyArray<A>): Zipper<A>

Added in v1.9.0 (function)

getMonoid

<A>(M: Monoid<A>): Monoid<Zipper<A>>

Added in v1.9.0 (function)

getSemigroup

<A>(S: Semigroup<A>): Semigroup<Zipper<A>>

Added in v1.9.0 (function)