forked from functionaljava/functionaljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOption_bind.java
More file actions
34 lines (32 loc) · 1.13 KB
/
Option_bind.java
File metadata and controls
34 lines (32 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package fj.demo;
import fj.F;
import fj.data.Option;
import static fj.data.Option.none;
import static fj.data.Option.some;
import static fj.Show.intShow;
import static fj.Show.optionShow;
public final class Option_bind {
public static void main(final String[] args) {
final Option<Integer> o1 = some(7);
final Option<Integer> o2 = some(8);
final Option<Integer> o3 = none();
final Option<Integer> p1 = o1.bind(new F<Integer, Option<Integer>>() {
public Option<Integer> f(final Integer i) {
return i % 2 == 0 ? some(i * 3) : Option.<Integer>none();
}
});
final Option<Integer> p2 = o2.bind(new F<Integer, Option<Integer>>() {
public Option<Integer> f(final Integer i) {
return i % 2 == 0 ? some(i * 3) : Option.<Integer>none();
}
});
final Option<Integer> p3 = o3.bind(new F<Integer, Option<Integer>>() {
public Option<Integer> f(final Integer i) {
return i % 2 == 0 ? some(i * 3) : Option.<Integer>none();
}
});
optionShow(intShow).println(p1); // None
optionShow(intShow).println(p2); // Some(24)
optionShow(intShow).println(p3); // None
}
}