1 package io.atlassian.fugue.optic;
2
3 import io.atlassian.fugue.Either;
4
5 import java.util.function.Function;
6
7
8
9
10 public final class Setter<S, A> extends PSetter<S, S, A, A> {
11
12 final PSetter<S, S, A, A> pSetter;
13
14 public Setter(final PSetter<S, S, A, A> pSetter) {
15 this.pSetter = pSetter;
16 }
17
18 @Override public Function<S, S> modify(final Function<A, A> f) {
19 return pSetter.modify(f);
20 }
21
22 @Override public Function<S, S> set(final A b) {
23 return pSetter.set(b);
24 }
25
26
27
28
29 public final <S1> Setter<Either<S, S1>, A> sum(final Setter<S1, A> other) {
30 return new Setter<>(pSetter.sum(other.pSetter));
31 }
32
33
34
35
36
37
38
39
40 public final <C> Setter<S, C> composeSetter(final Setter<A, C> other) {
41 return new Setter<>(pSetter.composeSetter(other.pSetter));
42 }
43
44
45
46
47 public final <C> Setter<S, C> composeTraversal(final Traversal<A, C> other) {
48 return new Setter<>(pSetter.composeTraversal(other.pTraversal));
49 }
50
51
52
53
54 public final <C> Setter<S, C> composeIso(final Iso<A, C> other) {
55 return new Setter<>(pSetter.composeIso(other.pIso));
56 }
57
58 public static <S> Setter<S, S> id() {
59 return new Setter<>(pId());
60 }
61
62 public static <S> Setter<Either<S, S>, S> codiagonal() {
63 return new Setter<>(pCodiagonal());
64 }
65
66
67
68
69 public static <S, A> Setter<S, A> setter(final Function<Function<A, A>, Function<S, S>> modify) {
70 return new Setter<>(pSetter(modify));
71 }
72 }