File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
core/src/test/java/fj/data Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ package fj .data ;
2+
3+ import fj .data .Reader ;
4+ import org .junit .Assert ;
5+ import org .junit .Test ;
6+
7+ import static org .junit .Assert .assertTrue ;
8+
9+ /**
10+ * Created by MarkPerry on 4/12/2014.
11+ *
12+ * Examples taken from http://learnyouahaskell.com/for-a-few-monads-more
13+ */
14+ public class ReaderTest {
15+
16+ @ Test
17+ public void testMap () {
18+ int x = Reader .unit ((Integer i ) -> i + 3 ).map (i -> i * 5 ).f (8 );
19+ assertTrue (x == 55 );
20+ // System.out.println(x); // 55
21+ }
22+
23+ @ Test
24+ public void testFlatMap () {
25+ int y = Reader .unit ((Integer i ) -> i * 2 ).flatMap (a -> Reader .unit ((Integer i ) -> i + 10 ).map (b -> a + b )).f (3 );
26+ // System.out.println(y); // 19
27+ assertTrue (y == 19 );
28+ }
29+
30+ }
You can’t perform that action at this time.
0 commit comments