Skip to content

Commit 63c87b8

Browse files
committed
functionaljava#176: Added min and max to Set
1 parent d04b616 commit 63c87b8

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

core/src/main/java/fj/data/Set.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import static fj.Function.*;
66
import static fj.data.Either.right;
7+
import static fj.data.Option.none;
78
import static fj.data.Option.some;
89
import static fj.function.Booleans.not;
910

@@ -387,6 +388,14 @@ public static <A> F<Set<A>, F<Set<A>, Set<A>>> minus() {
387388
return curry((s1, s2) -> s1.minus(s2));
388389
}
389390

391+
public Option<A> min() {
392+
return isEmpty() ? none() : l().min().orElse(some(head()));
393+
}
394+
395+
public Option<A> max() {
396+
return isEmpty() ? none() : r().max().orElse(some(head()));
397+
}
398+
390399
/**
391400
* Returns the size of this set.
392401
*

0 commit comments

Comments
 (0)