|
1 | 1 | package com.jnape.palatable.lambda.monad.transformer.builtin;
|
2 | 2 |
|
3 | 3 | import com.jnape.palatable.lambda.adt.Maybe;
|
| 4 | +import com.jnape.palatable.lambda.adt.Unit; |
4 | 5 | import com.jnape.palatable.lambda.adt.hlist.Tuple2;
|
5 | 6 | import com.jnape.palatable.lambda.functor.builtin.Identity;
|
6 | 7 | import com.jnape.palatable.traitor.annotations.TestTraits;
|
|
15 | 16 | import testsupport.traits.MonadRecLaws;
|
16 | 17 | import testsupport.traits.MonadWriterLaws;
|
17 | 18 |
|
| 19 | +import java.util.ArrayList; |
| 20 | +import java.util.List; |
| 21 | + |
18 | 22 | import static com.jnape.palatable.lambda.adt.Maybe.just;
|
19 | 23 | import static com.jnape.palatable.lambda.adt.Unit.UNIT;
|
20 | 24 | import static com.jnape.palatable.lambda.adt.hlist.HList.tuple;
|
21 | 25 | import static com.jnape.palatable.lambda.functor.builtin.Identity.pureIdentity;
|
| 26 | +import static com.jnape.palatable.lambda.optics.functions.Set.set; |
| 27 | +import static com.jnape.palatable.lambda.optics.lenses.ListLens.elementAt; |
| 28 | +import static java.util.Arrays.asList; |
22 | 29 | import static org.junit.Assert.assertEquals;
|
23 | 30 | import static testsupport.traits.Equivalence.equivalence;
|
24 | 31 |
|
@@ -57,11 +64,14 @@ public void mapStateT() {
|
57 | 64 |
|
58 | 65 | @Test
|
59 | 66 | public void zipping() {
|
60 |
| - assertEquals(new Identity<>(tuple(4, "final state: FOO")), |
61 |
| - StateT.<String, Identity<?>>modify(s -> new Identity<>(s.toUpperCase())) |
62 |
| - .discardL(StateT.gets(s -> new Identity<>(s.length()))) |
63 |
| - .flatMap(x -> StateT.stateT(s -> new Identity<>(tuple(x + 1, "final state: " + s)))) |
64 |
| - .<Identity<Tuple2<Integer, String>>>runStateT("foo")); |
| 67 | + Tuple2<Unit, List<String>> result = StateT.<List<String>, Identity<?>>modify( |
| 68 | + s -> new Identity<>(set(elementAt(s.size()), just("one"), s))) |
| 69 | + .discardL(StateT.modify(s -> new Identity<>(set(elementAt(s.size()), just("two"), s)))) |
| 70 | + .<Identity<Tuple2<Unit, List<String>>>>runStateT(new ArrayList<>()) |
| 71 | + .runIdentity(); |
| 72 | + |
| 73 | + assertEquals(tuple(UNIT, asList("one", "two")), |
| 74 | + result); |
65 | 75 | }
|
66 | 76 |
|
67 | 77 | @Test
|
|
0 commit comments