@nicolastoulemont/std 0.4.0 → 0.5.0

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.
Files changed (122) hide show
  1. package/dist/adt/index.d.mts +1 -1
  2. package/dist/adt/index.mjs +1 -3
  3. package/dist/adt-DZmVJG4P.mjs +2 -0
  4. package/dist/adt-DZmVJG4P.mjs.map +1 -0
  5. package/dist/{apply-fn.types-0g_9eXRy.d.mts → apply-fn.types-CMgY6WQe.d.mts} +1 -1
  6. package/dist/{apply-fn.types-0g_9eXRy.d.mts.map → apply-fn.types-CMgY6WQe.d.mts.map} +1 -1
  7. package/dist/brand/index.d.mts +1 -1
  8. package/dist/brand/index.mjs +1 -3
  9. package/dist/brand-BUqMmkzC.mjs +2 -0
  10. package/dist/{brand-BqcqFXj5.mjs.map → brand-BUqMmkzC.mjs.map} +1 -1
  11. package/dist/data/index.d.mts +1 -1
  12. package/dist/data/index.mjs +1 -3
  13. package/dist/data-DzqKBCQg.mjs +2 -0
  14. package/dist/data-DzqKBCQg.mjs.map +1 -0
  15. package/dist/{discriminator.types-D-UbMmAD.d.mts → discriminator.types-DkThfvNE.d.mts} +1 -1
  16. package/dist/discriminator.types-DkThfvNE.d.mts.map +1 -0
  17. package/dist/either/index.d.mts +2 -2
  18. package/dist/either/index.mjs +1 -3
  19. package/dist/either-BDY9T5oz.mjs +2 -0
  20. package/dist/either-BDY9T5oz.mjs.map +1 -0
  21. package/dist/equality-D2EJvZm4.mjs +2 -0
  22. package/dist/{equality-C2l3BIi8.mjs.map → equality-D2EJvZm4.mjs.map} +1 -1
  23. package/dist/err/index.d.mts +1 -1
  24. package/dist/err/index.mjs +1 -3
  25. package/dist/err-CYs4b1RV.mjs +2 -0
  26. package/dist/{err-BM-svBaK.mjs.map → err-CYs4b1RV.mjs.map} +1 -1
  27. package/dist/flow/index.d.mts +1 -1
  28. package/dist/flow/index.mjs +1 -3
  29. package/dist/flow-CxKQ5yac.mjs +2 -0
  30. package/dist/{flow-D4cE0EAg.mjs.map → flow-CxKQ5yac.mjs.map} +1 -1
  31. package/dist/fx/index.d.mts +3 -3
  32. package/dist/fx/index.mjs +1 -4
  33. package/dist/fx-C4UuWCqP.mjs +2 -0
  34. package/dist/fx-C4UuWCqP.mjs.map +1 -0
  35. package/dist/fx.types-CXTwEa1G.mjs +2 -0
  36. package/dist/{fx.types-DpIQILok.mjs.map → fx.types-CXTwEa1G.mjs.map} +1 -1
  37. package/dist/{fx.types-aTmhyidu.d.mts → fx.types-DO-8yG4c.d.mts} +1 -1
  38. package/dist/{fx.types-aTmhyidu.d.mts.map → fx.types-DO-8yG4c.d.mts.map} +1 -1
  39. package/dist/{index-USQPafrR.d.mts → index-78LWwTds.d.mts} +1 -1
  40. package/dist/{index-USQPafrR.d.mts.map → index-78LWwTds.d.mts.map} +1 -1
  41. package/dist/{index-BO6bxBeo.d.mts → index-BQ5wVDSP.d.mts} +8 -24
  42. package/dist/index-BQ5wVDSP.d.mts.map +1 -0
  43. package/dist/{index-BOrJQBPO.d.mts → index-BahMvQpA.d.mts} +2 -2
  44. package/dist/{index-BOrJQBPO.d.mts.map → index-BahMvQpA.d.mts.map} +1 -1
  45. package/dist/{index-ClxPiGP9.d.mts → index-Bs5TTFlK.d.mts} +40 -44
  46. package/dist/index-Bs5TTFlK.d.mts.map +1 -0
  47. package/dist/{index-D5tzehjf.d.mts → index-BuLJRX1e.d.mts} +11 -11
  48. package/dist/{index-D5tzehjf.d.mts.map → index-BuLJRX1e.d.mts.map} +1 -1
  49. package/dist/{index-CQxzD1YM.d.mts → index-CDio8mJY.d.mts} +4 -4
  50. package/dist/{index-CQxzD1YM.d.mts.map → index-CDio8mJY.d.mts.map} +1 -1
  51. package/dist/{index-FySViSfh.d.mts → index-DLlx9jiG.d.mts} +5 -105
  52. package/dist/index-DLlx9jiG.d.mts.map +1 -0
  53. package/dist/{index-CLspOlBH.d.mts → index-DQoTXLSm.d.mts} +192 -83
  54. package/dist/index-DQoTXLSm.d.mts.map +1 -0
  55. package/dist/{index-Cydt5ocm.d.mts → index-DjjJIDaA.d.mts} +2 -2
  56. package/dist/{index-Cydt5ocm.d.mts.map → index-DjjJIDaA.d.mts.map} +1 -1
  57. package/dist/{index-EmWRCTY3.d.mts → index-DtAPrec7.d.mts} +2 -2
  58. package/dist/{index-EmWRCTY3.d.mts.map → index-DtAPrec7.d.mts.map} +1 -1
  59. package/dist/{index-CLlcoy8B.d.mts → index-IdejL485.d.mts} +2 -2
  60. package/dist/{index-CLlcoy8B.d.mts.map → index-IdejL485.d.mts.map} +1 -1
  61. package/dist/index.d.mts +16 -40
  62. package/dist/index.mjs +1 -15
  63. package/dist/option/index.d.mts +3 -3
  64. package/dist/option/index.mjs +1 -4
  65. package/dist/option-Qiv7Ls7L.mjs +2 -0
  66. package/dist/option-Qiv7Ls7L.mjs.map +1 -0
  67. package/dist/option.types-By5UOfC2.mjs +2 -0
  68. package/dist/option.types-By5UOfC2.mjs.map +1 -0
  69. package/dist/{option.types-CVvowfmd.d.mts → option.types-Cluybn30.d.mts} +22 -20
  70. package/dist/option.types-Cluybn30.d.mts.map +1 -0
  71. package/dist/pipe/index.d.mts +1 -1
  72. package/dist/pipe/index.mjs +1 -3
  73. package/dist/pipe-BROILDeC.mjs +2 -0
  74. package/dist/{pipe-BF4G4SLo.mjs.map → pipe-BROILDeC.mjs.map} +1 -1
  75. package/dist/{pipeable-Dr0d_q4F.d.mts → pipeable-KHu4D8ol.d.mts} +1 -1
  76. package/dist/{pipeable-Dr0d_q4F.d.mts.map → pipeable-KHu4D8ol.d.mts.map} +1 -1
  77. package/dist/pipeable-rQvolRqh.mjs +2 -0
  78. package/dist/{pipeable-DYNrUps7.mjs.map → pipeable-rQvolRqh.mjs.map} +1 -1
  79. package/dist/predicate/index.d.mts +1 -1
  80. package/dist/predicate/index.mjs +1 -3
  81. package/dist/predicate-DvXnfmeJ.mjs +2 -0
  82. package/dist/{predicate-Dt9Qsbav.mjs.map → predicate-DvXnfmeJ.mjs.map} +1 -1
  83. package/dist/result/index.d.mts +2 -2
  84. package/dist/result/index.mjs +1 -3
  85. package/dist/result-B68pxC7l.mjs +2 -0
  86. package/dist/result-B68pxC7l.mjs.map +1 -0
  87. package/dist/result-uRORQlAQ.mjs +1 -0
  88. package/dist/{result.types-_W95221K.d.mts → result.types-fIbuBwVQ.d.mts} +129 -20
  89. package/dist/result.types-fIbuBwVQ.d.mts.map +1 -0
  90. package/package.json +1 -1
  91. package/dist/adt-DH37Pprw.mjs +0 -318
  92. package/dist/adt-DH37Pprw.mjs.map +0 -1
  93. package/dist/brand-BqcqFXj5.mjs +0 -165
  94. package/dist/chunk-DRYujVrt.mjs +0 -18
  95. package/dist/data-Cg8ySt6-.mjs +0 -244
  96. package/dist/data-Cg8ySt6-.mjs.map +0 -1
  97. package/dist/discriminator.types-D-UbMmAD.d.mts.map +0 -1
  98. package/dist/either-jkBX8xS1.mjs +0 -735
  99. package/dist/either-jkBX8xS1.mjs.map +0 -1
  100. package/dist/equality-C2l3BIi8.mjs +0 -201
  101. package/dist/err-BM-svBaK.mjs +0 -176
  102. package/dist/flow-D4cE0EAg.mjs +0 -28
  103. package/dist/fx-B-0MxGTM.mjs +0 -1306
  104. package/dist/fx-B-0MxGTM.mjs.map +0 -1
  105. package/dist/fx.types-DpIQILok.mjs +0 -13
  106. package/dist/index-BO6bxBeo.d.mts.map +0 -1
  107. package/dist/index-CLspOlBH.d.mts.map +0 -1
  108. package/dist/index-ClxPiGP9.d.mts.map +0 -1
  109. package/dist/index-FySViSfh.d.mts.map +0 -1
  110. package/dist/index.d.mts.map +0 -1
  111. package/dist/option-C2QpGffy.mjs +0 -530
  112. package/dist/option-C2QpGffy.mjs.map +0 -1
  113. package/dist/option.types-BiAiZ8Ks.mjs +0 -33
  114. package/dist/option.types-BiAiZ8Ks.mjs.map +0 -1
  115. package/dist/option.types-CVvowfmd.d.mts.map +0 -1
  116. package/dist/pipe-BF4G4SLo.mjs +0 -10
  117. package/dist/pipeable-DYNrUps7.mjs +0 -92
  118. package/dist/predicate-Dt9Qsbav.mjs +0 -293
  119. package/dist/result-BmqdTN5o.mjs +0 -1
  120. package/dist/result-DhYA-J-M.mjs +0 -542
  121. package/dist/result-DhYA-J-M.mjs.map +0 -1
  122. package/dist/result.types-_W95221K.d.mts.map +0 -1
@@ -1,92 +0,0 @@
1
- import { t as flow } from "./flow-D4cE0EAg.mjs";
2
-
3
- //#region src/shared/dual.ts
4
- /**
5
- * Dual function utility for creating functions that support both
6
- * data-first and data-last (curried) calling styles.
7
- *
8
- * This pattern is inspired by Effect's dual function implementation.
9
- * It enables better ergonomics by allowing direct function calls
10
- * without requiring pipe() for simple operations.
11
- *
12
- * @example
13
- * ```ts
14
- * // Define a dual function
15
- * const map = dual<
16
- * <T, U>(self: Option<T>, fn: (value: T) => U) => Option<U>,
17
- * <T, U>(fn: (value: T) => U) => (self: Option<T>) => Option<U>
18
- * >(2, (self, fn) => self.some ? some(fn(self.value)) : none())
19
- *
20
- * // Use data-first (direct call)
21
- * map(some(5), x => x * 2) // Option<10>
22
- *
23
- * // Use data-last (curried for pipe)
24
- * pipe(some(5), map(x => x * 2)) // Option<10>
25
- * ```
26
- */
27
- /**
28
- * Creates a function that can be called with all arguments (data-first)
29
- * or partially applied (data-last) for use in pipe chains.
30
- *
31
- * @param arity - The number of arguments in the data-first version (including self)
32
- * @param body - The implementation function that receives all arguments
33
- * @returns A function that supports both calling styles
34
- *
35
- * @remarks
36
- * The arity parameter is used to determine whether the function is being
37
- * called in data-first mode (all arguments provided) or data-last mode
38
- * (partial application for piping).
39
- *
40
- * TypeScript 5.4+ NoInfer is used where appropriate in consuming code
41
- * to prevent inference from fallback positions.
42
- */
43
- const dual = function(arityOrIsDataFirst, body) {
44
- if (typeof arityOrIsDataFirst === "function") return function() {
45
- if (arityOrIsDataFirst(arguments)) return body.apply(this, arguments);
46
- return ((self) => body(self, ...arguments));
47
- };
48
- switch (arityOrIsDataFirst) {
49
- case 0: return body;
50
- case 1: return function(a) {
51
- if (arguments.length > 0) return body.call(this, a);
52
- return body.bind(this);
53
- };
54
- case 2: return function(a, b) {
55
- if (arguments.length >= 2) return body.call(this, a, b);
56
- return (self) => body(self, a);
57
- };
58
- case 3: return function(a, b, c) {
59
- if (arguments.length >= 3) return body.call(this, a, b, c);
60
- return (self) => body(self, a, b);
61
- };
62
- case 4: return function(a, b, c, d) {
63
- if (arguments.length >= 4) return body.call(this, a, b, c, d);
64
- return (self) => body(self, a, b, c);
65
- };
66
- case 5: return function(a, b, c, d, e) {
67
- if (arguments.length >= 5) return body.call(this, a, b, c, d, e);
68
- return (self) => body(self, a, b, c, d);
69
- };
70
- default: return function() {
71
- if (arguments.length >= arityOrIsDataFirst) return body.apply(this, arguments);
72
- const args = arguments;
73
- return (self) => body(self, ...args);
74
- };
75
- }
76
- };
77
-
78
- //#endregion
79
- //#region src/shared/pipeable.ts
80
- /**
81
- * Create a pipe method implementation.
82
- * Returns a function that pipes the value through provided functions.
83
- * This is designed to be used as an object method, so it uses `this` binding.
84
- */
85
- function pipeMethod(...fns) {
86
- if (fns.length === 0) return this;
87
- return flow(...fns)(this);
88
- }
89
-
90
- //#endregion
91
- export { dual as n, pipeMethod as t };
92
- //# sourceMappingURL=pipeable-DYNrUps7.mjs.map
@@ -1,293 +0,0 @@
1
- //#region src/predicate/predicate.ts
2
- /**
3
- * Negate a predicate.
4
- * Returns true when the original predicate returns false, and vice versa.
5
- *
6
- * @template T - The type being tested
7
- * @param predicate - The predicate to negate
8
- * @returns A new predicate that returns the opposite boolean
9
- *
10
- * @example
11
- * ```ts
12
- * const isEven = (n: number) => n % 2 === 0
13
- * const isOdd = Predicate.not(isEven)
14
- *
15
- * isOdd(3) // true
16
- * isOdd(4) // false
17
- *
18
- * // Works in filter
19
- * [1, 2, 3, 4].filter(Predicate.not(isEven)) // [1, 3]
20
- * ```
21
- */
22
- const not = (predicate) => {
23
- return (value) => !predicate(value);
24
- };
25
- /**
26
- * Combine predicates with logical AND.
27
- * Returns true only when ALL predicates return true.
28
- * Short-circuits on first false (lazy evaluation).
29
- *
30
- * @template T - The type being tested
31
- * @param predicates - The predicates to combine
32
- * @returns A new predicate that returns true if all predicates pass
33
- *
34
- * @example
35
- * ```ts
36
- * const isPositive = (n: number) => n > 0
37
- * const isEven = (n: number) => n % 2 === 0
38
- * const isLessThan100 = (n: number) => n < 100
39
- *
40
- * const isValidNumber = Predicate.and(isPositive, isEven, isLessThan100)
41
- *
42
- * isValidNumber(42) // true
43
- * isValidNumber(-2) // false (not positive)
44
- * isValidNumber(101) // false (not less than 100)
45
- * ```
46
- */
47
- const and = (...predicates) => {
48
- return (value) => {
49
- for (const predicate of predicates) if (!predicate(value)) return false;
50
- return true;
51
- };
52
- };
53
- /**
54
- * Combine predicates with logical OR.
55
- * Returns true when ANY predicate returns true.
56
- * Short-circuits on first true (lazy evaluation).
57
- *
58
- * @template T - The type being tested
59
- * @param predicates - The predicates to combine
60
- * @returns A new predicate that returns true if any predicate passes
61
- *
62
- * @example
63
- * ```ts
64
- * const isZero = (n: number) => n === 0
65
- * const isNegative = (n: number) => n < 0
66
- *
67
- * const isNotPositive = Predicate.or(isZero, isNegative)
68
- *
69
- * isNotPositive(0) // true
70
- * isNotPositive(-5) // true
71
- * isNotPositive(5) // false
72
- * ```
73
- */
74
- const or = (...predicates) => {
75
- return (value) => {
76
- for (const predicate of predicates) if (predicate(value)) return true;
77
- return false;
78
- };
79
- };
80
- /**
81
- * Create a predicate that tests if ALL elements in an array match.
82
- * Returns true for empty arrays (vacuous truth).
83
- *
84
- * @template T - The element type
85
- * @param predicate - The predicate to test each element
86
- * @returns A predicate that takes an array and returns true if all match
87
- *
88
- * @example
89
- * ```ts
90
- * const isPositive = (n: number) => n > 0
91
- * const allPositive = Predicate.all(isPositive)
92
- *
93
- * allPositive([1, 2, 3]) // true
94
- * allPositive([1, -2, 3]) // false
95
- * allPositive([]) // true (vacuous truth)
96
- *
97
- * // Useful for validation
98
- * const areAllAdults = Predicate.all((u: User) => u.age >= 18)
99
- * ```
100
- */
101
- const all = (predicate) => {
102
- return (arr) => arr.every(predicate);
103
- };
104
- /**
105
- * Create a predicate that tests if ANY element in an array matches.
106
- * Returns false for empty arrays.
107
- *
108
- * @template T - The element type
109
- * @param predicate - The predicate to test each element
110
- * @returns A predicate that takes an array and returns true if any match
111
- *
112
- * @example
113
- * ```ts
114
- * const isNegative = (n: number) => n < 0
115
- * const hasNegative = Predicate.some(isNegative)
116
- *
117
- * hasNegative([1, -2, 3]) // true
118
- * hasNegative([1, 2, 3]) // false
119
- * hasNegative([]) // false
120
- * ```
121
- */
122
- const some = (predicate) => {
123
- return (arr) => arr.some(predicate);
124
- };
125
- /**
126
- * Create a predicate that tests if NO elements in an array match.
127
- * Returns true for empty arrays (vacuous truth).
128
- * Equivalent to `not(some(predicate))`.
129
- *
130
- * @template T - The element type
131
- * @param predicate - The predicate that should NOT match any element
132
- * @returns A predicate that takes an array and returns true if none match
133
- *
134
- * @example
135
- * ```ts
136
- * const isNegative = (n: number) => n < 0
137
- * const noNegatives = Predicate.none(isNegative)
138
- *
139
- * noNegatives([1, 2, 3]) // true
140
- * noNegatives([1, -2, 3]) // false
141
- * noNegatives([]) // true (vacuous truth)
142
- * ```
143
- */
144
- const none = (predicate) => {
145
- return (arr) => !arr.some(predicate);
146
- };
147
- /**
148
- * Combine refinements with logical AND, preserving type narrowing.
149
- * Use this instead of `and` when you need to preserve type guard behavior.
150
- *
151
- * @template T - The base type
152
- * @template U - The narrowed type (must extend T)
153
- * @param refinements - The refinements to combine
154
- * @returns A refinement that narrows to U if all refinements pass
155
- *
156
- * @example
157
- * ```ts
158
- * type User = { name: string; age: number; verified?: boolean }
159
- * type Adult = User & { age: number } // age >= 18
160
- * type VerifiedAdult = Adult & { verified: true }
161
- *
162
- * const isAdult = (u: User): u is Adult => u.age >= 18
163
- * const isVerified = (u: User): u is User & { verified: true } => u.verified === true
164
- *
165
- * // Combined refinement preserves type narrowing
166
- * const isVerifiedAdult = Predicate.andRefinement<User, VerifiedAdult>(isAdult, isVerified)
167
- *
168
- * if (isVerifiedAdult(user)) {
169
- * user.verified // TypeScript knows this is true
170
- * }
171
- * ```
172
- */
173
- const andRefinement = (...refinements) => {
174
- return (value) => {
175
- for (const refinement of refinements) if (!refinement(value)) return false;
176
- return true;
177
- };
178
- };
179
- /**
180
- * Combine refinements with logical OR, preserving type narrowing.
181
- * Use this instead of `or` when you need to preserve type guard behavior.
182
- *
183
- * @template T - The base type
184
- * @template U - The narrowed type (must extend T)
185
- * @param refinements - The refinements to combine
186
- * @returns A refinement that narrows to U if any refinement passes
187
- *
188
- * @example
189
- * ```ts
190
- * const isString = (v: unknown): v is string => typeof v === "string"
191
- * const isNumber = (v: unknown): v is number => typeof v === "number"
192
- *
193
- * const isStringOrNumber = Predicate.orRefinement<unknown, string | number>(isString, isNumber)
194
- *
195
- * if (isStringOrNumber(value)) {
196
- * // value is string | number
197
- * }
198
- * ```
199
- */
200
- const orRefinement = (...refinements) => {
201
- return (value) => {
202
- for (const refinement of refinements) if (refinement(value)) return true;
203
- return false;
204
- };
205
- };
206
- /**
207
- * Create a predicate from a constant boolean value.
208
- * Useful for testing or as a placeholder.
209
- *
210
- * @template T - The type (can be anything)
211
- * @param value - The constant boolean to return
212
- * @returns A predicate that always returns the given value
213
- *
214
- * @example
215
- * ```ts
216
- * const alwaysTrue = Predicate.constant(true)
217
- * const alwaysFalse = Predicate.constant(false)
218
- *
219
- * alwaysTrue("anything") // true
220
- * alwaysFalse(42) // false
221
- * ```
222
- */
223
- const constant = (value) => {
224
- return () => value;
225
- };
226
- /**
227
- * Create a predicate that checks strict equality.
228
- *
229
- * @template T - The type being compared
230
- * @param expected - The value to compare against
231
- * @returns A predicate that returns true if value === expected
232
- *
233
- * @example
234
- * ```ts
235
- * const isZero = Predicate.equals(0)
236
- * const isHello = Predicate.equals("hello")
237
- *
238
- * isZero(0) // true
239
- * isZero(1) // false
240
- *
241
- * // Works with references too
242
- * const obj = { a: 1 }
243
- * const isObj = Predicate.equals(obj)
244
- * isObj(obj) // true
245
- * isObj({ a: 1 }) // false (different reference)
246
- * ```
247
- */
248
- const equals = (expected) => {
249
- return (value) => value === expected;
250
- };
251
- /**
252
- * Predicate namespace containing composable boolean functions.
253
- *
254
- * Predicates are functions that test values and return booleans.
255
- * This namespace provides combinators to build complex predicates
256
- * from simple ones, with support for type guards (refinements).
257
- *
258
- * @example
259
- * ```ts
260
- * import { Predicate, pipe } from "@repo/std"
261
- *
262
- * // Basic predicates
263
- * const isPositive = (n: number) => n > 0
264
- * const isEven = (n: number) => n % 2 === 0
265
- *
266
- * // Combine with and/or
267
- * const isPositiveEven = Predicate.and(isPositive, isEven)
268
- * const isZeroOrNegative = Predicate.or(Predicate.equals(0), Predicate.not(isPositive))
269
- *
270
- * // Array predicates
271
- * const allPositive = Predicate.all(isPositive)
272
- * const hasNegative = Predicate.some(Predicate.not(isPositive))
273
- *
274
- * // Use with filter
275
- * [1, 2, 3, 4, 5].filter(isPositiveEven) // [2, 4]
276
- * ```
277
- */
278
- const Predicate = {
279
- not,
280
- and,
281
- or,
282
- all,
283
- some,
284
- none,
285
- andRefinement,
286
- orRefinement,
287
- constant,
288
- equals
289
- };
290
-
291
- //#endregion
292
- export { constant as a, not as c, some as d, andRefinement as i, or as l, all as n, equals as o, and as r, none as s, Predicate as t, orRefinement as u };
293
- //# sourceMappingURL=predicate-Dt9Qsbav.mjs.map
@@ -1 +0,0 @@
1
- export { };