public final class Zipper<A> extends java.lang.Object implements java.lang.Iterable<Zipper<A>>
Modifier and Type | Method and Description |
---|---|
boolean |
atEnd()
Returns whether the focus is on the last element.
|
boolean |
atStart()
Returns whether the focus is on the first element.
|
<B> Zipper<B> |
cobind(F<Zipper<A>,B> f)
Maps over variations of this zipper, such that the given function is applied to each variation (comonad pattern).
|
Zipper<A> |
cycleNext()
Move the focus to the next element.
|
Zipper<A> |
cyclePrevious()
Move the focus to the previous element.
|
Option<Zipper<A>> |
deleteLeft()
Possibly deletes the element at the focus, then moves the element on the left into focus.
|
Option<Zipper<A>> |
deleteLeftCycle()
Possibly deletes the element at the focus, then move the element on the left into focus.
|
Zipper<A> |
deleteOthers()
Deletes all elements in the zipper except the focus.
|
Option<Zipper<A>> |
deleteRight()
Possibly deletes the element at the focus, then moves the element on the right into focus.
|
Option<Zipper<A>> |
deleteRightCycle()
Possibly deletes the element at the focus, then move the element on the right into focus.
|
static <A> Equal<Zipper<A>> |
eq(Equal<A> e)
An Equal instance for Zippers.
|
Option<Zipper<A>> |
find(F<A,java.lang.Boolean> p)
Moves the focus to the element matching the given predicate, if present.
|
A |
focus()
Returns the focus element of this zipper.
|
<B> B |
foldRight(F<A,F<B,B>> f,
B z)
Performs a right-fold reduction across this zipper.
|
static <A> Option<Zipper<A>> |
fromStream(Stream<A> a)
Possibly create a zipper if the provided stream has at least one element, otherwise None.
|
static <A> Option<Zipper<A>> |
fromStreamEnd(Stream<A> a)
Possibly create a zipper if the provided stream has at least one element, otherwise None.
|
int |
index()
Returns the index of the focus.
|
Zipper<A> |
insertLeft(A a)
Inserts an element to the left of the focus, then moves the focus to the new element.
|
Zipper<A> |
insertRight(A a)
Inserts an element to the right of the focus, then moves the focus to the new element.
|
java.util.Iterator<Zipper<A>> |
iterator()
Returns an iterator of all the positions of this Zipper, starting from the leftmost position.
|
Stream<A> |
lefts()
Returns a Stream of the elements to the left of focus.
|
int |
length()
Returns the length of this zipper.
|
<B> Zipper<B> |
map(F<A,B> f)
Maps the given function across the elements of this zipper (covariant functor pattern).
|
static <A> F<java.lang.Integer,F<Zipper<A>,Option<Zipper<A>>>> |
move()
A first-class version of the move function.
|
Option<Zipper<A>> |
move(int n)
Move the focus to the specified index.
|
static <A> F<Zipper<A>,Option<Zipper<A>>> |
next_()
First-class version of the next() function.
|
Option<Zipper<A>> |
next()
Possibly moves the focus to the next element in the list.
|
static <A> Ord<Zipper<A>> |
ord(Ord<A> o)
An Ord instance for Zippers.
|
static <A> F<Zipper<A>,P3<Stream<A>,A,Stream<A>>> |
p_()
A first-class function that yields the product-3 representation of a given Zipper.
|
P3<Stream<A>,A,Stream<A>> |
p()
Returns the product-3 representation of this Zipper.
|
Zipper<Zipper<A>> |
positions()
Creates a zipper of variations of this zipper, in which each element is focused,
with this zipper as the focus of the zipper of zippers (comonad pattern).
|
static <A> F<Zipper<A>,Option<Zipper<A>>> |
previous_()
First-class version of the previous() function.
|
Option<Zipper<A>> |
previous()
Possibly moves the focus to the previous element in the list.
|
Zipper<A> |
replace(A a)
Replaces the element in focus with the given element.
|
Stream<A> |
rights()
Returns a Stream of the elements to the right of focus.
|
static <A> Show<Zipper<A>> |
show(Show<A> s)
A Show instance for Zippers.
|
static <A> Zipper<A> |
single(A a)
Creates a new zipper with a single element.
|
Stream<A> |
toStream()
Returns the Stream representation of this zipper.
|
Zipper<A> |
tryNext()
Attempts to move the focus to the next element, or throws an error if there are no more elements.
|
Zipper<A> |
tryPrevious()
Attempts to move the focus to the previous element, or throws an error if there are no more elements.
|
static <A> F3<Stream<A>,A,Stream<A>,Zipper<A>> |
zipper()
First-class constructor of zippers.
|
static <A> Zipper<A> |
zipper(P3<Stream<A>,A,Stream<A>> p)
Creates a new Zipper from the given triple.
|
static <A> Zipper<A> |
zipper(Stream<A> left,
A focus,
Stream<A> right)
Creates a new Zipper with the given streams before and after the focus, and the given focused item.
|
<B,C> Zipper<C> |
zipWith(Zipper<B> bs,
F<A,F<B,C>> f)
Zips this Zipper with another, applying the given function lock-step over both zippers in both directions.
|
<B,C> Zipper<C> |
zipWith(Zipper<B> bs,
F2<A,B,C> f)
Zips this Zipper with another, applying the given function lock-step over both zippers in both directions.
|
Zipper<P2<A,java.lang.Boolean>> |
zipWithFocus()
Zips the elements of this zipper with a boolean that indicates whether that element has focus.
|
public static <A> Zipper<A> zipper(Stream<A> left, A focus, Stream<A> right)
left
- The stream of elements before the focus.focus
- The element under focus.right
- The stream of elements after the focus.public static <A> Zipper<A> zipper(P3<Stream<A>,A,Stream<A>> p)
p
- A triple of the elements before the focus, the focus element, and the elements after the focus,
respectively.public static <A> F3<Stream<A>,A,Stream<A>,Zipper<A>> zipper()
public P3<Stream<A>,A,Stream<A>> p()
public static <A> F<Zipper<A>,P3<Stream<A>,A,Stream<A>>> p_()
public static <A> Ord<Zipper<A>> ord(Ord<A> o)
o
- An Ord instance for the element type.public static <A> Equal<Zipper<A>> eq(Equal<A> e)
e
- An Equal instance for the element type.public static <A> Show<Zipper<A>> show(Show<A> s)
s
- A Show instance for the element type.public <B> Zipper<B> map(F<A,B> f)
f
- A function to map across this zipper.public <B> B foldRight(F<A,F<B,B>> f, B z)
f
- The function to apply on each element of this zipper.z
- The beginning value to start the application from.public static <A> Zipper<A> single(A a)
a
- The focus element of the new zipper.public static <A> Option<Zipper<A>> fromStream(Stream<A> a)
a
- The stream from which to create a zipper.public static <A> Option<Zipper<A>> fromStreamEnd(Stream<A> a)
a
- The stream from which to create a zipper.public A focus()
public Option<Zipper<A>> next()
public Zipper<A> tryNext()
public Option<Zipper<A>> previous()
public Zipper<A> tryPrevious()
public static <A> F<Zipper<A>,Option<Zipper<A>>> next_()
public static <A> F<Zipper<A>,Option<Zipper<A>>> previous_()
public Zipper<A> insertLeft(A a)
a
- A new element to insert into this zipper.public Zipper<A> insertRight(A a)
a
- A new element to insert into this zipper.public Option<Zipper<A>> deleteLeft()
public Option<Zipper<A>> deleteRight()
public Zipper<A> deleteOthers()
public int length()
public boolean atStart()
public boolean atEnd()
public Zipper<Zipper<A>> positions()
public <B> Zipper<B> cobind(F<Zipper<A>,B> f)
f
- The comonadic function to apply for each variation of this zipper.public Zipper<P2<A,java.lang.Boolean>> zipWithFocus()
public Option<Zipper<A>> move(int n)
n
- The index to which to move the focus.public static <A> F<java.lang.Integer,F<Zipper<A>,Option<Zipper<A>>>> move()
public Option<Zipper<A>> find(F<A,java.lang.Boolean> p)
p
- A predicate to match.public int index()
public Zipper<A> cycleNext()
public Zipper<A> cyclePrevious()
public Option<Zipper<A>> deleteLeftCycle()
public Option<Zipper<A>> deleteRightCycle()
public Zipper<A> replace(A a)
a
- An element to replace the focused element with.public Stream<A> toStream()
public Stream<A> lefts()
public Stream<A> rights()
public <B,C> Zipper<C> zipWith(Zipper<B> bs, F2<A,B,C> f)
bs
- A Zipper to zip this one with.f
- A function with which to zip together the two Zippers.public <B,C> Zipper<C> zipWith(Zipper<B> bs, F<A,F<B,C>> f)
bs
- A Zipper to zip this one with.f
- A function with which to zip together the two Zippers.