forked from functionaljava/functionaljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetter.java
More file actions
61 lines (47 loc) · 1.81 KB
/
Setter.java
File metadata and controls
61 lines (47 loc) · 1.81 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package fj.data.optic;
import fj.F;
import fj.data.Either;
/** {@link PSetter} with a monomorphic modify function */
public final class Setter<S, A> extends PSetter<S, S, A, A> {
final PSetter<S, S, A, A> pSetter;
public Setter(final PSetter<S, S, A, A> pSetter) {
this.pSetter = pSetter;
}
@Override
public F<S, S> modify(final F<A, A> f) {
return pSetter.modify(f);
}
@Override
public F<S, S> set(final A b) {
return pSetter.set(b);
}
/** join two {@link Setter} with the same target */
public <S1> Setter<Either<S, S1>, A> sum(final Setter<S1, A> other) {
return new Setter<>(pSetter.sum(other.pSetter));
}
/************************************************************/
/** Compose methods between a {@link Setter} and another Optics */
/************************************************************/
/** compose a {@link Setter} with a {@link Setter} */
public <C> Setter<S, C> composeSetter(final Setter<A, C> other) {
return new Setter<>(pSetter.composeSetter(other.pSetter));
}
/** compose a {@link Setter} with a {@link Traversal} */
public <C> Setter<S, C> composeTraversal(final Traversal<A, C> other) {
return new Setter<>(pSetter.composeTraversal(other.pTraversal));
}
/** compose a {@link Setter} with an {@link Iso} */
public <C> Setter<S, C> composeIso(final Iso<A, C> other) {
return new Setter<>(pSetter.composeIso(other.pIso));
}
public static <S> Setter<S, S> id() {
return new Setter<>(PSetter.pId());
}
public static <S> Setter<Either<S, S>, S> codiagonal() {
return new Setter<>(PSetter.pCodiagonal());
}
/** alias for {@link PSetter} constructor with a monomorphic modify function */
public static <S, A> Setter<S, A> setter(final F<F<A, A>, F<S, S>> modify) {
return new Setter<>(PSetter.pSetter(modify));
}
}