effect 3.14.11 → 3.14.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BigDecimal.js +3 -0
- package/dist/cjs/BigDecimal.js.map +1 -1
- package/dist/cjs/BigInt.js +3 -0
- package/dist/cjs/BigInt.js.map +1 -1
- package/dist/cjs/JSONSchema.js +24 -10
- package/dist/cjs/JSONSchema.js.map +1 -1
- package/dist/cjs/Number.js +650 -196
- package/dist/cjs/Number.js.map +1 -1
- package/dist/cjs/ParseResult.js +3 -1
- package/dist/cjs/ParseResult.js.map +1 -1
- package/dist/cjs/Schema.js +4 -2
- package/dist/cjs/Schema.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/BigDecimal.d.ts +3 -0
- package/dist/dts/BigDecimal.d.ts.map +1 -1
- package/dist/dts/BigInt.d.ts +3 -0
- package/dist/dts/BigInt.d.ts.map +1 -1
- package/dist/dts/JSONSchema.d.ts.map +1 -1
- package/dist/dts/Number.d.ts +866 -421
- package/dist/dts/Number.d.ts.map +1 -1
- package/dist/dts/ParseResult.d.ts.map +1 -1
- package/dist/dts/Schema.d.ts +1 -3
- package/dist/dts/Schema.d.ts.map +1 -1
- package/dist/dts/index.d.ts +98 -3
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/esm/BigDecimal.js +3 -0
- package/dist/esm/BigDecimal.js.map +1 -1
- package/dist/esm/BigInt.js +3 -0
- package/dist/esm/BigInt.js.map +1 -1
- package/dist/esm/JSONSchema.js +24 -10
- package/dist/esm/JSONSchema.js.map +1 -1
- package/dist/esm/Number.js +645 -192
- package/dist/esm/Number.js.map +1 -1
- package/dist/esm/ParseResult.js +2 -1
- package/dist/esm/ParseResult.js.map +1 -1
- package/dist/esm/Schema.js +4 -2
- package/dist/esm/Schema.js.map +1 -1
- package/dist/esm/index.js +98 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +1 -1
- package/src/BigDecimal.ts +3 -0
- package/src/BigInt.ts +3 -0
- package/src/JSONSchema.ts +20 -7
- package/src/Number.ts +913 -475
- package/src/ParseResult.ts +2 -1
- package/src/Schema.ts +11 -8
- package/src/index.ts +98 -3
- package/src/internal/version.ts +1 -1
package/dist/dts/Number.d.ts
CHANGED
|
@@ -1,553 +1,976 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* # Number
|
|
3
|
+
*
|
|
4
|
+
* This module provides utility functions and type class instances for working
|
|
5
|
+
* with the `number` type in TypeScript. It includes functions for basic
|
|
6
|
+
* arithmetic operations, as well as type class instances for `Equivalence` and
|
|
7
|
+
* `Order`.
|
|
8
|
+
*
|
|
9
|
+
* ## Operations Reference
|
|
10
|
+
*
|
|
11
|
+
* | Category | Operation | Description | Domain | Co-domain |
|
|
12
|
+
* | ------------ | ------------------------------------------ | ------------------------------------------------------- | ------------------------------ | --------------------- |
|
|
13
|
+
* | constructors | {@link module:Number.parse} | Safely parses a string to a number | `string` | `Option<number>` |
|
|
14
|
+
* | | | | | |
|
|
15
|
+
* | math | {@link module:Number.sum} | Adds two numbers | `number`, `number` | `number` |
|
|
16
|
+
* | math | {@link module:Number.sumAll} | Sums all numbers in a collection | `Iterable<number>` | `number` |
|
|
17
|
+
* | math | {@link module:Number.subtract} | Subtracts one number from another | `number`, `number` | `number` |
|
|
18
|
+
* | math | {@link module:Number.multiply} | Multiplies two numbers | `number`, `number` | `number` |
|
|
19
|
+
* | math | {@link module:Number.multiplyAll} | Multiplies all numbers in a collection | `Iterable<number>` | `number` |
|
|
20
|
+
* | math | {@link module:Number.divide} | Safely divides handling division by zero | `number`, `number` | `Option<number>` |
|
|
21
|
+
* | math | {@link module:Number.unsafeDivide} | Divides but misbehaves for division by zero | `number`, `number` | `number` |
|
|
22
|
+
* | math | {@link module:Number.remainder} | Calculates remainder of division | `number`, `number` | `number` |
|
|
23
|
+
* | math | {@link module:Number.increment} | Adds 1 to a number | `number` | `number` |
|
|
24
|
+
* | math | {@link module:Number.decrement} | Subtracts 1 from a number | `number` | `number` |
|
|
25
|
+
* | math | {@link module:Number.sign} | Determines the sign of a number | `number` | `Ordering` |
|
|
26
|
+
* | math | {@link module:Number.nextPow2} | Finds the next power of 2 | `number` | `number` |
|
|
27
|
+
* | math | {@link module:Number.round} | Rounds a number with specified precision | `number`, `number` | `number` |
|
|
28
|
+
* | | | | | |
|
|
29
|
+
* | predicates | {@link module:Number.between} | Checks if a number is in a range | `number`, `{minimum, maximum}` | `boolean` |
|
|
30
|
+
* | predicates | {@link module:Number.lessThan} | Checks if one number is less than another | `number`, `number` | `boolean` |
|
|
31
|
+
* | predicates | {@link module:Number.lessThanOrEqualTo} | Checks if one number is less than or equal | `number`, `number` | `boolean` |
|
|
32
|
+
* | predicates | {@link module:Number.greaterThan} | Checks if one number is greater than another | `number`, `number` | `boolean` |
|
|
33
|
+
* | predicates | {@link module:Number.greaterThanOrEqualTo} | Checks if one number is greater or equal | `number`, `number` | `boolean` |
|
|
34
|
+
* | | | | | |
|
|
35
|
+
* | guards | {@link module:Number.isNumber} | Type guard for JavaScript numbers | `unknown` | `boolean` |
|
|
36
|
+
* | | | | | |
|
|
37
|
+
* | comparison | {@link module:Number.min} | Returns the minimum of two numbers | `number`, `number` | `number` |
|
|
38
|
+
* | comparison | {@link module:Number.max} | Returns the maximum of two numbers | `number`, `number` | `number` |
|
|
39
|
+
* | comparison | {@link module:Number.clamp} | Restricts a number to a range | `number`, `{minimum, maximum}` | `number` |
|
|
40
|
+
* | | | | | |
|
|
41
|
+
* | instances | {@link module:Number.Equivalence} | Equivalence instance for numbers | | `Equivalence<number>` |
|
|
42
|
+
* | instances | {@link module:Number.Order} | Order instance for numbers | | `Order<number>` |
|
|
43
|
+
* | | | | | |
|
|
44
|
+
* | errors | {@link module:Number.DivisionByZeroError} | Error thrown by unsafeDivide | | |
|
|
45
|
+
*
|
|
46
|
+
* ## Composition Patterns and Type Safety
|
|
47
|
+
*
|
|
48
|
+
* When building function pipelines, understanding how types flow through
|
|
49
|
+
* operations is critical:
|
|
50
|
+
*
|
|
51
|
+
* ### Composing with type-preserving operations
|
|
52
|
+
*
|
|
53
|
+
* Most operations in this module are type-preserving (`number → number`),
|
|
54
|
+
* making them easily composable in pipelines:
|
|
5
55
|
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { pipe } from "effect"
|
|
58
|
+
* import * as Number from "effect/Number"
|
|
59
|
+
*
|
|
60
|
+
* const result = pipe(
|
|
61
|
+
* 10,
|
|
62
|
+
* Number.increment, // number → number
|
|
63
|
+
* Number.multiply(2), // number → number
|
|
64
|
+
* Number.round(1) // number → number
|
|
65
|
+
* ) // Result: number (21)
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* ### Working with Option results
|
|
69
|
+
*
|
|
70
|
+
* Operations that might fail (like division by zero) return Option types and
|
|
71
|
+
* require Option combinators:
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { pipe, Option } from "effect"
|
|
75
|
+
* import * as Number from "effect/Number"
|
|
76
|
+
*
|
|
77
|
+
* const result = pipe(
|
|
78
|
+
* 10,
|
|
79
|
+
* Number.divide(0), // number → Option<number>
|
|
80
|
+
* Option.getOrElse(() => 0) // Option<number> → number
|
|
81
|
+
* ) // Result: number (0)
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* ### Composition best practices
|
|
85
|
+
*
|
|
86
|
+
* - Chain type-preserving operations for maximum composability
|
|
87
|
+
* - Use Option combinators when working with potentially failing operations
|
|
88
|
+
* - Consider using Effect for operations that might fail with specific errors
|
|
89
|
+
* - Remember that all operations maintain JavaScript's floating-point precision
|
|
90
|
+
* limitations
|
|
91
|
+
*
|
|
92
|
+
* @module Number
|
|
6
93
|
* @since 2.0.0
|
|
94
|
+
* @see {@link module:BigInt} for more similar operations on `bigint` types
|
|
95
|
+
* @see {@link module:BigDecimal} for more similar operations on `BigDecimal` types
|
|
7
96
|
*/
|
|
8
97
|
import * as equivalence from "./Equivalence.js";
|
|
9
98
|
import type { Option } from "./Option.js";
|
|
10
99
|
import * as order from "./Order.js";
|
|
11
100
|
import type { Ordering } from "./Ordering.js";
|
|
12
101
|
/**
|
|
13
|
-
*
|
|
102
|
+
* Type guard that tests if a value is a member of the set of JavaScript
|
|
103
|
+
* numbers.
|
|
14
104
|
*
|
|
105
|
+
* @memberof Number
|
|
106
|
+
* @since 2.0.0
|
|
107
|
+
* @category guards
|
|
15
108
|
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* import * as assert from "node:assert"
|
|
18
|
-
* import { isNumber } from "effect/Number"
|
|
19
109
|
*
|
|
20
|
-
*
|
|
21
|
-
* assert
|
|
110
|
+
* ```ts
|
|
111
|
+
* import * as assert from "node:assert/strict"
|
|
112
|
+
* import * as Number from "effect/Number"
|
|
113
|
+
*
|
|
114
|
+
* // Regular numbers
|
|
115
|
+
* assert.equal(Number.isNumber(2), true)
|
|
116
|
+
* assert.equal(Number.isNumber(-3.14), true)
|
|
117
|
+
* assert.equal(Number.isNumber(0), true)
|
|
118
|
+
*
|
|
119
|
+
* // Special numeric values
|
|
120
|
+
* assert.equal(Number.isNumber(Infinity), true)
|
|
121
|
+
* assert.equal(Number.isNumber(NaN), true)
|
|
122
|
+
*
|
|
123
|
+
* // Non-number values
|
|
124
|
+
* assert.equal(Number.isNumber("2"), false)
|
|
125
|
+
* assert.equal(Number.isNumber(true), false)
|
|
126
|
+
* assert.equal(Number.isNumber(null), false)
|
|
127
|
+
* assert.equal(Number.isNumber(undefined), false)
|
|
128
|
+
* assert.equal(Number.isNumber({}), false)
|
|
129
|
+
* assert.equal(Number.isNumber([]), false)
|
|
130
|
+
*
|
|
131
|
+
* // Using as a type guard in conditionals
|
|
132
|
+
* function processValue(value: unknown): string {
|
|
133
|
+
* if (Number.isNumber(value)) {
|
|
134
|
+
* // TypeScript now knows 'value' is a number
|
|
135
|
+
* return `Numeric value: ${value.toFixed(2)}`
|
|
136
|
+
* }
|
|
137
|
+
* return "Not a number"
|
|
138
|
+
* }
|
|
139
|
+
*
|
|
140
|
+
* assert.strictEqual(processValue(42), "Numeric value: 42.00")
|
|
141
|
+
* assert.strictEqual(processValue("hello"), "Not a number")
|
|
142
|
+
*
|
|
143
|
+
* // Filtering for numbers in an array
|
|
144
|
+
* const mixed = [1, "two", 3, false, 5]
|
|
145
|
+
* const onlyNumbers = mixed.filter(Number.isNumber)
|
|
146
|
+
* assert.equal(onlyNumbers, [1, 3, 5])
|
|
22
147
|
* ```
|
|
23
148
|
*
|
|
24
|
-
* @
|
|
25
|
-
*
|
|
149
|
+
* @param input - The value to test for membership in the set of JavaScript
|
|
150
|
+
* numbers
|
|
151
|
+
*
|
|
152
|
+
* @returns `true` if the input is a JavaScript number, `false` otherwise
|
|
26
153
|
*/
|
|
27
154
|
export declare const isNumber: (input: unknown) => input is number;
|
|
28
155
|
/**
|
|
29
|
-
*
|
|
156
|
+
* Returns the additive inverse of a number, effectively negating it.
|
|
30
157
|
*
|
|
158
|
+
* @memberof Number
|
|
159
|
+
* @since 3.14.6
|
|
31
160
|
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* import * as assert from "node:assert"
|
|
34
|
-
* import { sum } from "effect/Number"
|
|
35
161
|
*
|
|
36
|
-
*
|
|
162
|
+
* ```ts
|
|
163
|
+
* import * as assert from "node:assert/strict"
|
|
164
|
+
* import { pipe } from "effect"
|
|
165
|
+
* import * as Number from "effect/Number"
|
|
166
|
+
*
|
|
167
|
+
* assert.equal(
|
|
168
|
+
* Number.negate(5), //
|
|
169
|
+
* -5
|
|
170
|
+
* )
|
|
171
|
+
*
|
|
172
|
+
* assert.equal(
|
|
173
|
+
* Number.negate(-5), //
|
|
174
|
+
* 5
|
|
175
|
+
* )
|
|
176
|
+
*
|
|
177
|
+
* assert.equal(
|
|
178
|
+
* Number.negate(0), //
|
|
179
|
+
* 0
|
|
180
|
+
* )
|
|
37
181
|
* ```
|
|
38
182
|
*
|
|
39
|
-
* @
|
|
183
|
+
* @param n - The number value to be negated.
|
|
184
|
+
*
|
|
185
|
+
* @returns The negated number value.
|
|
186
|
+
*/
|
|
187
|
+
export declare const negate: (n: number) => number;
|
|
188
|
+
/**
|
|
189
|
+
* Performs addition in the set of JavaScript numbers.
|
|
190
|
+
*
|
|
191
|
+
* @memberof Number
|
|
40
192
|
* @since 2.0.0
|
|
193
|
+
* @category math
|
|
194
|
+
* @example
|
|
195
|
+
*
|
|
196
|
+
* ```ts
|
|
197
|
+
* import * as assert from "node:assert/strict"
|
|
198
|
+
* import { pipe } from "effect"
|
|
199
|
+
* import * as Number from "effect/Number"
|
|
200
|
+
*
|
|
201
|
+
* // Data-first style (direct application)
|
|
202
|
+
* assert.equal(Number.sum(2, 3), 5)
|
|
203
|
+
* assert.equal(Number.sum(-10, 5), -5)
|
|
204
|
+
* assert.equal(Number.sum(0.1, 0.2), 0.30000000000000004) // Note: floating-point precision limitation
|
|
205
|
+
*
|
|
206
|
+
* // Data-last style (pipeable)
|
|
207
|
+
* assert.equal(
|
|
208
|
+
* pipe(
|
|
209
|
+
* 10,
|
|
210
|
+
* Number.sum(5) // 10 + 5 = 15
|
|
211
|
+
* ),
|
|
212
|
+
* 15
|
|
213
|
+
* )
|
|
214
|
+
*
|
|
215
|
+
* // Chaining multiple additions
|
|
216
|
+
* assert.equal(
|
|
217
|
+
* pipe(
|
|
218
|
+
* 1,
|
|
219
|
+
* Number.sum(2), // 1 + 2 = 3
|
|
220
|
+
* Number.sum(3), // 3 + 3 = 6
|
|
221
|
+
* Number.sum(4) // 6 + 4 = 10
|
|
222
|
+
* ),
|
|
223
|
+
* 10
|
|
224
|
+
* )
|
|
225
|
+
*
|
|
226
|
+
* // Identity property: a + 0 = a
|
|
227
|
+
* assert.equal(Number.sum(42, 0), 42)
|
|
228
|
+
*
|
|
229
|
+
* // Commutative property: a + b = b + a
|
|
230
|
+
* assert.equal(Number.sum(5, 3), Number.sum(3, 5))
|
|
231
|
+
* ```
|
|
41
232
|
*/
|
|
42
233
|
export declare const sum: {
|
|
43
234
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```ts
|
|
48
|
-
* import * as assert from "node:assert"
|
|
49
|
-
* import { sum } from "effect/Number"
|
|
235
|
+
* Returns a function that adds a specified number to its argument.
|
|
50
236
|
*
|
|
51
|
-
*
|
|
52
|
-
* ```
|
|
237
|
+
* @param that - The number to add to the input of the resulting function
|
|
53
238
|
*
|
|
54
|
-
* @
|
|
55
|
-
*
|
|
239
|
+
* @returns A function that takes a number and returns the sum of that number
|
|
240
|
+
* and `that`
|
|
56
241
|
*/
|
|
57
242
|
(that: number): (self: number) => number;
|
|
58
243
|
/**
|
|
59
|
-
*
|
|
244
|
+
* Adds two numbers together.
|
|
60
245
|
*
|
|
61
|
-
* @
|
|
62
|
-
*
|
|
63
|
-
* import * as assert from "node:assert"
|
|
64
|
-
* import { sum } from "effect/Number"
|
|
65
|
-
*
|
|
66
|
-
* assert.deepStrictEqual(sum(2, 3), 5)
|
|
67
|
-
* ```
|
|
246
|
+
* @param self - The first addend
|
|
247
|
+
* @param that - The second addend
|
|
68
248
|
*
|
|
69
|
-
* @
|
|
70
|
-
* @since 2.0.0
|
|
249
|
+
* @returns The sum of the two numbers
|
|
71
250
|
*/
|
|
72
251
|
(self: number, that: number): number;
|
|
73
252
|
};
|
|
74
253
|
/**
|
|
75
|
-
*
|
|
254
|
+
* Computes the sum of all elements in an iterable collection of numbers.
|
|
76
255
|
*
|
|
256
|
+
* @memberof Number
|
|
257
|
+
* @since 2.0.0
|
|
258
|
+
* @category math
|
|
77
259
|
* @example
|
|
260
|
+
*
|
|
78
261
|
* ```ts
|
|
79
|
-
* import * as assert from "node:assert"
|
|
80
|
-
* import
|
|
262
|
+
* import * as assert from "node:assert/strict"
|
|
263
|
+
* import * as Number from "effect/Number"
|
|
264
|
+
*
|
|
265
|
+
* // Basic sums
|
|
266
|
+
* assert.equal(Number.sumAll([2, 3, 4]), 9) // 2 + 3 + 4 = 9
|
|
267
|
+
* assert.equal(Number.sumAll([1.1, 2.2, 3.3]), 6.6) // 1.1 + 2.2 + 3.3 = 6.6
|
|
268
|
+
*
|
|
269
|
+
* // Empty collection returns the additive identity (0)
|
|
270
|
+
* assert.equal(Number.sumAll([]), 0)
|
|
271
|
+
*
|
|
272
|
+
* // Single element collection
|
|
273
|
+
* assert.equal(Number.sumAll([42]), 42)
|
|
81
274
|
*
|
|
82
|
-
*
|
|
275
|
+
* // Sums with negative numbers
|
|
276
|
+
* assert.equal(Number.sumAll([2, -3, 4]), 3) // 2 + (-3) + 4 = 3
|
|
277
|
+
* assert.equal(Number.sumAll([-2, -3, -4]), -9) // (-2) + (-3) + (-4) = -9
|
|
278
|
+
*
|
|
279
|
+
* // Works with any iterable
|
|
280
|
+
* assert.equal(Number.sumAll(new Set([2, 3, 4])), 9)
|
|
281
|
+
*
|
|
282
|
+
* // Using with generated sequences
|
|
283
|
+
* function* range(start: number, end: number) {
|
|
284
|
+
* for (let i = start; i <= end; i++) yield i
|
|
285
|
+
* }
|
|
286
|
+
*
|
|
287
|
+
* // Compute sum of first 5 natural numbers: 1 + 2 + 3 + 4 + 5 = 15
|
|
288
|
+
* assert.equal(Number.sumAll(range(1, 5)), 15)
|
|
289
|
+
*
|
|
290
|
+
* // Floating point precision example
|
|
291
|
+
* assert.equal(
|
|
292
|
+
* Number.sumAll([0.1, 0.2]),
|
|
293
|
+
* 0.30000000000000004 // Note IEEE 754 precision limitation
|
|
294
|
+
* )
|
|
83
295
|
* ```
|
|
84
296
|
*
|
|
85
|
-
* @
|
|
297
|
+
* @param collection - An `iterable` containing the `numbers` to sum
|
|
298
|
+
*
|
|
299
|
+
* @returns The sum of all numbers in the collection, or 0 if the collection is
|
|
300
|
+
* empty
|
|
301
|
+
*/
|
|
302
|
+
export declare const sumAll: (collection: Iterable<number>) => number;
|
|
303
|
+
/**
|
|
304
|
+
* Performs subtraction in the set of JavaScript numbers.
|
|
305
|
+
*
|
|
306
|
+
* @memberof Number
|
|
86
307
|
* @since 2.0.0
|
|
308
|
+
* @category math
|
|
309
|
+
* @example
|
|
310
|
+
*
|
|
311
|
+
* ```ts
|
|
312
|
+
* import * as assert from "node:assert/strict"
|
|
313
|
+
* import { pipe } from "effect"
|
|
314
|
+
* import * as Number from "effect/Number"
|
|
315
|
+
*
|
|
316
|
+
* // Data-first style (direct application)
|
|
317
|
+
* assert.equal(Number.subtract(2, 3), -1) // 2 - 3 = -1
|
|
318
|
+
* assert.equal(Number.subtract(10, 5), 5) // 10 - 5 = 5
|
|
319
|
+
* assert.equal(Number.subtract(0.3, 0.1), 0.19999999999999998) // Note: floating-point precision limitation
|
|
320
|
+
*
|
|
321
|
+
* // Data-last style (pipeable)
|
|
322
|
+
* assert.equal(
|
|
323
|
+
* pipe(
|
|
324
|
+
* 10,
|
|
325
|
+
* Number.subtract(5) // 10 - 5 = 5
|
|
326
|
+
* ),
|
|
327
|
+
* 5
|
|
328
|
+
* )
|
|
329
|
+
*
|
|
330
|
+
* // Chaining multiple subtractions
|
|
331
|
+
* assert.equal(
|
|
332
|
+
* pipe(
|
|
333
|
+
* 20,
|
|
334
|
+
* Number.subtract(5), // 20 - 5 = 15
|
|
335
|
+
* Number.subtract(3), // 15 - 3 = 12
|
|
336
|
+
* Number.subtract(2) // 12 - 2 = 10
|
|
337
|
+
* ),
|
|
338
|
+
* 10
|
|
339
|
+
* )
|
|
340
|
+
*
|
|
341
|
+
* // Right identity property: a - 0 = a
|
|
342
|
+
* assert.equal(Number.subtract(42, 0), 42)
|
|
343
|
+
*
|
|
344
|
+
* // Self-annihilation property: a - a = 0
|
|
345
|
+
* assert.equal(Number.subtract(42, 42), 0)
|
|
346
|
+
*
|
|
347
|
+
* // Non-commutative property: a - b ≠ b - a
|
|
348
|
+
* assert.equal(Number.subtract(5, 3), 2) // 5 - 3 = 2
|
|
349
|
+
* assert.equal(Number.subtract(3, 5), -2) // 3 - 5 = -2
|
|
350
|
+
*
|
|
351
|
+
* // Inverse relation: a - b = -(b - a)
|
|
352
|
+
* assert.equal(Number.subtract(5, 3), -Number.subtract(3, 5))
|
|
353
|
+
* ```
|
|
87
354
|
*/
|
|
88
|
-
export declare const
|
|
355
|
+
export declare const subtract: {
|
|
89
356
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```ts
|
|
94
|
-
* import * as assert from "node:assert"
|
|
95
|
-
* import { multiply } from "effect/Number"
|
|
357
|
+
* Returns a function that subtracts a specified number from its argument.
|
|
96
358
|
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
359
|
+
* @param subtrahend - The number to subtract from the input of the resulting
|
|
360
|
+
* function
|
|
99
361
|
*
|
|
100
|
-
* @
|
|
101
|
-
*
|
|
362
|
+
* @returns A function that takes a minuend and returns the difference of
|
|
363
|
+
* subtracting the subtrahend from it
|
|
102
364
|
*/
|
|
103
|
-
(
|
|
365
|
+
(subtrahend: number): (minuend: number) => number;
|
|
104
366
|
/**
|
|
105
|
-
*
|
|
367
|
+
* Subtracts the subtrahend from the minuend and returns the difference.
|
|
106
368
|
*
|
|
107
|
-
* @
|
|
108
|
-
*
|
|
109
|
-
* import * as assert from "node:assert"
|
|
110
|
-
* import { multiply } from "effect/Number"
|
|
111
|
-
*
|
|
112
|
-
* assert.deepStrictEqual(multiply(2, 3), 6)
|
|
113
|
-
* ```
|
|
369
|
+
* @param minuend - The number from which another number is to be subtracted
|
|
370
|
+
* @param subtrahend - The number to subtract from the minuend
|
|
114
371
|
*
|
|
115
|
-
* @
|
|
116
|
-
* @since 2.0.0
|
|
372
|
+
* @returns The difference of the minuend minus the subtrahend
|
|
117
373
|
*/
|
|
118
|
-
(
|
|
374
|
+
(minuend: number, subtrahend: number): number;
|
|
119
375
|
};
|
|
120
376
|
/**
|
|
121
|
-
*
|
|
377
|
+
* Performs **multiplication** in the set of JavaScript numbers.
|
|
122
378
|
*
|
|
379
|
+
* @memberof Number
|
|
380
|
+
* @since 2.0.0
|
|
381
|
+
* @category math
|
|
123
382
|
* @example
|
|
124
|
-
* ```ts
|
|
125
|
-
* import * as assert from "node:assert"
|
|
126
|
-
* import { subtract } from "effect/Number"
|
|
127
383
|
*
|
|
128
|
-
*
|
|
384
|
+
* ```ts
|
|
385
|
+
* import * as assert from "node:assert/strict"
|
|
386
|
+
* import { pipe } from "effect"
|
|
387
|
+
* import * as Number from "effect/Number"
|
|
388
|
+
*
|
|
389
|
+
* // Data-first style (direct application)
|
|
390
|
+
* assert.equal(Number.multiply(2, 3), 6) // 2 × 3 = 6
|
|
391
|
+
* assert.equal(Number.multiply(-4, 5), -20) // (-4) × 5 = -20
|
|
392
|
+
* assert.equal(Number.multiply(-3, -2), 6) // (-3) × (-2) = 6
|
|
393
|
+
* assert.equal(Number.multiply(0.1, 0.2), 0.020000000000000004) // Note: floating-point precision limitation
|
|
394
|
+
*
|
|
395
|
+
* // Data-last style (pipeable)
|
|
396
|
+
* assert.equal(
|
|
397
|
+
* pipe(
|
|
398
|
+
* 10,
|
|
399
|
+
* Number.multiply(5) // 10 × 5 = 50
|
|
400
|
+
* ),
|
|
401
|
+
* 50
|
|
402
|
+
* )
|
|
403
|
+
*
|
|
404
|
+
* // Chaining multiple multiplications
|
|
405
|
+
* assert.equal(
|
|
406
|
+
* pipe(
|
|
407
|
+
* 2,
|
|
408
|
+
* Number.multiply(3), // 2 × 3 = 6
|
|
409
|
+
* Number.multiply(4), // 6 × 4 = 24
|
|
410
|
+
* Number.multiply(0.5) // 24 × 0.5 = 12
|
|
411
|
+
* ),
|
|
412
|
+
* 12
|
|
413
|
+
* )
|
|
414
|
+
*
|
|
415
|
+
* // Identity property: a × 1 = a
|
|
416
|
+
* assert.equal(Number.multiply(42, 1), 42)
|
|
417
|
+
*
|
|
418
|
+
* // Zero property: a × 0 = 0
|
|
419
|
+
* assert.equal(Number.multiply(42, 0), 0)
|
|
420
|
+
*
|
|
421
|
+
* // Commutative property: a × b = b × a
|
|
422
|
+
* assert.equal(Number.multiply(5, 3), Number.multiply(3, 5))
|
|
423
|
+
*
|
|
424
|
+
* // Associative property: (a × b) × c = a × (b × c)
|
|
425
|
+
* const a = 2,
|
|
426
|
+
* b = 3,
|
|
427
|
+
* c = 4
|
|
428
|
+
* assert.equal(
|
|
429
|
+
* Number.multiply(Number.multiply(a, b), c),
|
|
430
|
+
* Number.multiply(a, Number.multiply(b, c))
|
|
431
|
+
* )
|
|
129
432
|
* ```
|
|
130
|
-
*
|
|
131
|
-
* @category math
|
|
132
|
-
* @since 2.0.0
|
|
133
433
|
*/
|
|
134
|
-
export declare const
|
|
434
|
+
export declare const multiply: {
|
|
135
435
|
/**
|
|
136
|
-
*
|
|
436
|
+
* Returns a function that multiplies a specified number with its argument.
|
|
137
437
|
*
|
|
138
|
-
* @
|
|
139
|
-
*
|
|
140
|
-
* import * as assert from "node:assert"
|
|
141
|
-
* import { subtract } from "effect/Number"
|
|
438
|
+
* @param multiplicand - The number to multiply with the input of the
|
|
439
|
+
* resulting function
|
|
142
440
|
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* @category math
|
|
147
|
-
* @since 2.0.0
|
|
441
|
+
* @returns A function that takes a multiplier and returns the product of that
|
|
442
|
+
* multiplier and the multiplicand
|
|
148
443
|
*/
|
|
149
|
-
(
|
|
444
|
+
(multiplicand: number): (multiplier: number) => number;
|
|
150
445
|
/**
|
|
151
|
-
*
|
|
446
|
+
* Multiplies two numbers together.
|
|
152
447
|
*
|
|
153
|
-
* @
|
|
154
|
-
*
|
|
155
|
-
* import * as assert from "node:assert"
|
|
156
|
-
* import { subtract } from "effect/Number"
|
|
157
|
-
*
|
|
158
|
-
* assert.deepStrictEqual(subtract(2, 3), -1)
|
|
159
|
-
* ```
|
|
448
|
+
* @param multiplier - The first factor
|
|
449
|
+
* @param multiplicand - The second factor
|
|
160
450
|
*
|
|
161
|
-
* @
|
|
162
|
-
* @since 2.0.0
|
|
451
|
+
* @returns The product of the two numbers
|
|
163
452
|
*/
|
|
164
|
-
(
|
|
453
|
+
(multiplier: number, multiplicand: number): number;
|
|
165
454
|
};
|
|
166
455
|
/**
|
|
167
|
-
*
|
|
456
|
+
* Computes the product of all elements in an iterable collection of numbers.
|
|
168
457
|
*
|
|
458
|
+
* @memberof Number
|
|
459
|
+
* @since 2.0.0
|
|
460
|
+
* @category math
|
|
169
461
|
* @example
|
|
462
|
+
*
|
|
170
463
|
* ```ts
|
|
171
|
-
* import * as assert from "node:assert"
|
|
172
|
-
* import
|
|
464
|
+
* import * as assert from "node:assert/strict"
|
|
465
|
+
* import * as Number from "effect/Number"
|
|
466
|
+
*
|
|
467
|
+
* // Basic products
|
|
468
|
+
* assert.equal(Number.multiplyAll([2, 3, 4]), 24) // 2 × 3 × 4 = 24
|
|
469
|
+
* assert.equal(Number.multiplyAll([1.5, 2, 3]), 9) // 1.5 × 2 × 3 = 9
|
|
470
|
+
*
|
|
471
|
+
* // Empty collection returns the multiplicative identity (1)
|
|
472
|
+
* assert.equal(Number.multiplyAll([]), 1)
|
|
173
473
|
*
|
|
174
|
-
*
|
|
175
|
-
* assert.
|
|
474
|
+
* // Single element collection
|
|
475
|
+
* assert.equal(Number.multiplyAll([42]), 42)
|
|
476
|
+
*
|
|
477
|
+
* // Products with negative numbers
|
|
478
|
+
* assert.equal(Number.multiplyAll([2, -3, 4]), -24) // 2 × (-3) × 4 = -24
|
|
479
|
+
* assert.equal(Number.multiplyAll([-2, -3]), 6) // (-2) × (-3) = 6
|
|
480
|
+
*
|
|
481
|
+
* // Zero property - if any element is zero, product is zero
|
|
482
|
+
* assert.equal(Number.multiplyAll([2, 0, 3]), 0)
|
|
483
|
+
*
|
|
484
|
+
* // Works with any iterable
|
|
485
|
+
* assert.equal(Number.multiplyAll(new Set([2, 3, 4])), 24)
|
|
486
|
+
*
|
|
487
|
+
* // Using with generated sequences
|
|
488
|
+
* function* range(start: number, end: number) {
|
|
489
|
+
* for (let i = start; i <= end; i++) yield i
|
|
490
|
+
* }
|
|
491
|
+
*
|
|
492
|
+
* // Compute factorial: 5! = 5 × 4 × 3 × 2 × 1 = 120
|
|
493
|
+
* assert.equal(Number.multiplyAll(range(1, 5)), 120)
|
|
176
494
|
* ```
|
|
177
495
|
*
|
|
178
|
-
* @
|
|
496
|
+
* @param collection - An `iterable` containing the `numbers` to multiply
|
|
497
|
+
*
|
|
498
|
+
* @returns The product of all numbers in the collection, or 1 if the collection
|
|
499
|
+
* is empty
|
|
500
|
+
*/
|
|
501
|
+
export declare const multiplyAll: (collection: Iterable<number>) => number;
|
|
502
|
+
/**
|
|
503
|
+
* Performs division in the set of JavaScript numbers, returning the result
|
|
504
|
+
* wrapped in an `Option` to handle division by zero.
|
|
505
|
+
*
|
|
506
|
+
* @memberof Number
|
|
179
507
|
* @since 2.0.0
|
|
508
|
+
* @category math
|
|
509
|
+
* @example
|
|
510
|
+
*
|
|
511
|
+
* ```ts
|
|
512
|
+
* import * as assert from "node:assert/strict"
|
|
513
|
+
* import { pipe, Option } from "effect"
|
|
514
|
+
* import * as Number from "effect/Number"
|
|
515
|
+
*
|
|
516
|
+
* // Data-first style (direct application)
|
|
517
|
+
* assert.equal(Number.divide(6, 3), Option.some(2)) // 6 ÷ 3 = 2
|
|
518
|
+
* assert.equal(Number.divide(-8, 4), Option.some(-2)) // (-8) ÷ 4 = -2
|
|
519
|
+
* assert.equal(Number.divide(-10, -5), Option.some(2)) // (-10) ÷ (-5) = 2
|
|
520
|
+
* assert.equal(Number.divide(1, 3), Option.some(0.3333333333333333)) // Note: floating-point approximation
|
|
521
|
+
*
|
|
522
|
+
* // Handling division by zero
|
|
523
|
+
* assert.equal(Number.divide(6, 0), Option.none()) // 6 ÷ 0 is undefined
|
|
524
|
+
*
|
|
525
|
+
* // Data-last style (pipeable)
|
|
526
|
+
* assert.equal(
|
|
527
|
+
* pipe(
|
|
528
|
+
* 10,
|
|
529
|
+
* Number.divide(2) // 10 ÷ 2 = 5
|
|
530
|
+
* ),
|
|
531
|
+
* Option.some(5)
|
|
532
|
+
* )
|
|
533
|
+
*
|
|
534
|
+
* // Chaining multiple divisions using Option combinators
|
|
535
|
+
* assert.equal(
|
|
536
|
+
* pipe(
|
|
537
|
+
* Option.some(24),
|
|
538
|
+
* Option.flatMap((n) => Number.divide(n, 2)), // 24 ÷ 2 = 12
|
|
539
|
+
* Option.flatMap(Number.divide(3)), // 12 ÷ 3 = 4
|
|
540
|
+
* Option.flatMap(Number.divide(2)) // 4 ÷ 2 = 2
|
|
541
|
+
* ),
|
|
542
|
+
* Option.some(2)
|
|
543
|
+
* )
|
|
544
|
+
*
|
|
545
|
+
* // Division-by-one property: a ÷ 1 = a
|
|
546
|
+
* assert.equal(Number.divide(42, 1), Option.some(42))
|
|
547
|
+
*
|
|
548
|
+
* // Self-division property: a ÷ a = 1 (for a ≠ 0)
|
|
549
|
+
* assert.equal(Number.divide(42, 42), Option.some(1))
|
|
550
|
+
*
|
|
551
|
+
* // Non-commutative property: a ÷ b ≠ b ÷ a
|
|
552
|
+
* assert.notDeepStrictEqual(
|
|
553
|
+
* Number.divide(6, 3), // 6 ÷ 3 = 2
|
|
554
|
+
* Number.divide(3, 6) // 3 ÷ 6 = 0.5
|
|
555
|
+
* )
|
|
556
|
+
* ```
|
|
180
557
|
*/
|
|
181
558
|
export declare const divide: {
|
|
182
559
|
/**
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
* @example
|
|
186
|
-
* ```ts
|
|
187
|
-
* import * as assert from "node:assert"
|
|
188
|
-
* import { Number, Option } from "effect"
|
|
560
|
+
* Returns a function that divides its input by a specified divisor.
|
|
189
561
|
*
|
|
190
|
-
*
|
|
191
|
-
* assert.deepStrictEqual(Number.divide(6, 0), Option.none())
|
|
192
|
-
* ```
|
|
562
|
+
* @param divisor - The number to divide by
|
|
193
563
|
*
|
|
194
|
-
* @
|
|
195
|
-
*
|
|
564
|
+
* @returns A function that takes a dividend and returns the quotient wrapped
|
|
565
|
+
* in an Option (Option.none() if divisor is 0)
|
|
196
566
|
*/
|
|
197
|
-
(
|
|
567
|
+
(divisor: number): (dividend: number) => Option<number>;
|
|
198
568
|
/**
|
|
199
|
-
*
|
|
569
|
+
* Divides the dividend by the divisor and returns the quotient wrapped in an
|
|
570
|
+
* Option.
|
|
200
571
|
*
|
|
201
|
-
* @
|
|
202
|
-
*
|
|
203
|
-
* import * as assert from "node:assert"
|
|
204
|
-
* import { Number, Option } from "effect"
|
|
572
|
+
* @param dividend - The number to be divided
|
|
573
|
+
* @param divisor - The number to divide by
|
|
205
574
|
*
|
|
206
|
-
*
|
|
207
|
-
* assert.deepStrictEqual(Number.divide(6, 0), Option.none())
|
|
208
|
-
* ```
|
|
209
|
-
*
|
|
210
|
-
* @category math
|
|
211
|
-
* @since 2.0.0
|
|
575
|
+
* @returns Some(quotient) if the divisor is not 0, None otherwise
|
|
212
576
|
*/
|
|
213
|
-
(
|
|
577
|
+
(dividend: number, divisor: number): Option<number>;
|
|
214
578
|
};
|
|
215
579
|
/**
|
|
216
|
-
*
|
|
580
|
+
* Performs division in the set of JavaScript numbers, but misbehaves for
|
|
581
|
+
* division by zero.
|
|
582
|
+
*
|
|
583
|
+
* Unlike {@link module:Number.divide} which returns an Option, this function
|
|
584
|
+
* directly returns a number or `Infinity` or `NaN`.
|
|
217
585
|
*
|
|
218
|
-
*
|
|
586
|
+
* - If the `divisor` is zero, it returns `Infinity`.
|
|
587
|
+
* - If both the `dividend` and the `divisor` are zero, then it returns `NaN`.
|
|
219
588
|
*
|
|
589
|
+
* @memberof Number
|
|
590
|
+
* @since 2.0.0
|
|
591
|
+
* @category math
|
|
220
592
|
* @example
|
|
221
|
-
* ```ts
|
|
222
|
-
* import * as assert from "node:assert"
|
|
223
|
-
* import { unsafeDivide } from "effect/Number"
|
|
224
593
|
*
|
|
225
|
-
*
|
|
594
|
+
* ```ts
|
|
595
|
+
* import * as assert from "node:assert/strict"
|
|
596
|
+
* import { pipe } from "effect"
|
|
597
|
+
* import * as Number from "effect/Number"
|
|
598
|
+
*
|
|
599
|
+
* // Data-first style (direct application)
|
|
600
|
+
* assert.equal(Number.unsafeDivide(6, 3), 2) // 6 ÷ 3 = 2
|
|
601
|
+
* assert.equal(Number.unsafeDivide(-8, 4), -2) // (-8) ÷ 4 = -2
|
|
602
|
+
* assert.equal(Number.unsafeDivide(-10, -5), 2) // (-10) ÷ (-5) = 2
|
|
603
|
+
* assert.equal(Number.unsafeDivide(1, 3), 0.3333333333333333)
|
|
604
|
+
*
|
|
605
|
+
* // Data-last style (pipeable)
|
|
606
|
+
* assert.equal(
|
|
607
|
+
* pipe(
|
|
608
|
+
* 10,
|
|
609
|
+
* Number.unsafeDivide(2) // 10 ÷ 2 = 5
|
|
610
|
+
* ),
|
|
611
|
+
* 5
|
|
612
|
+
* )
|
|
613
|
+
*
|
|
614
|
+
* // Chaining multiple divisions
|
|
615
|
+
* assert.equal(
|
|
616
|
+
* pipe(
|
|
617
|
+
* 24,
|
|
618
|
+
* Number.unsafeDivide(2), // 24 ÷ 2 = 12
|
|
619
|
+
* Number.unsafeDivide(3), // 12 ÷ 3 = 4
|
|
620
|
+
* Number.unsafeDivide(2) // 4 ÷ 2 = 2
|
|
621
|
+
* ),
|
|
622
|
+
* 2
|
|
623
|
+
* )
|
|
624
|
+
*
|
|
625
|
+
* assert.equal(Number.unsafeDivide(6, 0), Infinity)
|
|
626
|
+
*
|
|
627
|
+
* assert.equal(Number.unsafeDivide(0, 0), NaN)
|
|
628
|
+
*
|
|
629
|
+
* // Compare with safe division
|
|
630
|
+
* const safeResult = Number.divide(6, 3) // Option.some(2)
|
|
631
|
+
* const unsafeResult = Number.unsafeDivide(6, 3) // 2 directly
|
|
226
632
|
* ```
|
|
227
633
|
*
|
|
228
|
-
* @
|
|
229
|
-
* @
|
|
634
|
+
* @throws - An {@link module:Number.DivisionByZeroError} if the divisor is zero.
|
|
635
|
+
* @see {@link module:Number.divide} - Safe division returning an Option
|
|
230
636
|
*/
|
|
231
637
|
export declare const unsafeDivide: {
|
|
232
638
|
/**
|
|
233
|
-
*
|
|
639
|
+
* Returns a function that divides its input by a specified divisor.
|
|
234
640
|
*
|
|
235
|
-
*
|
|
641
|
+
* @param divisor - The number to divide by
|
|
236
642
|
*
|
|
237
|
-
* @
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* import { unsafeDivide } from "effect/Number"
|
|
241
|
-
*
|
|
242
|
-
* assert.deepStrictEqual(unsafeDivide(6, 3), 2)
|
|
243
|
-
* ```
|
|
244
|
-
*
|
|
245
|
-
* @category math
|
|
246
|
-
* @since 2.0.0
|
|
643
|
+
* @returns A function that takes a dividend and returns the quotient
|
|
644
|
+
* @throws - An {@link module:Number.DivisionByZeroError} if the divisor is
|
|
645
|
+
* zero
|
|
247
646
|
*/
|
|
248
|
-
(
|
|
647
|
+
(divisor: number): (dividend: number) => number;
|
|
249
648
|
/**
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
* Throws a `RangeError` if the divisor is `0`.
|
|
649
|
+
* Divides the dividend by the divisor and returns the quotient.
|
|
253
650
|
*
|
|
254
|
-
*
|
|
255
|
-
* ```ts
|
|
256
|
-
* import * as assert from "node:assert"
|
|
257
|
-
* import { unsafeDivide } from "effect/Number"
|
|
651
|
+
* If the divisor is zero, it returns Infinity.
|
|
258
652
|
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
653
|
+
* @param dividend - The number to be divided
|
|
654
|
+
* @param divisor - The number to divide by
|
|
261
655
|
*
|
|
262
|
-
* @
|
|
263
|
-
* @since 2.0.0
|
|
656
|
+
* @returns The quotient of the division
|
|
264
657
|
*/
|
|
265
|
-
(
|
|
658
|
+
(dividend: number, divisor: number): number;
|
|
266
659
|
};
|
|
267
660
|
/**
|
|
268
661
|
* Returns the result of adding `1` to a given number.
|
|
269
662
|
*
|
|
663
|
+
* @memberof Number
|
|
664
|
+
* @since 2.0.0
|
|
665
|
+
* @category math
|
|
270
666
|
* @example
|
|
667
|
+
*
|
|
271
668
|
* ```ts
|
|
272
|
-
* import * as assert from "node:assert"
|
|
669
|
+
* import * as assert from "node:assert/strict"
|
|
273
670
|
* import { increment } from "effect/Number"
|
|
274
671
|
*
|
|
275
|
-
* assert.
|
|
672
|
+
* assert.equal(increment(2), 3)
|
|
276
673
|
* ```
|
|
277
|
-
*
|
|
278
|
-
* @category math
|
|
279
|
-
* @since 2.0.0
|
|
280
674
|
*/
|
|
281
675
|
export declare const increment: (n: number) => number;
|
|
282
676
|
/**
|
|
283
677
|
* Decrements a number by `1`.
|
|
284
678
|
*
|
|
679
|
+
* @memberof Number
|
|
680
|
+
* @since 2.0.0
|
|
681
|
+
* @category math
|
|
285
682
|
* @example
|
|
683
|
+
*
|
|
286
684
|
* ```ts
|
|
287
|
-
* import * as assert from "node:assert"
|
|
685
|
+
* import * as assert from "node:assert/strict"
|
|
288
686
|
* import { decrement } from "effect/Number"
|
|
289
687
|
*
|
|
290
|
-
* assert.
|
|
688
|
+
* assert.equal(decrement(3), 2)
|
|
291
689
|
* ```
|
|
292
|
-
*
|
|
293
|
-
* @category math
|
|
294
|
-
* @since 2.0.0
|
|
295
690
|
*/
|
|
296
691
|
export declare const decrement: (n: number) => number;
|
|
297
692
|
/**
|
|
298
|
-
* @
|
|
693
|
+
* @memberof Number
|
|
299
694
|
* @since 2.0.0
|
|
695
|
+
* @category instances
|
|
300
696
|
*/
|
|
301
697
|
export declare const Equivalence: equivalence.Equivalence<number>;
|
|
302
698
|
/**
|
|
303
|
-
* @
|
|
699
|
+
* @memberof Number
|
|
304
700
|
* @since 2.0.0
|
|
701
|
+
* @category instances
|
|
305
702
|
*/
|
|
306
703
|
export declare const Order: order.Order<number>;
|
|
307
704
|
/**
|
|
308
|
-
* Returns `true` if the first argument is less than the second, otherwise
|
|
705
|
+
* Returns `true` if the first argument is less than the second, otherwise
|
|
706
|
+
* `false`.
|
|
309
707
|
*
|
|
708
|
+
* @memberof Number
|
|
709
|
+
* @since 2.0.0
|
|
710
|
+
* @category predicates
|
|
310
711
|
* @example
|
|
712
|
+
*
|
|
311
713
|
* ```ts
|
|
312
|
-
* import * as assert from "node:assert"
|
|
714
|
+
* import * as assert from "node:assert/strict"
|
|
313
715
|
* import { lessThan } from "effect/Number"
|
|
314
716
|
*
|
|
315
|
-
* assert.
|
|
316
|
-
* assert.
|
|
317
|
-
* assert.
|
|
717
|
+
* assert.equal(lessThan(2, 3), true)
|
|
718
|
+
* assert.equal(lessThan(3, 3), false)
|
|
719
|
+
* assert.equal(lessThan(4, 3), false)
|
|
318
720
|
* ```
|
|
319
|
-
*
|
|
320
|
-
* @category predicates
|
|
321
|
-
* @since 2.0.0
|
|
322
721
|
*/
|
|
323
722
|
export declare const lessThan: {
|
|
324
723
|
/**
|
|
325
|
-
* Returns `true` if the first argument is less than the second, otherwise
|
|
724
|
+
* Returns `true` if the first argument is less than the second, otherwise
|
|
725
|
+
* `false`.
|
|
326
726
|
*
|
|
727
|
+
* @memberof Number
|
|
728
|
+
* @since 2.0.0
|
|
729
|
+
* @category predicates
|
|
327
730
|
* @example
|
|
731
|
+
*
|
|
328
732
|
* ```ts
|
|
329
|
-
* import * as assert from "node:assert"
|
|
733
|
+
* import * as assert from "node:assert/strict"
|
|
330
734
|
* import { lessThan } from "effect/Number"
|
|
331
735
|
*
|
|
332
|
-
* assert.
|
|
333
|
-
* assert.
|
|
334
|
-
* assert.
|
|
736
|
+
* assert.equal(lessThan(2, 3), true)
|
|
737
|
+
* assert.equal(lessThan(3, 3), false)
|
|
738
|
+
* assert.equal(lessThan(4, 3), false)
|
|
335
739
|
* ```
|
|
336
|
-
*
|
|
337
|
-
* @category predicates
|
|
338
|
-
* @since 2.0.0
|
|
339
740
|
*/
|
|
340
741
|
(that: number): (self: number) => boolean;
|
|
341
742
|
/**
|
|
342
|
-
* Returns `true` if the first argument is less than the second, otherwise
|
|
743
|
+
* Returns `true` if the first argument is less than the second, otherwise
|
|
744
|
+
* `false`.
|
|
343
745
|
*
|
|
746
|
+
* @memberof Number
|
|
747
|
+
* @since 2.0.0
|
|
748
|
+
* @category predicates
|
|
344
749
|
* @example
|
|
750
|
+
*
|
|
345
751
|
* ```ts
|
|
346
|
-
* import * as assert from "node:assert"
|
|
752
|
+
* import * as assert from "node:assert/strict"
|
|
347
753
|
* import { lessThan } from "effect/Number"
|
|
348
754
|
*
|
|
349
|
-
* assert.
|
|
350
|
-
* assert.
|
|
351
|
-
* assert.
|
|
755
|
+
* assert.equal(lessThan(2, 3), true)
|
|
756
|
+
* assert.equal(lessThan(3, 3), false)
|
|
757
|
+
* assert.equal(lessThan(4, 3), false)
|
|
352
758
|
* ```
|
|
353
|
-
*
|
|
354
|
-
* @category predicates
|
|
355
|
-
* @since 2.0.0
|
|
356
759
|
*/
|
|
357
760
|
(self: number, that: number): boolean;
|
|
358
761
|
};
|
|
359
762
|
/**
|
|
360
|
-
* Returns a function that checks if a given `number` is less than or equal to
|
|
763
|
+
* Returns a function that checks if a given `number` is less than or equal to
|
|
764
|
+
* the provided one.
|
|
361
765
|
*
|
|
766
|
+
* @memberof Number
|
|
767
|
+
* @since 2.0.0
|
|
768
|
+
* @category predicates
|
|
362
769
|
* @example
|
|
770
|
+
*
|
|
363
771
|
* ```ts
|
|
364
|
-
* import * as assert from "node:assert"
|
|
772
|
+
* import * as assert from "node:assert/strict"
|
|
365
773
|
* import { lessThanOrEqualTo } from "effect/Number"
|
|
366
774
|
*
|
|
367
|
-
* assert.
|
|
368
|
-
* assert.
|
|
369
|
-
* assert.
|
|
775
|
+
* assert.equal(lessThanOrEqualTo(2, 3), true)
|
|
776
|
+
* assert.equal(lessThanOrEqualTo(3, 3), true)
|
|
777
|
+
* assert.equal(lessThanOrEqualTo(4, 3), false)
|
|
370
778
|
* ```
|
|
371
|
-
*
|
|
372
|
-
* @category predicates
|
|
373
|
-
* @since 2.0.0
|
|
374
779
|
*/
|
|
375
780
|
export declare const lessThanOrEqualTo: {
|
|
376
781
|
/**
|
|
377
|
-
* Returns a function that checks if a given `number` is less than or equal to
|
|
782
|
+
* Returns a function that checks if a given `number` is less than or equal to
|
|
783
|
+
* the provided one.
|
|
378
784
|
*
|
|
785
|
+
* @memberof Number
|
|
786
|
+
* @since 2.0.0
|
|
787
|
+
* @category predicates
|
|
379
788
|
* @example
|
|
789
|
+
*
|
|
380
790
|
* ```ts
|
|
381
|
-
* import * as assert from "node:assert"
|
|
791
|
+
* import * as assert from "node:assert/strict"
|
|
382
792
|
* import { lessThanOrEqualTo } from "effect/Number"
|
|
383
793
|
*
|
|
384
|
-
* assert.
|
|
385
|
-
* assert.
|
|
386
|
-
* assert.
|
|
794
|
+
* assert.equal(lessThanOrEqualTo(2, 3), true)
|
|
795
|
+
* assert.equal(lessThanOrEqualTo(3, 3), true)
|
|
796
|
+
* assert.equal(lessThanOrEqualTo(4, 3), false)
|
|
387
797
|
* ```
|
|
388
|
-
*
|
|
389
|
-
* @category predicates
|
|
390
|
-
* @since 2.0.0
|
|
391
798
|
*/
|
|
392
799
|
(that: number): (self: number) => boolean;
|
|
393
800
|
/**
|
|
394
|
-
* Returns a function that checks if a given `number` is less than or equal to
|
|
801
|
+
* Returns a function that checks if a given `number` is less than or equal to
|
|
802
|
+
* the provided one.
|
|
395
803
|
*
|
|
804
|
+
* @memberof Number
|
|
805
|
+
* @since 2.0.0
|
|
806
|
+
* @category predicates
|
|
396
807
|
* @example
|
|
808
|
+
*
|
|
397
809
|
* ```ts
|
|
398
|
-
* import * as assert from "node:assert"
|
|
810
|
+
* import * as assert from "node:assert/strict"
|
|
399
811
|
* import { lessThanOrEqualTo } from "effect/Number"
|
|
400
812
|
*
|
|
401
|
-
* assert.
|
|
402
|
-
* assert.
|
|
403
|
-
* assert.
|
|
813
|
+
* assert.equal(lessThanOrEqualTo(2, 3), true)
|
|
814
|
+
* assert.equal(lessThanOrEqualTo(3, 3), true)
|
|
815
|
+
* assert.equal(lessThanOrEqualTo(4, 3), false)
|
|
404
816
|
* ```
|
|
405
|
-
*
|
|
406
|
-
* @category predicates
|
|
407
|
-
* @since 2.0.0
|
|
408
817
|
*/
|
|
409
818
|
(self: number, that: number): boolean;
|
|
410
819
|
};
|
|
411
820
|
/**
|
|
412
|
-
* Returns `true` if the first argument is greater than the second, otherwise
|
|
821
|
+
* Returns `true` if the first argument is greater than the second, otherwise
|
|
822
|
+
* `false`.
|
|
413
823
|
*
|
|
824
|
+
* @memberof Number
|
|
825
|
+
* @since 2.0.0
|
|
826
|
+
* @category predicates
|
|
414
827
|
* @example
|
|
828
|
+
*
|
|
415
829
|
* ```ts
|
|
416
|
-
* import * as assert from "node:assert"
|
|
830
|
+
* import * as assert from "node:assert/strict"
|
|
417
831
|
* import { greaterThan } from "effect/Number"
|
|
418
832
|
*
|
|
419
|
-
* assert.
|
|
420
|
-
* assert.
|
|
421
|
-
* assert.
|
|
833
|
+
* assert.equal(greaterThan(2, 3), false)
|
|
834
|
+
* assert.equal(greaterThan(3, 3), false)
|
|
835
|
+
* assert.equal(greaterThan(4, 3), true)
|
|
422
836
|
* ```
|
|
423
|
-
*
|
|
424
|
-
* @category predicates
|
|
425
|
-
* @since 2.0.0
|
|
426
837
|
*/
|
|
427
838
|
export declare const greaterThan: {
|
|
428
839
|
/**
|
|
429
|
-
* Returns `true` if the first argument is greater than the second, otherwise
|
|
840
|
+
* Returns `true` if the first argument is greater than the second, otherwise
|
|
841
|
+
* `false`.
|
|
430
842
|
*
|
|
843
|
+
* @memberof Number
|
|
844
|
+
* @since 2.0.0
|
|
845
|
+
* @category predicates
|
|
431
846
|
* @example
|
|
847
|
+
*
|
|
432
848
|
* ```ts
|
|
433
|
-
* import * as assert from "node:assert"
|
|
849
|
+
* import * as assert from "node:assert/strict"
|
|
434
850
|
* import { greaterThan } from "effect/Number"
|
|
435
851
|
*
|
|
436
|
-
* assert.
|
|
437
|
-
* assert.
|
|
438
|
-
* assert.
|
|
852
|
+
* assert.equal(greaterThan(2, 3), false)
|
|
853
|
+
* assert.equal(greaterThan(3, 3), false)
|
|
854
|
+
* assert.equal(greaterThan(4, 3), true)
|
|
439
855
|
* ```
|
|
440
|
-
*
|
|
441
|
-
* @category predicates
|
|
442
|
-
* @since 2.0.0
|
|
443
856
|
*/
|
|
444
857
|
(that: number): (self: number) => boolean;
|
|
445
858
|
/**
|
|
446
|
-
* Returns `true` if the first argument is greater than the second, otherwise
|
|
859
|
+
* Returns `true` if the first argument is greater than the second, otherwise
|
|
860
|
+
* `false`.
|
|
447
861
|
*
|
|
862
|
+
* @memberof Number
|
|
863
|
+
* @since 2.0.0
|
|
864
|
+
* @category predicates
|
|
448
865
|
* @example
|
|
866
|
+
*
|
|
449
867
|
* ```ts
|
|
450
|
-
* import * as assert from "node:assert"
|
|
868
|
+
* import * as assert from "node:assert/strict"
|
|
451
869
|
* import { greaterThan } from "effect/Number"
|
|
452
870
|
*
|
|
453
|
-
* assert.
|
|
454
|
-
* assert.
|
|
455
|
-
* assert.
|
|
871
|
+
* assert.equal(greaterThan(2, 3), false)
|
|
872
|
+
* assert.equal(greaterThan(3, 3), false)
|
|
873
|
+
* assert.equal(greaterThan(4, 3), true)
|
|
456
874
|
* ```
|
|
457
|
-
*
|
|
458
|
-
* @category predicates
|
|
459
|
-
* @since 2.0.0
|
|
460
875
|
*/
|
|
461
876
|
(self: number, that: number): boolean;
|
|
462
877
|
};
|
|
463
878
|
/**
|
|
464
|
-
* Returns a function that checks if a given `number` is greater than or equal
|
|
879
|
+
* Returns a function that checks if a given `number` is greater than or equal
|
|
880
|
+
* to the provided one.
|
|
465
881
|
*
|
|
882
|
+
* @memberof Number
|
|
883
|
+
* @since 2.0.0
|
|
884
|
+
* @category predicates
|
|
466
885
|
* @example
|
|
886
|
+
*
|
|
467
887
|
* ```ts
|
|
468
|
-
* import * as assert from "node:assert"
|
|
888
|
+
* import * as assert from "node:assert/strict"
|
|
469
889
|
* import { greaterThanOrEqualTo } from "effect/Number"
|
|
470
890
|
*
|
|
471
|
-
* assert.
|
|
472
|
-
* assert.
|
|
473
|
-
* assert.
|
|
891
|
+
* assert.equal(greaterThanOrEqualTo(2, 3), false)
|
|
892
|
+
* assert.equal(greaterThanOrEqualTo(3, 3), true)
|
|
893
|
+
* assert.equal(greaterThanOrEqualTo(4, 3), true)
|
|
474
894
|
* ```
|
|
475
|
-
*
|
|
476
|
-
* @category predicates
|
|
477
|
-
* @since 2.0.0
|
|
478
895
|
*/
|
|
479
896
|
export declare const greaterThanOrEqualTo: {
|
|
480
897
|
/**
|
|
481
|
-
* Returns a function that checks if a given `number` is greater than or equal
|
|
898
|
+
* Returns a function that checks if a given `number` is greater than or equal
|
|
899
|
+
* to the provided one.
|
|
482
900
|
*
|
|
901
|
+
* @memberof Number
|
|
902
|
+
* @since 2.0.0
|
|
903
|
+
* @category predicates
|
|
483
904
|
* @example
|
|
905
|
+
*
|
|
484
906
|
* ```ts
|
|
485
|
-
* import * as assert from "node:assert"
|
|
907
|
+
* import * as assert from "node:assert/strict"
|
|
486
908
|
* import { greaterThanOrEqualTo } from "effect/Number"
|
|
487
909
|
*
|
|
488
|
-
* assert.
|
|
489
|
-
* assert.
|
|
490
|
-
* assert.
|
|
910
|
+
* assert.equal(greaterThanOrEqualTo(2, 3), false)
|
|
911
|
+
* assert.equal(greaterThanOrEqualTo(3, 3), true)
|
|
912
|
+
* assert.equal(greaterThanOrEqualTo(4, 3), true)
|
|
491
913
|
* ```
|
|
492
|
-
*
|
|
493
|
-
* @category predicates
|
|
494
|
-
* @since 2.0.0
|
|
495
914
|
*/
|
|
496
915
|
(that: number): (self: number) => boolean;
|
|
497
916
|
/**
|
|
498
|
-
* Returns a function that checks if a given `number` is greater than or equal
|
|
917
|
+
* Returns a function that checks if a given `number` is greater than or equal
|
|
918
|
+
* to the provided one.
|
|
499
919
|
*
|
|
920
|
+
* @memberof Number
|
|
921
|
+
* @since 2.0.0
|
|
922
|
+
* @category predicates
|
|
500
923
|
* @example
|
|
924
|
+
*
|
|
501
925
|
* ```ts
|
|
502
|
-
* import * as assert from "node:assert"
|
|
926
|
+
* import * as assert from "node:assert/strict"
|
|
503
927
|
* import { greaterThanOrEqualTo } from "effect/Number"
|
|
504
928
|
*
|
|
505
|
-
* assert.
|
|
506
|
-
* assert.
|
|
507
|
-
* assert.
|
|
929
|
+
* assert.equal(greaterThanOrEqualTo(2, 3), false)
|
|
930
|
+
* assert.equal(greaterThanOrEqualTo(3, 3), true)
|
|
931
|
+
* assert.equal(greaterThanOrEqualTo(4, 3), true)
|
|
508
932
|
* ```
|
|
509
|
-
*
|
|
510
|
-
* @category predicates
|
|
511
|
-
* @since 2.0.0
|
|
512
933
|
*/
|
|
513
934
|
(self: number, that: number): boolean;
|
|
514
935
|
};
|
|
515
936
|
/**
|
|
516
937
|
* Checks if a `number` is between a `minimum` and `maximum` value (inclusive).
|
|
517
938
|
*
|
|
939
|
+
* @memberof Number
|
|
940
|
+
* @since 2.0.0
|
|
941
|
+
* @category predicates
|
|
518
942
|
* @example
|
|
943
|
+
*
|
|
519
944
|
* ```ts
|
|
520
|
-
* import * as assert from "node:assert"
|
|
945
|
+
* import * as assert from "node:assert/strict"
|
|
521
946
|
* import { Number } from "effect"
|
|
522
947
|
*
|
|
523
948
|
* const between = Number.between({ minimum: 0, maximum: 5 })
|
|
524
949
|
*
|
|
525
|
-
* assert.
|
|
526
|
-
* assert.
|
|
527
|
-
* assert.
|
|
950
|
+
* assert.equal(between(3), true)
|
|
951
|
+
* assert.equal(between(-1), false)
|
|
952
|
+
* assert.equal(between(6), false)
|
|
528
953
|
* ```
|
|
529
|
-
*
|
|
530
|
-
* @category predicates
|
|
531
|
-
* @since 2.0.0
|
|
532
954
|
*/
|
|
533
955
|
export declare const between: {
|
|
534
956
|
/**
|
|
535
957
|
* Checks if a `number` is between a `minimum` and `maximum` value (inclusive).
|
|
536
958
|
*
|
|
959
|
+
* @memberof Number
|
|
960
|
+
* @since 2.0.0
|
|
961
|
+
* @category predicates
|
|
537
962
|
* @example
|
|
963
|
+
*
|
|
538
964
|
* ```ts
|
|
539
|
-
* import * as assert from "node:assert"
|
|
965
|
+
* import * as assert from "node:assert/strict"
|
|
540
966
|
* import { Number } from "effect"
|
|
541
967
|
*
|
|
542
968
|
* const between = Number.between({ minimum: 0, maximum: 5 })
|
|
543
969
|
*
|
|
544
|
-
* assert.
|
|
545
|
-
* assert.
|
|
546
|
-
* assert.
|
|
970
|
+
* assert.equal(between(3), true)
|
|
971
|
+
* assert.equal(between(-1), false)
|
|
972
|
+
* assert.equal(between(6), false)
|
|
547
973
|
* ```
|
|
548
|
-
*
|
|
549
|
-
* @category predicates
|
|
550
|
-
* @since 2.0.0
|
|
551
974
|
*/
|
|
552
975
|
(options: {
|
|
553
976
|
minimum: number;
|
|
@@ -556,20 +979,21 @@ export declare const between: {
|
|
|
556
979
|
/**
|
|
557
980
|
* Checks if a `number` is between a `minimum` and `maximum` value (inclusive).
|
|
558
981
|
*
|
|
982
|
+
* @memberof Number
|
|
983
|
+
* @since 2.0.0
|
|
984
|
+
* @category predicates
|
|
559
985
|
* @example
|
|
986
|
+
*
|
|
560
987
|
* ```ts
|
|
561
|
-
* import * as assert from "node:assert"
|
|
988
|
+
* import * as assert from "node:assert/strict"
|
|
562
989
|
* import { Number } from "effect"
|
|
563
990
|
*
|
|
564
991
|
* const between = Number.between({ minimum: 0, maximum: 5 })
|
|
565
992
|
*
|
|
566
|
-
* assert.
|
|
567
|
-
* assert.
|
|
568
|
-
* assert.
|
|
993
|
+
* assert.equal(between(3), true)
|
|
994
|
+
* assert.equal(between(-1), false)
|
|
995
|
+
* assert.equal(between(6), false)
|
|
569
996
|
* ```
|
|
570
|
-
*
|
|
571
|
-
* @category predicates
|
|
572
|
-
* @since 2.0.0
|
|
573
997
|
*/
|
|
574
998
|
(self: number, options: {
|
|
575
999
|
minimum: number;
|
|
@@ -577,15 +1001,21 @@ export declare const between: {
|
|
|
577
1001
|
}): boolean;
|
|
578
1002
|
};
|
|
579
1003
|
/**
|
|
580
|
-
* Restricts the given `number` to be within the range specified by the
|
|
1004
|
+
* Restricts the given `number` to be within the range specified by the
|
|
1005
|
+
* `minimum` and `maximum` values.
|
|
581
1006
|
*
|
|
582
|
-
* - If the `number` is less than the `minimum` value, the function returns the
|
|
583
|
-
*
|
|
1007
|
+
* - If the `number` is less than the `minimum` value, the function returns the
|
|
1008
|
+
* `minimum` value.
|
|
1009
|
+
* - If the `number` is greater than the `maximum` value, the function returns the
|
|
1010
|
+
* `maximum` value.
|
|
584
1011
|
* - Otherwise, it returns the original `number`.
|
|
585
1012
|
*
|
|
1013
|
+
* @memberof Number
|
|
1014
|
+
* @since 2.0.0
|
|
586
1015
|
* @example
|
|
1016
|
+
*
|
|
587
1017
|
* ```ts
|
|
588
|
-
* import * as assert from "node:assert"
|
|
1018
|
+
* import * as assert from "node:assert/strict"
|
|
589
1019
|
* import { Number } from "effect"
|
|
590
1020
|
*
|
|
591
1021
|
* const clamp = Number.clamp({ minimum: 1, maximum: 5 })
|
|
@@ -594,20 +1024,24 @@ export declare const between: {
|
|
|
594
1024
|
* assert.equal(clamp(0), 1)
|
|
595
1025
|
* assert.equal(clamp(6), 5)
|
|
596
1026
|
* ```
|
|
597
|
-
*
|
|
598
|
-
* @since 2.0.0
|
|
599
1027
|
*/
|
|
600
1028
|
export declare const clamp: {
|
|
601
1029
|
/**
|
|
602
|
-
* Restricts the given `number` to be within the range specified by the
|
|
1030
|
+
* Restricts the given `number` to be within the range specified by the
|
|
1031
|
+
* `minimum` and `maximum` values.
|
|
603
1032
|
*
|
|
604
|
-
* - If the `number` is less than the `minimum` value, the function returns the
|
|
605
|
-
*
|
|
1033
|
+
* - If the `number` is less than the `minimum` value, the function returns the
|
|
1034
|
+
* `minimum` value.
|
|
1035
|
+
* - If the `number` is greater than the `maximum` value, the function returns the
|
|
1036
|
+
* `maximum` value.
|
|
606
1037
|
* - Otherwise, it returns the original `number`.
|
|
607
1038
|
*
|
|
1039
|
+
* @memberof Number
|
|
1040
|
+
* @since 2.0.0
|
|
608
1041
|
* @example
|
|
1042
|
+
*
|
|
609
1043
|
* ```ts
|
|
610
|
-
* import * as assert from "node:assert"
|
|
1044
|
+
* import * as assert from "node:assert/strict"
|
|
611
1045
|
* import { Number } from "effect"
|
|
612
1046
|
*
|
|
613
1047
|
* const clamp = Number.clamp({ minimum: 1, maximum: 5 })
|
|
@@ -616,23 +1050,27 @@ export declare const clamp: {
|
|
|
616
1050
|
* assert.equal(clamp(0), 1)
|
|
617
1051
|
* assert.equal(clamp(6), 5)
|
|
618
1052
|
* ```
|
|
619
|
-
*
|
|
620
|
-
* @since 2.0.0
|
|
621
1053
|
*/
|
|
622
1054
|
(options: {
|
|
623
1055
|
minimum: number;
|
|
624
1056
|
maximum: number;
|
|
625
1057
|
}): (self: number) => number;
|
|
626
1058
|
/**
|
|
627
|
-
* Restricts the given `number` to be within the range specified by the
|
|
1059
|
+
* Restricts the given `number` to be within the range specified by the
|
|
1060
|
+
* `minimum` and `maximum` values.
|
|
628
1061
|
*
|
|
629
|
-
* - If the `number` is less than the `minimum` value, the function returns the
|
|
630
|
-
*
|
|
1062
|
+
* - If the `number` is less than the `minimum` value, the function returns the
|
|
1063
|
+
* `minimum` value.
|
|
1064
|
+
* - If the `number` is greater than the `maximum` value, the function returns the
|
|
1065
|
+
* `maximum` value.
|
|
631
1066
|
* - Otherwise, it returns the original `number`.
|
|
632
1067
|
*
|
|
1068
|
+
* @memberof Number
|
|
1069
|
+
* @since 2.0.0
|
|
633
1070
|
* @example
|
|
1071
|
+
*
|
|
634
1072
|
* ```ts
|
|
635
|
-
* import * as assert from "node:assert"
|
|
1073
|
+
* import * as assert from "node:assert/strict"
|
|
636
1074
|
* import { Number } from "effect"
|
|
637
1075
|
*
|
|
638
1076
|
* const clamp = Number.clamp({ minimum: 1, maximum: 5 })
|
|
@@ -641,8 +1079,6 @@ export declare const clamp: {
|
|
|
641
1079
|
* assert.equal(clamp(0), 1)
|
|
642
1080
|
* assert.equal(clamp(6), 5)
|
|
643
1081
|
* ```
|
|
644
|
-
*
|
|
645
|
-
* @since 2.0.0
|
|
646
1082
|
*/
|
|
647
1083
|
(self: number, options: {
|
|
648
1084
|
minimum: number;
|
|
@@ -652,264 +1088,273 @@ export declare const clamp: {
|
|
|
652
1088
|
/**
|
|
653
1089
|
* Returns the minimum between two `number`s.
|
|
654
1090
|
*
|
|
1091
|
+
* @memberof Number
|
|
1092
|
+
* @since 2.0.0
|
|
655
1093
|
* @example
|
|
1094
|
+
*
|
|
656
1095
|
* ```ts
|
|
657
|
-
* import * as assert from "node:assert"
|
|
1096
|
+
* import * as assert from "node:assert/strict"
|
|
658
1097
|
* import { min } from "effect/Number"
|
|
659
1098
|
*
|
|
660
|
-
* assert.
|
|
1099
|
+
* assert.equal(min(2, 3), 2)
|
|
661
1100
|
* ```
|
|
662
|
-
*
|
|
663
|
-
* @since 2.0.0
|
|
664
1101
|
*/
|
|
665
1102
|
export declare const min: {
|
|
666
1103
|
/**
|
|
667
1104
|
* Returns the minimum between two `number`s.
|
|
668
1105
|
*
|
|
1106
|
+
* @memberof Number
|
|
1107
|
+
* @since 2.0.0
|
|
669
1108
|
* @example
|
|
1109
|
+
*
|
|
670
1110
|
* ```ts
|
|
671
|
-
* import * as assert from "node:assert"
|
|
1111
|
+
* import * as assert from "node:assert/strict"
|
|
672
1112
|
* import { min } from "effect/Number"
|
|
673
1113
|
*
|
|
674
|
-
* assert.
|
|
1114
|
+
* assert.equal(min(2, 3), 2)
|
|
675
1115
|
* ```
|
|
676
|
-
*
|
|
677
|
-
* @since 2.0.0
|
|
678
1116
|
*/
|
|
679
1117
|
(that: number): (self: number) => number;
|
|
680
1118
|
/**
|
|
681
1119
|
* Returns the minimum between two `number`s.
|
|
682
1120
|
*
|
|
1121
|
+
* @memberof Number
|
|
1122
|
+
* @since 2.0.0
|
|
683
1123
|
* @example
|
|
1124
|
+
*
|
|
684
1125
|
* ```ts
|
|
685
|
-
* import * as assert from "node:assert"
|
|
1126
|
+
* import * as assert from "node:assert/strict"
|
|
686
1127
|
* import { min } from "effect/Number"
|
|
687
1128
|
*
|
|
688
|
-
* assert.
|
|
1129
|
+
* assert.equal(min(2, 3), 2)
|
|
689
1130
|
* ```
|
|
690
|
-
*
|
|
691
|
-
* @since 2.0.0
|
|
692
1131
|
*/
|
|
693
1132
|
(self: number, that: number): number;
|
|
694
1133
|
};
|
|
695
1134
|
/**
|
|
696
1135
|
* Returns the maximum between two `number`s.
|
|
697
1136
|
*
|
|
1137
|
+
* @memberof Number
|
|
1138
|
+
* @since 2.0.0
|
|
698
1139
|
* @example
|
|
1140
|
+
*
|
|
699
1141
|
* ```ts
|
|
700
|
-
* import * as assert from "node:assert"
|
|
1142
|
+
* import * as assert from "node:assert/strict"
|
|
701
1143
|
* import { max } from "effect/Number"
|
|
702
1144
|
*
|
|
703
|
-
* assert.
|
|
1145
|
+
* assert.equal(max(2, 3), 3)
|
|
704
1146
|
* ```
|
|
705
|
-
*
|
|
706
|
-
* @since 2.0.0
|
|
707
1147
|
*/
|
|
708
1148
|
export declare const max: {
|
|
709
1149
|
/**
|
|
710
1150
|
* Returns the maximum between two `number`s.
|
|
711
1151
|
*
|
|
1152
|
+
* @memberof Number
|
|
1153
|
+
* @since 2.0.0
|
|
712
1154
|
* @example
|
|
1155
|
+
*
|
|
713
1156
|
* ```ts
|
|
714
|
-
* import * as assert from "node:assert"
|
|
1157
|
+
* import * as assert from "node:assert/strict"
|
|
715
1158
|
* import { max } from "effect/Number"
|
|
716
1159
|
*
|
|
717
|
-
* assert.
|
|
1160
|
+
* assert.equal(max(2, 3), 3)
|
|
718
1161
|
* ```
|
|
719
|
-
*
|
|
720
|
-
* @since 2.0.0
|
|
721
1162
|
*/
|
|
722
1163
|
(that: number): (self: number) => number;
|
|
723
1164
|
/**
|
|
724
1165
|
* Returns the maximum between two `number`s.
|
|
725
1166
|
*
|
|
1167
|
+
* @memberof Number
|
|
1168
|
+
* @since 2.0.0
|
|
726
1169
|
* @example
|
|
1170
|
+
*
|
|
727
1171
|
* ```ts
|
|
728
|
-
* import * as assert from "node:assert"
|
|
1172
|
+
* import * as assert from "node:assert/strict"
|
|
729
1173
|
* import { max } from "effect/Number"
|
|
730
1174
|
*
|
|
731
|
-
* assert.
|
|
1175
|
+
* assert.equal(max(2, 3), 3)
|
|
732
1176
|
* ```
|
|
733
|
-
*
|
|
734
|
-
* @since 2.0.0
|
|
735
1177
|
*/
|
|
736
1178
|
(self: number, that: number): number;
|
|
737
1179
|
};
|
|
738
1180
|
/**
|
|
739
1181
|
* Determines the sign of a given `number`.
|
|
740
1182
|
*
|
|
1183
|
+
* @memberof Number
|
|
1184
|
+
* @since 2.0.0
|
|
1185
|
+
* @category math
|
|
741
1186
|
* @example
|
|
1187
|
+
*
|
|
742
1188
|
* ```ts
|
|
743
|
-
* import * as assert from "node:assert"
|
|
1189
|
+
* import * as assert from "node:assert/strict"
|
|
744
1190
|
* import { sign } from "effect/Number"
|
|
745
1191
|
*
|
|
746
|
-
* assert.
|
|
747
|
-
* assert.
|
|
748
|
-
* assert.
|
|
1192
|
+
* assert.equal(sign(-5), -1)
|
|
1193
|
+
* assert.equal(sign(0), 0)
|
|
1194
|
+
* assert.equal(sign(5), 1)
|
|
749
1195
|
* ```
|
|
750
|
-
*
|
|
751
|
-
* @category math
|
|
752
|
-
* @since 2.0.0
|
|
753
1196
|
*/
|
|
754
1197
|
export declare const sign: (n: number) => Ordering;
|
|
755
1198
|
/**
|
|
756
|
-
*
|
|
1199
|
+
* Returns the remainder left over when one operand is divided by a second
|
|
1200
|
+
* operand.
|
|
757
1201
|
*
|
|
758
|
-
*
|
|
759
|
-
* ```ts
|
|
760
|
-
* import * as assert from "node:assert"
|
|
761
|
-
* import { sumAll } from "effect/Number"
|
|
762
|
-
*
|
|
763
|
-
* assert.deepStrictEqual(sumAll([2, 3, 4]), 9)
|
|
764
|
-
* ```
|
|
1202
|
+
* It always takes the sign of the dividend.
|
|
765
1203
|
*
|
|
766
|
-
* @
|
|
1204
|
+
* @memberof Number
|
|
767
1205
|
* @since 2.0.0
|
|
768
|
-
*/
|
|
769
|
-
export declare const sumAll: (collection: Iterable<number>) => number;
|
|
770
|
-
/**
|
|
771
|
-
* Takes an `Iterable` of `number`s and returns their multiplication as a single `number`.
|
|
772
|
-
*
|
|
773
|
-
* @example
|
|
774
|
-
* ```ts
|
|
775
|
-
* import * as assert from "node:assert"
|
|
776
|
-
* import { multiplyAll } from "effect/Number"
|
|
777
|
-
*
|
|
778
|
-
* assert.deepStrictEqual(multiplyAll([2, 3, 4]), 24)
|
|
779
|
-
* ```
|
|
780
|
-
*
|
|
781
1206
|
* @category math
|
|
782
|
-
* @since 2.0.0
|
|
783
|
-
*/
|
|
784
|
-
export declare const multiplyAll: (collection: Iterable<number>) => number;
|
|
785
|
-
/**
|
|
786
|
-
* Returns the remainder left over when one operand is divided by a second operand.
|
|
787
|
-
*
|
|
788
|
-
* It always takes the sign of the dividend.
|
|
789
|
-
*
|
|
790
1207
|
* @example
|
|
1208
|
+
*
|
|
791
1209
|
* ```ts
|
|
792
|
-
* import * as assert from "node:assert"
|
|
1210
|
+
* import * as assert from "node:assert/strict"
|
|
793
1211
|
* import { remainder } from "effect/Number"
|
|
794
1212
|
*
|
|
795
|
-
* assert.
|
|
796
|
-
* assert.
|
|
797
|
-
* assert.
|
|
1213
|
+
* assert.equal(remainder(2, 2), 0)
|
|
1214
|
+
* assert.equal(remainder(3, 2), 1)
|
|
1215
|
+
* assert.equal(remainder(-4, 2), -0)
|
|
798
1216
|
* ```
|
|
799
|
-
*
|
|
800
|
-
* @category math
|
|
801
|
-
* @since 2.0.0
|
|
802
1217
|
*/
|
|
803
1218
|
export declare const remainder: {
|
|
804
1219
|
/**
|
|
805
|
-
* Returns the remainder left over when one operand is divided by a second
|
|
1220
|
+
* Returns the remainder left over when one operand is divided by a second
|
|
1221
|
+
* operand.
|
|
806
1222
|
*
|
|
807
1223
|
* It always takes the sign of the dividend.
|
|
808
1224
|
*
|
|
1225
|
+
* @memberof Number
|
|
1226
|
+
* @since 2.0.0
|
|
1227
|
+
* @category math
|
|
809
1228
|
* @example
|
|
1229
|
+
*
|
|
810
1230
|
* ```ts
|
|
811
|
-
* import * as assert from "node:assert"
|
|
1231
|
+
* import * as assert from "node:assert/strict"
|
|
812
1232
|
* import { remainder } from "effect/Number"
|
|
813
1233
|
*
|
|
814
|
-
* assert.
|
|
815
|
-
* assert.
|
|
816
|
-
* assert.
|
|
1234
|
+
* assert.equal(remainder(2, 2), 0)
|
|
1235
|
+
* assert.equal(remainder(3, 2), 1)
|
|
1236
|
+
* assert.equal(remainder(-4, 2), -0)
|
|
817
1237
|
* ```
|
|
818
|
-
*
|
|
819
|
-
* @category math
|
|
820
|
-
* @since 2.0.0
|
|
821
1238
|
*/
|
|
822
|
-
(divisor: number): (
|
|
1239
|
+
(divisor: number): (dividend: number) => number;
|
|
823
1240
|
/**
|
|
824
|
-
* Returns the remainder left over when one operand is divided by a second
|
|
1241
|
+
* Returns the remainder left over when one operand is divided by a second
|
|
1242
|
+
* operand.
|
|
825
1243
|
*
|
|
826
1244
|
* It always takes the sign of the dividend.
|
|
827
1245
|
*
|
|
1246
|
+
* @memberof Number
|
|
1247
|
+
* @since 2.0.0
|
|
1248
|
+
* @category math
|
|
828
1249
|
* @example
|
|
1250
|
+
*
|
|
829
1251
|
* ```ts
|
|
830
|
-
* import * as assert from "node:assert"
|
|
1252
|
+
* import * as assert from "node:assert/strict"
|
|
831
1253
|
* import { remainder } from "effect/Number"
|
|
832
1254
|
*
|
|
833
|
-
* assert.
|
|
834
|
-
* assert.
|
|
835
|
-
* assert.
|
|
1255
|
+
* assert.equal(remainder(2, 2), 0)
|
|
1256
|
+
* assert.equal(remainder(3, 2), 1)
|
|
1257
|
+
* assert.equal(remainder(-4, 2), -0)
|
|
836
1258
|
* ```
|
|
837
|
-
*
|
|
838
|
-
* @category math
|
|
839
|
-
* @since 2.0.0
|
|
840
1259
|
*/
|
|
841
|
-
(
|
|
1260
|
+
(dividend: number, divisor: number): number;
|
|
842
1261
|
};
|
|
843
1262
|
/**
|
|
844
|
-
* Returns the next power of 2
|
|
1263
|
+
* Returns the next power of 2 greater than or equal to the given number.
|
|
1264
|
+
*
|
|
1265
|
+
* - For `positive` inputs, returns the smallest power of 2 that is >= the input
|
|
1266
|
+
* - For `zero`, returns 2
|
|
1267
|
+
* - For `negative` inputs, returns NaN (as logarithms of negative numbers are
|
|
1268
|
+
* undefined)
|
|
1269
|
+
* - For `NaN` input, returns NaN
|
|
1270
|
+
* - For `Infinity`, returns Infinity
|
|
845
1271
|
*
|
|
1272
|
+
* @memberof Number
|
|
1273
|
+
* @since 2.0.0
|
|
1274
|
+
* @category math
|
|
846
1275
|
* @example
|
|
1276
|
+
*
|
|
847
1277
|
* ```ts
|
|
848
|
-
* import * as assert from "node:assert"
|
|
1278
|
+
* import * as assert from "node:assert/strict"
|
|
849
1279
|
* import { nextPow2 } from "effect/Number"
|
|
850
1280
|
*
|
|
851
|
-
* assert.
|
|
852
|
-
* assert.
|
|
1281
|
+
* assert.equal(nextPow2(5), 8)
|
|
1282
|
+
* assert.equal(nextPow2(17), 32)
|
|
1283
|
+
* assert.equal(nextPow2(0), 2)
|
|
1284
|
+
* assert.equal(Number.isNaN(nextPow2(-1)), true) // Negative inputs result in NaN
|
|
853
1285
|
* ```
|
|
854
|
-
*
|
|
855
|
-
* @category math
|
|
856
|
-
* @since 2.0.0
|
|
857
1286
|
*/
|
|
858
1287
|
export declare const nextPow2: (n: number) => number;
|
|
859
1288
|
/**
|
|
860
|
-
* Tries to parse a `number` from a `string` using the `Number()` function.
|
|
861
|
-
*
|
|
1289
|
+
* Tries to parse a `number` from a `string` using the `Number()` function. The
|
|
1290
|
+
* following special string values are supported: "NaN", "Infinity",
|
|
1291
|
+
* "-Infinity".
|
|
862
1292
|
*
|
|
863
|
-
* @
|
|
1293
|
+
* @memberof Number
|
|
864
1294
|
* @since 2.0.0
|
|
1295
|
+
* @category constructors
|
|
865
1296
|
*/
|
|
866
|
-
export declare const parse:
|
|
1297
|
+
export declare const parse: {
|
|
1298
|
+
/**
|
|
1299
|
+
* Tries to parse a `number` from a `string` using the `Number()` function. The
|
|
1300
|
+
* following special string values are supported: "NaN", "Infinity",
|
|
1301
|
+
* "-Infinity".
|
|
1302
|
+
*
|
|
1303
|
+
* @memberof Number
|
|
1304
|
+
* @since 2.0.0
|
|
1305
|
+
* @category constructors
|
|
1306
|
+
*/
|
|
1307
|
+
(s: string): Option<number>;
|
|
1308
|
+
};
|
|
867
1309
|
/**
|
|
868
1310
|
* Returns the number rounded with the given precision.
|
|
869
1311
|
*
|
|
1312
|
+
* @memberof Number
|
|
1313
|
+
* @since 3.8.0
|
|
1314
|
+
* @category math
|
|
870
1315
|
* @example
|
|
1316
|
+
*
|
|
871
1317
|
* ```ts
|
|
872
|
-
* import * as assert from "node:assert"
|
|
1318
|
+
* import * as assert from "node:assert/strict"
|
|
873
1319
|
* import { round } from "effect/Number"
|
|
874
1320
|
*
|
|
875
|
-
* assert.
|
|
876
|
-
* assert.
|
|
1321
|
+
* assert.equal(round(1.1234, 2), 1.12)
|
|
1322
|
+
* assert.equal(round(1.567, 2), 1.57)
|
|
877
1323
|
* ```
|
|
878
|
-
*
|
|
879
|
-
* @category math
|
|
880
|
-
* @since 3.8.0
|
|
881
1324
|
*/
|
|
882
1325
|
export declare const round: {
|
|
883
1326
|
/**
|
|
884
1327
|
* Returns the number rounded with the given precision.
|
|
885
1328
|
*
|
|
1329
|
+
* @memberof Number
|
|
1330
|
+
* @since 3.8.0
|
|
1331
|
+
* @category math
|
|
886
1332
|
* @example
|
|
1333
|
+
*
|
|
887
1334
|
* ```ts
|
|
888
|
-
* import * as assert from "node:assert"
|
|
1335
|
+
* import * as assert from "node:assert/strict"
|
|
889
1336
|
* import { round } from "effect/Number"
|
|
890
1337
|
*
|
|
891
|
-
* assert.
|
|
892
|
-
* assert.
|
|
1338
|
+
* assert.equal(round(1.1234, 2), 1.12)
|
|
1339
|
+
* assert.equal(round(1.567, 2), 1.57)
|
|
893
1340
|
* ```
|
|
894
|
-
*
|
|
895
|
-
* @category math
|
|
896
|
-
* @since 3.8.0
|
|
897
1341
|
*/
|
|
898
1342
|
(precision: number): (self: number) => number;
|
|
899
1343
|
/**
|
|
900
1344
|
* Returns the number rounded with the given precision.
|
|
901
1345
|
*
|
|
1346
|
+
* @memberof Number
|
|
1347
|
+
* @since 3.8.0
|
|
1348
|
+
* @category math
|
|
902
1349
|
* @example
|
|
1350
|
+
*
|
|
903
1351
|
* ```ts
|
|
904
|
-
* import * as assert from "node:assert"
|
|
1352
|
+
* import * as assert from "node:assert/strict"
|
|
905
1353
|
* import { round } from "effect/Number"
|
|
906
1354
|
*
|
|
907
|
-
* assert.
|
|
908
|
-
* assert.
|
|
1355
|
+
* assert.equal(round(1.1234, 2), 1.12)
|
|
1356
|
+
* assert.equal(round(1.567, 2), 1.57)
|
|
909
1357
|
* ```
|
|
910
|
-
*
|
|
911
|
-
* @category math
|
|
912
|
-
* @since 3.8.0
|
|
913
1358
|
*/
|
|
914
1359
|
(self: number, precision: number): number;
|
|
915
1360
|
};
|