Skip to content

Commit 3812a83

Browse files
committed
Add uncons to FingerTree
1 parent 0704e22 commit 3812a83

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

core/src/main/java/fj/data/fingertrees/FingerTree.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ public final Option<A> headOption() {
167167
return isEmpty() ? Option.none() : Option.some(head());
168168
}
169169

170+
/**
171+
* Performs a reduction on this finger tree using the given arguments.
172+
*
173+
* @param nil The value to return if this finger tree is empty.
174+
* @param cons The function to apply to the head and tail of this finger tree if it is not empty.
175+
* @return A reduction on this finger tree.
176+
*/
177+
public final <B> B uncons(B nil, F2<A, FingerTree<V, A>, B> cons) {
178+
return isEmpty() ? nil : cons.f(head(), tail());
179+
}
180+
181+
170182
/**
171183
* The last element of this tree. This is an O(1) operation.
172184
*

0 commit comments

Comments
 (0)