-
-
Notifications
You must be signed in to change notification settings - Fork 503
/
Endomorphism.ts
65 lines (55 loc) · 1.55 KB
/
Endomorphism.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
/**
* @since 2.11.0
*/
import { flow, identity } from './function'
import { Monoid } from './Monoid'
import { Semigroup } from './Semigroup'
// -------------------------------------------------------------------------------------
// model
// -------------------------------------------------------------------------------------
/**
* @since 2.11.0
*/
export interface Endomorphism<A> {
(a: A): A
}
// -------------------------------------------------------------------------------------
// instances
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
// instances
// -------------------------------------------------------------------------------------
/**
* @category instances
* @since 2.11.0
*/
export const URI = 'Endomorphism'
/**
* @category instances
* @since 2.11.0
*/
export type URI = typeof URI
declare module './HKT' {
interface URItoKind<A> {
readonly [URI]: Endomorphism<A>
}
}
/**
* Endomorphism form a `Semigroup` where the `concat` operation is the usual function composition.
*
* @category instances
* @since 2.11.0
*/
export const getSemigroup = <A = never>(): Semigroup<Endomorphism<A>> => ({
concat: (first, second) => flow(first, second)
})
/**
* Endomorphism form a `Monoid` where the `empty` value is the `identity` function.
*
* @category instances
* @since 2.11.0
*/
export const getMonoid = <A = never>(): Monoid<Endomorphism<A>> => ({
concat: getSemigroup<A>().concat,
empty: identity
})