This repository has been archived by the owner on May 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
identity.ts
95 lines (78 loc) · 3.08 KB
/
identity.ts
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import type * as HKT from "./hkt.ts";
import type * as TC from "./type_classes.ts";
import { call, identity } from "./fns.ts";
/*******************************************************************************
* Types
******************************************************************************/
/*******************************************************************************
* Identity<A>
*
* The identity type returns exactly the type that is passed into it.
******************************************************************************/
export type Identity<A> = A;
/*******************************************************************************
* Kind Registration
******************************************************************************/
/*******************************************************************************
* The Kinds URI for Identity
******************************************************************************/
export const URI = "Identity";
/*******************************************************************************
* The Kinds URI Type for Identity
******************************************************************************/
export type URI = typeof URI;
declare module "./hkt.ts" {
// deno-lint-ignore no-explicit-any
export interface Kinds<_ extends any[]> {
[URI]: Identity<_[0]>;
}
}
/*******************************************************************************
* Modules
******************************************************************************/
/*******************************************************************************
* The standard Functor instance for Identity
******************************************************************************/
export const Functor: TC.Functor<URI> = {
map: identity,
};
/*******************************************************************************
* The standard Apply instance for Identity
******************************************************************************/
export const Apply: TC.Apply<URI> = {
ap: call,
map: Functor.map,
};
export const Applicative: TC.Applicative<URI> = {
of: identity,
ap: Apply.ap,
map: Functor.map,
};
export const Chain: TC.Chain<URI> = {
ap: Apply.ap,
map: Functor.map,
chain: identity,
};
export const Monad: TC.Monad<URI> = {
of: Applicative.of,
ap: Apply.ap,
map: Functor.map,
join: identity,
chain: Chain.chain,
};
/*******************************************************************************
* Pipeables
******************************************************************************/
/*******************************************************************************
* of
*
* Takes a value of any type and returns that value.
******************************************************************************/
export const of = Monad.of;
/*******************************************************************************
* ap
*
* Takes a function A -> B and returns a function A -> B
******************************************************************************/
export const ap = Monad.ap;
export const { map, join, chain } = Monad;