forked from baetheus/fun
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentity.ts
More file actions
36 lines (28 loc) · 770 Bytes
/
identity.ts
File metadata and controls
36 lines (28 loc) · 770 Bytes
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
import type { Kind, Out } from "./kind.ts";
import type { Monad } from "./monad.ts";
export type Identity<A> = A;
export interface KindIdentity extends Kind {
readonly kind: Identity<Out<this, 0>>;
}
export function of<A>(a: A): Identity<A> {
return a;
}
export function map<A, I>(
fai: (a: A) => I,
): (ta: Identity<A>) => Identity<I> {
return fai;
}
export function ap<A>(
ua: Identity<A>,
): <I>(ufai: Identity<(a: A) => I>) => Identity<I> {
return (ufai) => ufai(ua);
}
export function join<A>(ta: Identity<Identity<A>>): Identity<A> {
return ta;
}
export function chain<A, I>(
fati: (a: A) => Identity<I>,
): (ta: Identity<A>) => Identity<I> {
return fati;
}
export const MonadIdentity: Monad<KindIdentity> = { of, ap, map, join, chain };