Class Zipper<A>
java.lang.Object
fj.data.Zipper<A>
Provides a pointed stream, which is a non-empty zipper-like stream structure that tracks an index (focus)
position in a stream. Focus can be moved forward and backwards through the stream, elements can be inserted
before or after the focused position, and the focused item can be deleted.
Based on the pointedlist library by Jeff Wheeler.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanatEnd()Returns whether the focus is on the last element.booleanatStart()Returns whether the focus is on the first element.<B> Zipper<B> Maps over variations of this zipper, such that the given function is applied to each variation (comonad pattern).Move the focus to the next element.Move the focus to the previous element.Possibly deletes the element at the focus, then moves the element on the left into focus.Possibly deletes the element at the focus, then move the element on the left into focus.Deletes all elements in the zipper except the focus.Possibly deletes the element at the focus, then moves the element on the right into focus.Possibly deletes the element at the focus, then move the element on the right into focus.An Equal instance for Zippers.final booleanMoves the focus to the element matching the given predicate, if present.focus()Returns the focus element of this zipper.<B> BPerforms a right-fold reduction across this zipper.fromStream(Stream<A> a) Possibly create a zipper if the provided stream has at least one element, otherwise None.fromStreamEnd(Stream<A> a) Possibly create a zipper if the provided stream has at least one element, otherwise None.final inthashCode()intindex()Returns the index of the focus.insertLeft(A a) Inserts an element to the left of the focus, then moves the focus to the new element.insertRight(A a) Inserts an element to the right of the focus, then moves the focus to the new element.iterator()Returns an iterator of all the positions of this Zipper, starting from the leftmost position.lefts()Returns a Stream of the elements to the left of focus.intlength()Returns the length of this zipper.<B> Zipper<B> Maps the given function across the elements of this zipper (covariant functor pattern).move()A first-class version of the move function.move(int n) Move the focus to the specified index.next()Possibly moves the focus to the next element in the list.next_()First-class version of the next() function.An Ord instance for Zippers.p()Returns the product-3 representation of this Zipper.p_()A first-class function that yields the product-3 representation of a given Zipper.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).previous()Possibly moves the focus to the previous element in the list.First-class version of the previous() function.Replaces the element in focus with the given element.rights()Returns a Stream of the elements to the right of focus.A Show instance for Zippers.static <A> Zipper<A> single(A a) Creates a new zipper with a single element.toStream()Returns the Stream representation of this zipper.tryNext()Attempts to move the focus to the next element, or throws an error if there are no more elements.Attempts to move the focus to the previous element, or throws an error if there are no more elements.zipper()First-class constructor of zippers.static <A> Zipper<A> Creates a new Zipper with the given streams before and after the focus, and the given focused item.static <A> Zipper<A> Creates a new Zipper from the given triple.<B,C> Zipper <C> Zips this Zipper with another, applying the given function lock-step over both zippers in both directions.<B,C> Zipper <C> Zips this Zipper with another, applying the given function lock-step over both zippers in both directions.Zips the elements of this zipper with a boolean that indicates whether that element has focus.Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
left
-
focus
-
right
-
-
Constructor Details
-
Zipper
-
-
Method Details
-
zipper
Creates a new Zipper with the given streams before and after the focus, and the given focused item.- Parameters:
left- The stream of elements before the focus.focus- The element under focus.right- The stream of elements after the focus.- Returns:
- a new Zipper with the given streams before and after the focus, and the given focused item.
-
zipper
-
zipper
-
p
-
p_
-
ord
-
equals
-
hashCode
-
eq
-
show
-
map
-
foldRight
-
single
Creates a new zipper with a single element.- Parameters:
a- The focus element of the new zipper.- Returns:
- a new zipper with a single element which is in focus.
-
fromStream
Possibly create a zipper if the provided stream has at least one element, otherwise None. The provided stream's head will be the focus of the zipper, and the rest of the stream will follow on the right side.- Parameters:
a- The stream from which to create a zipper.- Returns:
- a new zipper if the provided stream has at least one element, otherwise None.
-
fromStreamEnd
Possibly create a zipper if the provided stream has at least one element, otherwise None. The provided stream's last element will be the focus of the zipper, following the rest of the stream in order, to the left.- Parameters:
a- The stream from which to create a zipper.- Returns:
- a new zipper if the provided stream has at least one element, otherwise None.
-
focus
Returns the focus element of this zipper.- Returns:
- the focus element of this zipper.
-
next
-
tryNext
-
previous
-
tryPrevious
-
next_
-
previous_
-
insertLeft
-
insertRight
-
deleteLeft
Possibly deletes the element at the focus, then moves the element on the left into focus. If no element is on the left, focus on the element to the right. Returns None if the focus element is the only element in this zipper.- Returns:
- A new zipper with this zipper's focus element removed, or None if deleting the focus element would cause the zipper to be empty.
-
deleteRight
Possibly deletes the element at the focus, then moves the element on the right into focus. If no element is on the right, focus on the element to the left. Returns None if the focus element is the only element in this zipper.- Returns:
- A new zipper with this zipper's focus element removed, or None if deleting the focus element would cause the zipper to be empty.
-
deleteOthers
-
length
public int length()Returns the length of this zipper.- Returns:
- the length of this zipper.
-
atStart
public boolean atStart()Returns whether the focus is on the first element.- Returns:
- true if the focus is on the first element, otherwise false.
-
atEnd
public boolean atEnd()Returns whether the focus is on the last element.- Returns:
- true if the focus is on the last element, otherwise false.
-
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).- Returns:
- a zipper of variations of the provided zipper, in which each element is focused, with this zipper as the focus of the zipper of zippers.
-
cobind
Maps over variations of this zipper, such that the given function is applied to each variation (comonad pattern).- Parameters:
f- The comonadic function to apply for each variation of this zipper.- Returns:
- A new zipper, with the given function applied for each variation of this zipper.
-
zipWithFocus
Zips the elements of this zipper with a boolean that indicates whether that element has focus. All of the booleans will be false, except the focused element.- Returns:
- A new zipper of pairs, with each element of this zipper paired with a boolean that is true if that element has focus, and false otherwise.
-
move
-
move
-
find
-
index
public int index()Returns the index of the focus.- Returns:
- the index of the focus.
-
cycleNext
-
cyclePrevious
-
deleteLeftCycle
Possibly deletes the element at the focus, then move the element on the left into focus. If no element is on the left, focus on the last element. If the deletion will cause the list to be empty, return None.- Returns:
- A new zipper with the focused element removed, and focus on the previous element to the left, or the last element if there is no element to the left.
-
deleteRightCycle
Possibly deletes the element at the focus, then move the element on the right into focus. If no element is on the right, focus on the first element. If the deletion will cause the list to be empty, return None.- Returns:
- A new zipper with the focused element removed, and focus on the next element to the right, or the first element if there is no element to the right.
-
replace
-
toStream
-
lefts
-
rights
-
zipWith
Zips this Zipper with another, applying the given function lock-step over both zippers in both directions. The structure of the resulting Zipper is the structural intersection of the two Zippers.- Parameters:
bs- A Zipper to zip this one with.f- A function with which to zip together the two Zippers.- Returns:
- The result of applying the given function over this Zipper and the given Zipper, location-wise.
-
zipWith
Zips this Zipper with another, applying the given function lock-step over both zippers in both directions. The structure of the resulting Zipper is the structural intersection of the two Zippers.- Parameters:
bs- A Zipper to zip this one with.f- A function with which to zip together the two Zippers.- Returns:
- The result of applying the given function over this Zipper and the given Zipper, location-wise.
-
iterator
-