Zipper overview
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 Zipper([1, 2], 3, [4])
Adapted from
- https://github.com/DavidHarrison/purescript-list-zipper
- https://github.com/thunklife/purescript-zipper
- https://github.com/scalaz/scalaz/blob/series/7.3.x/core/src/main/scala/scalaz/Zipper.scala
Added in v0.1.6
Table of contents
- Applicative
- Apply
- Comonad
- Extend
- Foldable
- Functor
- FunctorWithIndex
- Traversable
- combinators
- constructors
- destructors
- instances
- model
- utils
Applicative
of
Signature
export declare const of: <A>(focus: A) => Zipper<A>
Added in v0.1.6
Apply
ap
Signature
export declare const ap: <A>(fa: Zipper<A>) => <B>(fab: Zipper<(a: A) => B>) => Zipper<B>
Added in v0.1.18
apFirst
Signature
export declare const apFirst: <B>(fb: Zipper<B>) => <A>(fa: Zipper<A>) => Zipper<A>
Added in v0.1.18
apSecond
Signature
export declare const apSecond: <B>(fb: Zipper<B>) => <A>(fa: Zipper<A>) => Zipper<B>
Added in v0.1.18
Comonad
extract
Signature
export declare const extract: <A>(wa: Zipper<A>) => A
Added in v0.1.18
Extend
duplicate
Signature
export declare const duplicate: <A>(wa: Zipper<A>) => Zipper<Zipper<A>>
Added in v0.1.18
extend
Signature
export declare const extend: <A, B>(f: (fa: Zipper<A>) => B) => (wa: Zipper<A>) => Zipper<B>
Added in v0.1.18
Foldable
foldMap
Signature
export declare const foldMap: <M>(M: Monoid<M>) => <A>(f: (a: A) => M) => (fa: Zipper<A>) => M
Added in v0.1.18
reduce
Signature
export declare const reduce: <A, B>(b: B, f: (b: B, a: A) => B) => (fa: Zipper<A>) => B
Added in v0.1.18
reduceRight
Signature
export declare const reduceRight: <A, B>(b: B, f: (a: A, b: B) => B) => (fa: Zipper<A>) => B
Added in v0.1.18
Functor
map
Signature
export declare const map: <A, B>(f: (a: A) => B) => (fa: Zipper<A>) => Zipper<B>
Added in v0.1.18
FunctorWithIndex
mapWithIndex
Signature
export declare const mapWithIndex: <A, B>(f: (i: number, a: A) => B) => (fa: Zipper<A>) => Zipper<B>
Added in v0.1.18
Traversable
sequence
Signature
export declare const sequence: Sequence1<'Zipper'>
Added in v0.1.18
combinators
deleteLeft
Deletes the element at focus and moves the focus to the left. If there is no element on the left, the focus is moved to the right.
Signature
export declare const deleteLeft: <A>(fa: Zipper<A>) => O.Option<Zipper<A>>
Added in v0.1.6
deleteRight
Deletes the element at focus and moves the focus to the right. If there is no element on the right, the focus is moved to the left.
Signature
export declare const deleteRight: <A>(fa: Zipper<A>) => O.Option<Zipper<A>>
Added in v0.1.6
down
Moves focus of the zipper down.
Signature
export declare const down: <A>(fa: Zipper<A>) => O.Option<Zipper<A>>
Added in v0.1.6
end
Moves focus to the end of the zipper.
Signature
export declare const end: <A>(fa: Zipper<A>) => Zipper<A>
Added in v0.1.6
insertLeft
Inserts an element to the left of the focus and focuses on the new element.
Signature
export declare const insertLeft: <A>(a: A) => (fa: Zipper<A>) => Zipper<A>
Added in v0.1.6
insertRight
Inserts an element to the right of the focus and focuses on the new element.
Signature
export declare const insertRight: <A>(a: A) => (fa: Zipper<A>) => Zipper<A>
Added in v0.1.6
modify
Applies f
to the focus and update with the result.
Signature
export declare const modify: <A>(f: (a: A) => A) => (fa: Zipper<A>) => Zipper<A>
Added in v0.1.6
move
Moves focus in the zipper, or None
if there is no such element.
Signature
export declare const move: <A>(f: (currentIndex: number) => number, fa: Zipper<A>) => O.Option<Zipper<A>>
Added in v0.1.6
moveByFindFirst
Use a function to find and focus the first matching element in the array. If no element matches, None
is returned. If an element matches, Some<Zipper<A>>
is returned.
Signature
export declare const moveByFindFirst: <A>(predicate: Predicate<A>) => (fa: Zipper<A>) => O.Option<Zipper<A>>
Added in v0.1.26
start
Moves focus to the start of the zipper.
Signature
export declare const start: <A>(fa: Zipper<A>) => Zipper<A>
Added in v0.1.6
up
Moves focus of the zipper up.
Signature
export declare const up: <A>(fa: Zipper<A>) => O.Option<Zipper<A>>
Added in v0.1.6
update
Updates the focus of the zipper.
Signature
export declare const update: <A>(a: A) => (fa: Zipper<A>) => Zipper<A>
Added in v0.1.6
constructors
fromArray
Signature
export declare const fromArray: <A>(as: A[], focusIndex?: number | undefined) => O.Option<Zipper<A>>
Added in v0.1.6
fromNonEmptyArray
Signature
export declare const fromNonEmptyArray: <A>(nea: NEA.NonEmptyArray<A>) => Zipper<A>
Added in v0.1.6
fromReadonlyArray
Signature
export declare const fromReadonlyArray: <A>(as: readonly A[], focusIndex?: number | undefined) => O.Option<Zipper<A>>
Added in v0.1.23
fromReadonlyNonEmptyArray
Signature
export declare const fromReadonlyNonEmptyArray: <A>(rnea: ReadonlyNonEmptyArray<A>) => Zipper<A>
Added in v0.1.23
make
Creates a new zipper.
Signature
export declare const make: <A>(lefts: readonly A[], focus: A, rights: readonly A[]) => Zipper<A>
Added in v0.1.6
destructors
isOutOfBound
Signature
export declare const isOutOfBound: <A>(index: number, fa: Zipper<A>) => boolean
Added in v0.1.18
length
Signature
export declare const length: <A>(fa: Zipper<A>) => number
Added in v0.1.6
toNonEmptyArray
Signature
export declare const toNonEmptyArray: <A>(fa: Zipper<A>) => NEA.NonEmptyArray<A>
Added in v0.1.23
toReadonlyNonEmptyArray
Signature
export declare const toReadonlyNonEmptyArray: <A>(fa: Zipper<A>) => ReadonlyNonEmptyArray<A>
Added in v0.1.23
toArray
Signature
export declare const toArray: <A>(fa: Zipper<A>) => A[]
Added in v0.1.6
instances
Applicative
Signature
export declare const Applicative: Applicative1<'Zipper'>
Added in v0.1.18
Apply
Signature
export declare const Apply: Apply1<'Zipper'>
Added in v0.1.18
Comonad
Signature
export declare const Comonad: Comonad1<'Zipper'>
Added in v0.1.18
Foldable
Signature
export declare const Foldable: Foldable1<'Zipper'>
Added in v0.1.18
Functor
Signature
export declare const Functor: Functor1<'Zipper'>
Added in v0.1.18
FunctorWithIndex
Signature
export declare const FunctorWithIndex: FunctorWithIndex1<'Zipper', number>
Added in v0.1.18
Traversable
Signature
export declare const Traversable: Traversable1<'Zipper'>
Added in v0.1.18
URI
Signature
export declare const URI: 'Zipper'
Added in v0.1.6
URI (type alias)
Signature
export type URI = typeof URI
Added in v0.1.6
getMonoid
Signature
export declare const getMonoid: <A>(M: Monoid<A>) => Monoid<Zipper<A>>
Added in v0.1.6
getSemigroup
Signature
export declare const getSemigroup: <A>(S: Semigroup<A>) => Semigroup<Zipper<A>>
Added in v0.1.6
getShow
Signature
export declare const getShow: <A>(S: Show<A>) => Show<Zipper<A>>
Added in v0.1.6
zipper
Signature
export declare const zipper: Applicative1<'Zipper'> &
Foldable1<'Zipper'> &
Traversable1<'Zipper'> &
Comonad1<'Zipper'> &
FunctorWithIndex1<'Zipper', number>
Added in v0.1.6
model
Zipper (interface)
Signature
export interface Zipper<A> {
readonly lefts: Array<A>
readonly focus: A
readonly rights: Array<A>
}
Added in v0.1.6
utils
findIndex
Find the first index for which a predicate holds.
Signature
export declare const findIndex: <A>(predicate: Predicate<A>) => (fa: Zipper<A>) => Option<number>
Added in v0.1.24