blob: 7e70c61d0a844a297588052e01ba2e55aad9e95a (
plain)
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
|
package bjc.typeclasses;
import java.util.function.Function;
/**
* Represents an applicative
* @author bjcul
*
* @param <A> The contained type
* @param <App> The self type
*/
public interface Applicative<A, App extends Applicative<?, App>> extends FunctorX<A, App> {
/**
* Create an applicative from a value
*
* @param <B> The type of the value
*
* @param val The value
*
* @return An applicative containing the given value
*/
<B> Applicative<B, App> pure(B val);
/**
* Apply the given applicative
*
* @param <B> The type of the result
*
* @param func An applicative containing a function
*
* @return An applicative containing the result of applying the function
*/
<B> Applicative<B, App> app(Applicative<Function<? super A, ? extends B>, App> func);
@Override
default <B> FunctorX<B, App> fmap(Function<? super A, ? extends B> fn) {
return app(pure(fn));
}
}
|