Skip to content

Commit a79e760

Browse files
committed
Adding missing javadoc
1 parent 39b772c commit a79e760

2 files changed

Lines changed: 99 additions & 8 deletions

File tree

src/main/java/com/jnape/palatable/lambda/functor/builtin/Market.java

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.jnape.palatable.lambda.functor.Applicative;
77
import com.jnape.palatable.lambda.functor.Cocartesian;
88
import com.jnape.palatable.lambda.monad.Monad;
9+
import com.jnape.palatable.lambda.optics.Prism;
910

1011
import java.util.function.Function;
1112

@@ -15,6 +16,14 @@
1516
import static com.jnape.palatable.lambda.functions.Fn1.fn1;
1617
import static com.jnape.palatable.lambda.functions.builtin.fn1.Constantly.constantly;
1718

19+
/**
20+
* A profunctor used to extract the isomorphic functions a {@link Prism} is composed of.
21+
*
22+
* @param <A> the output that might fail to be produced
23+
* @param <B> the input that guarantees its output
24+
* @param <S> the input that might fail to map to its output
25+
* @param <T> the guaranteed output
26+
*/
1827
public final class Market<A, B, S, T> implements
1928
Monad<T, Market<A, B, S, ?>>,
2029
Cocartesian<S, T, Market<A, B, ?, ?>> {
@@ -27,11 +36,35 @@ public Market(Function<? super B, ? extends T> bt, Function<? super S, ? extends
2736
this.sta = fn1(sta);
2837
}
2938

39+
/**
40+
* Extract the mapping <code>B -&gt; T</code>.
41+
*
42+
* @return a <code>{@link Function}&lt;B, T&gt;</code>
43+
*/
44+
public Fn1<? super B, ? extends T> bt() {
45+
return bt;
46+
}
47+
48+
/**
49+
* Extract the mapping <code>S -&gt; {@link Either}&lt;T, A&gt;</code>.
50+
*
51+
* @return a <code>{@link Function}&lt;S, {@link Either}&lt;T, A&gt;&gt;</code>
52+
*/
53+
public Fn1<? super S, ? extends Either<T, A>> sta() {
54+
return sta;
55+
}
56+
57+
/**
58+
* {@inheritDoc}
59+
*/
3060
@Override
3161
public <U> Market<A, B, S, U> pure(U u) {
3262
return new Market<>(constantly(u), constantly(left(u)));
3363
}
3464

65+
/**
66+
* {@inheritDoc}
67+
*/
3568
@Override
3669
public <U> Market<A, B, S, U> flatMap(Function<? super T, ? extends Monad<U, Market<A, B, S, ?>>> f) {
3770
return new Market<>(b -> f.apply(bt().apply(b)).<Market<A, B, S, U>>coerce().bt().apply(b),
@@ -40,49 +73,62 @@ public <U> Market<A, B, S, U> flatMap(Function<? super T, ? extends Monad<U, Mar
4073
.apply(s).invert()).invert());
4174
}
4275

76+
/**
77+
* {@inheritDoc}
78+
*/
4379
@Override
4480
public <U> Market<A, B, S, U> zip(Applicative<Function<? super T, ? extends U>, Market<A, B, S, ?>> appFn) {
4581
Market<A, B, S, Function<? super T, ? extends U>> marketF = appFn.coerce();
4682
return new Market<>(b -> marketF.bt().apply(b).apply(bt().apply(b)),
4783
s -> sta().apply(s).invert().zip(marketF.sta().apply(s).invert()).invert());
4884
}
4985

50-
public Fn1<? super B, ? extends T> bt() {
51-
return bt;
52-
}
53-
54-
public Fn1<? super S, ? extends Either<T, A>> sta() {
55-
return sta;
56-
}
57-
86+
/**
87+
* {@inheritDoc}
88+
*/
5889
@Override
5990
public <U> Market<A, B, S, U> fmap(Function<? super T, ? extends U> fn) {
6091
return diMapR(fn);
6192
}
6293

94+
/**
95+
* {@inheritDoc}
96+
*/
6397
@Override
6498
public <C> Market<A, B, Choice2<C, S>, Choice2<C, T>> cocartesian() {
6599
return new Market<>(bt.fmap(Choice2::b),
66100
cs -> cs.fmap(sta).match(c -> left(a(c)),
67101
tOrA -> tOrA.match(t -> left(b(t)), Either::right)));
68102
}
69103

104+
/**
105+
* {@inheritDoc}
106+
*/
70107
@Override
71108
public <R, U> Market<A, B, R, U> diMap(Function<? super R, ? extends S> lFn,
72109
Function<? super T, ? extends U> rFn) {
73110
return new Market<>(bt.fmap(rFn), sta.diMapL(lFn).diMapR(c -> c.biMapL(rFn)));
74111
}
75112

113+
/**
114+
* {@inheritDoc}
115+
*/
76116
@Override
77117
public <R> Market<A, B, R, T> diMapL(Function<? super R, ? extends S> fn) {
78118
return (Market<A, B, R, T>) Cocartesian.super.<R>diMapL(fn);
79119
}
80120

121+
/**
122+
* {@inheritDoc}
123+
*/
81124
@Override
82125
public <U> Market<A, B, S, U> diMapR(Function<? super T, ? extends U> fn) {
83126
return (Market<A, B, S, U>) Cocartesian.super.<U>diMapR(fn);
84127
}
85128

129+
/**
130+
* {@inheritDoc}
131+
*/
86132
@Override
87133
public <R> Market<A, B, R, T> contraMap(Function<? super R, ? extends S> fn) {
88134
return (Market<A, B, R, T>) Cocartesian.super.<R>contraMap(fn);

src/main/java/com/jnape/palatable/lambda/functor/builtin/Tagged.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,68 +9,113 @@
99

1010
import static com.jnape.palatable.lambda.adt.choice.Choice2.b;
1111

12+
/**
13+
* Like {@link Const}, but the phantom parameter is in the contravariant position, and the value is in covariant
14+
* position.
15+
*
16+
* @param <S> the phantom type
17+
* @param <B> the value type
18+
*/
1219
public final class Tagged<S, B> implements Monad<B, Tagged<S, ?>>, Cocartesian<S, B, Tagged<?, ?>> {
1320
private final B b;
1421

1522
public Tagged(B b) {
1623
this.b = b;
1724
}
1825

26+
/**
27+
* Extract the contained value.
28+
*
29+
* @return the value
30+
*/
1931
public B unTagged() {
2032
return b;
2133
}
2234

35+
/**
36+
* {@inheritDoc}
37+
*/
2338
@Override
2439
public <C> Tagged<S, C> flatMap(Function<? super B, ? extends Monad<C, Tagged<S, ?>>> f) {
2540
return f.apply(b).coerce();
2641
}
2742

43+
/**
44+
* {@inheritDoc}
45+
*/
2846
@Override
2947
public <C> Tagged<S, C> pure(C c) {
3048
return new Tagged<>(c);
3149
}
3250

51+
/**
52+
* {@inheritDoc}
53+
*/
3354
@Override
3455
public <C> Tagged<S, C> fmap(Function<? super B, ? extends C> fn) {
3556
return Monad.super.<C>fmap(fn).coerce();
3657
}
3758

59+
/**
60+
* {@inheritDoc}
61+
*/
3862
@Override
3963
public <C> Tagged<S, C> zip(Applicative<Function<? super B, ? extends C>, Tagged<S, ?>> appFn) {
4064
return Monad.super.zip(appFn).coerce();
4165
}
4266

67+
/**
68+
* {@inheritDoc}
69+
*/
4370
@Override
4471
public <C> Tagged<S, C> discardL(Applicative<C, Tagged<S, ?>> appB) {
4572
return Monad.super.discardL(appB).coerce();
4673
}
4774

75+
/**
76+
* {@inheritDoc}
77+
*/
4878
@Override
4979
public <C> Tagged<S, B> discardR(Applicative<C, Tagged<S, ?>> appB) {
5080
return Monad.super.discardR(appB).coerce();
5181
}
5282

83+
/**
84+
* {@inheritDoc}
85+
*/
5386
@Override
5487
public <C> Tagged<Choice2<C, S>, Choice2<C, B>> cocartesian() {
5588
return new Tagged<>(b(b));
5689
}
5790

91+
/**
92+
* {@inheritDoc}
93+
*/
5894
@Override
5995
public <Z, C> Tagged<Z, C> diMap(Function<? super Z, ? extends S> lFn,
6096
Function<? super B, ? extends C> rFn) {
6197
return new Tagged<>(rFn.apply(b));
6298
}
6399

100+
/**
101+
* {@inheritDoc}
102+
*/
64103
@Override
65104
public <Z> Tagged<Z, B> diMapL(Function<? super Z, ? extends S> fn) {
66105
return (Tagged<Z, B>) Cocartesian.super.<Z>diMapL(fn);
67106
}
68107

108+
/**
109+
* {@inheritDoc}
110+
*/
69111
@Override
70112
public <C> Tagged<S, C> diMapR(Function<? super B, ? extends C> fn) {
71113
return (Tagged<S, C>) Cocartesian.super.<C>diMapR(fn);
72114
}
73115

116+
/**
117+
* {@inheritDoc}
118+
*/
74119
@Override
75120
public <Z> Tagged<Z, B> contraMap(Function<? super Z, ? extends S> fn) {
76121
return (Tagged<Z, B>) Cocartesian.super.<Z>contraMap(fn);

0 commit comments

Comments
 (0)