-
-
Notifications
You must be signed in to change notification settings - Fork 511
Expand file tree
/
Copy pathnumber.ts
More file actions
150 lines (137 loc) · 3.15 KB
/
Copy pathnumber.ts
File metadata and controls
150 lines (137 loc) · 3.15 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
* @since 2.10.0
*/
import * as B from './Bounded'
import * as E from './Eq'
import * as F from './Field'
import * as J from './Json'
import { Magma } from './Magma'
import { Monoid } from './Monoid'
import * as O from './Ord'
import { Refinement } from './Refinement'
import { Semigroup } from './Semigroup'
import * as S from './Show'
// -------------------------------------------------------------------------------------
// refinements
// -------------------------------------------------------------------------------------
/**
* @category refinements
* @since 2.11.0
*/
export const isNumber: Refinement<unknown, number> = (u: unknown): u is number => typeof u === 'number'
// -------------------------------------------------------------------------------------
// instances
// -------------------------------------------------------------------------------------
/**
* @category instances
* @since 2.10.0
*/
export const Eq: E.Eq<number> = {
equals: (first, second) => first === second
}
/**
* @category instances
* @since 2.10.0
*/
export const Ord: O.Ord<number> = {
equals: Eq.equals,
compare: (first, second) => (first < second ? -1 : first > second ? 1 : 0)
}
/**
* @category instances
* @since 2.10.0
*/
export const Bounded: B.Bounded<number> = {
equals: Eq.equals,
compare: Ord.compare,
top: Infinity,
bottom: -Infinity
}
/**
* @category instances
* @since 2.10.0
*/
export const Show: S.Show<number> = J.Show
/**
* @category instances
* @since 2.11.0
*/
export const MagmaSub: Magma<number> = {
concat: (first, second) => first - second
}
/**
* `number` semigroup under addition.
*
* @example
* import { SemigroupSum } from 'fp-ts/number'
*
* assert.deepStrictEqual(SemigroupSum.concat(2, 3), 5)
*
* @category instances
* @since 2.10.0
*/
export const SemigroupSum: Semigroup<number> = {
concat: (first, second) => first + second
}
/**
* `number` semigroup under multiplication.
*
* @example
* import { SemigroupProduct } from 'fp-ts/number'
*
* assert.deepStrictEqual(SemigroupProduct.concat(2, 3), 6)
*
* @category instances
* @since 2.10.0
*/
export const SemigroupProduct: Semigroup<number> = {
concat: (first, second) => first * second
}
/**
* `number` monoid under addition.
*
* The `empty` value is `0`.
*
* @example
* import { MonoidSum } from 'fp-ts/number'
*
* assert.deepStrictEqual(MonoidSum.concat(2, MonoidSum.empty), 2)
*
* @category instances
* @since 2.10.0
*/
export const MonoidSum: Monoid<number> = {
concat: SemigroupSum.concat,
empty: 0
}
/**
* `number` monoid under multiplication.
*
* The `empty` value is `1`.
*
* @example
* import { MonoidProduct } from 'fp-ts/number'
*
* assert.deepStrictEqual(MonoidProduct.concat(2, MonoidProduct.empty), 2)
*
* @category instances
* @since 2.10.0
*/
export const MonoidProduct: Monoid<number> = {
concat: SemigroupProduct.concat,
empty: 1
}
/**
* @category instances
* @since 2.10.0
*/
export const Field: F.Field<number> = {
add: SemigroupSum.concat,
zero: 0,
mul: SemigroupProduct.concat,
one: 1,
sub: MagmaSub.concat,
degree: (_) => 1,
div: (first, second) => first / second,
mod: (first, second) => first % second
}