functype 0.8.63 → 0.8.65

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Jordan Burke
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jordan Burke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,277 +1,277 @@
1
- # Functype
2
-
3
- ![NPM Version](https://img.shields.io/npm/v/functype?link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Ffunctype)
4
- [![Node.js Build](https://github.com/jordanburke/functype/actions/workflows/pnpm-build.yml/badge.svg)](https://github.com/jordanburke/functype/actions/workflows/pnpm-build.yml)
5
-
6
- ## A Functional Programming Library for TypeScript
7
-
8
- Functype is a lightweight functional programming library for TypeScript, drawing inspiration from functional programming paradigms, the Scala Standard Library, and ZIO. It provides a comprehensive set of utilities and abstractions designed to facilitate functional programming within TypeScript applications.
9
-
10
- [API Documentation](https://jordanburke.github.io/functype/)
11
-
12
- ## Core Principles
13
-
14
- - **Immutability**: All data structures are immutable, promoting predictable and side-effect-free code
15
- - **Type Safety**: Leverages TypeScript's type system to ensure compile-time safety
16
- - **Composability**: Provides abstractions for building complex programs from simple components
17
- - **Functional Paradigms**: Embraces concepts like monads, functors, and type classes
18
-
19
- ## Key Features
20
-
21
- - **Option Type**: Handle nullable values with `Some` and `None` types
22
- - **Either Type**: Express computation results with potential failures using `Left` and `Right`
23
- - **List, Set, Map**: Immutable collection types with functional operators
24
- - **Try Type**: Safely execute operations that might throw exceptions
25
- - **Task**: Handle synchronous and asynchronous operations with error handling
26
- - **Tuple**: Type-safe fixed-length arrays
27
- - **Typeable**: Runtime type identification with compile-time safety
28
-
29
- ## Roadmap / TODO
30
-
31
- ### Missing Functionality
32
-
33
- - [ ] Add lazy evaluation structures (LazyList/Stream)
34
- - [ ] Implement Validation type for applicative validation
35
- - [ ] Add Reader/State/IO monads for more functional patterns
36
- - [ ] Implement lens/optics for immutable updates
37
- - [ ] Expand concurrent execution utilities beyond FPromise.all
38
-
39
- ### Performance Optimizations
40
-
41
- - [ ] Add memoization utilities
42
- - [ ] Improve recursive operations for large collections
43
- - [ ] Implement immutable data structures with structural sharing
44
- - [ ] Add performance benchmarks
45
- - [x] Optimize TreeShaking with sideEffects flag in package.json
46
- - [x] Support selective module imports for smaller bundles
47
- - [x] Add bundle size monitoring to CI/CD
48
-
49
- ### API Consistency
50
-
51
- - [ ] Ensure all modules follow the Scala-inspired pattern:
52
- - Constructor functions that return objects with methods
53
- - Object methods for common operations
54
- - Companion functions for additional utilities
55
- - [x] Align Task API with other monadic structures
56
- - [ ] Standardize import patterns (@ imports vs relative paths)
57
- - [x] Implement consistent error handling strategy for async operations
58
-
59
- ### Testing and Documentation
60
-
61
- - [ ] Add observable test coverage metrics
62
- - [x] Implement property-based testing
63
- - [ ] Expand error handling tests
64
- - [ ] Add interoperability tests with other libraries
65
-
66
- ### TypeScript Improvements
67
-
68
- - [x] Enable stricter TypeScript settings (noImplicitAny: true)
69
- - [x] Add noUncheckedIndexedAccess for safer array indexing
70
- - [ ] Improve support for higher-kinded types:
71
- - Current type parameters work well for first-order types
72
- - Expand to support type constructors as parameters (F<A> => F<B>)
73
- - [ ] Add branded/nominal types for stronger type safety
74
- - [ ] Implement more type-level utilities (conditional types, template literals)
75
- - [ ] Leverage newer TypeScript features (const type parameters, tuple manipulation)
76
-
77
- ## Installation
78
-
79
- ```bash
80
- # NPM
81
- npm install functype
82
-
83
- # Yarn
84
- yarn add functype
85
-
86
- # PNPM
87
- pnpm add functype
88
-
89
- # Bun
90
- bun add functype
91
- ```
92
-
93
- ### Bundle Size Optimization
94
-
95
- Functype is optimized for tree-shaking and offers multiple import strategies to minimize bundle size:
96
-
97
- ```typescript
98
- // Selective module imports (recommended for production)
99
- import { Option } from "functype/option"
100
- import { Either } from "functype/either"
101
-
102
- // Direct constructor imports (smallest bundle)
103
- import { some, none } from "functype/option"
104
- ```
105
-
106
- For detailed optimization strategies, see the [Bundle Optimization Guide](docs/BUNDLE_OPTIMIZATION.md).
107
-
108
- ## Usage Examples
109
-
110
- ### Option
111
-
112
- ```typescript
113
- import { Option, Some, None } from "functype"
114
-
115
- // Create options
116
- const value = Option("hello") // Some("hello")
117
- const empty = Option(null) // None
118
- const explicit = Some(42) // Some(42)
119
-
120
- // Transform values
121
- const length = value.map((s) => s.length) // Some(5)
122
- const nothing = empty.map((s) => s.length) // None
123
-
124
- // Handle default values
125
- const result = value.getOrElse("world") // "hello"
126
- const fallback = empty.getOrElse("world") // "world"
127
-
128
- // Conditionally filter
129
- const filtered = value.filter((s) => s.length > 10) // None
130
- ```
131
-
132
- ### Either
133
-
134
- ```typescript
135
- import { Either, Right, Left } from "functype"
136
-
137
- // Success case
138
- const success = Right<string, number>(42)
139
- // Error case
140
- const failure = Left<string, number>("error")
141
-
142
- // Transform values (map only applies to Right)
143
- const doubled = success.map((x) => x * 2) // Right(84)
144
- const stillError = failure.map((x) => x * 2) // Left("error")
145
-
146
- // Handle errors
147
- const value = success.getOrElse(0) // 42
148
- const fallback = failure.getOrElse(0) // 0
149
-
150
- // Pattern matching with fold
151
- const result = success.fold(
152
- (err) => `Error: ${err}`,
153
- (val) => `Success: ${val}`,
154
- ) // "Success: 42"
155
- ```
156
-
157
- ### List
158
-
159
- ```typescript
160
- import { List } from "functype"
161
-
162
- const numbers = List([1, 2, 3, 4])
163
-
164
- // Transform
165
- const doubled = numbers.map((x) => x * 2) // List([2, 4, 6, 8])
166
-
167
- // Filter
168
- const evens = numbers.filter((x) => x % 2 === 0) // List([2, 4])
169
-
170
- // Reduce
171
- const sum = numbers.foldLeft(0)((acc, x) => acc + x) // 10
172
-
173
- // Add/remove elements (immutably)
174
- const withFive = numbers.add(5) // List([1, 2, 3, 4, 5])
175
- const without3 = numbers.remove(3) // List([1, 2, 4])
176
- ```
177
-
178
- ### Try
179
-
180
- ```typescript
181
- import { Try } from "functype"
182
-
183
- // Safely execute code that might throw
184
- const result = Try(() => {
185
- // Potentially throwing operation
186
- return JSON.parse('{"name": "John"}')
187
- })
188
-
189
- // Handle success/failure
190
- if (result.isSuccess()) {
191
- console.log("Result:", result.get())
192
- } else {
193
- console.error("Error:", result.error)
194
- }
195
-
196
- // Transform with map (only applies on Success)
197
- const name = result.map((obj) => obj.name)
198
-
199
- // Convert to Either
200
- const either = result.toEither()
201
- ```
202
-
203
- ### Task
204
-
205
- ```typescript
206
- import { Task } from "functype"
207
-
208
- // Synchronous operations with error handling
209
- const syncResult = Task().Sync(
210
- () => "success",
211
- (error) => new Error(`Failed: ${error}`),
212
- )
213
-
214
- // Asynchronous operations
215
- const asyncTask = async () => {
216
- const result = await Task().Async(
217
- async () => await fetchData(),
218
- async (error) => new Error(`Fetch failed: ${error}`),
219
- )
220
- return result
221
- }
222
-
223
- // Converting promise-based functions to Task
224
- const fetchUserAPI = (userId: string): Promise<User> => fetch(`/api/users/${userId}`).then((r) => r.json())
225
-
226
- // Use the adapter pattern for seamless integration
227
- const fetchUser = Task({ name: "UserFetch" }).fromPromise(fetchUserAPI)
228
-
229
- // Later use it with standard promise patterns
230
- fetchUser("user123")
231
- .then((user) => console.log(user))
232
- .catch((error) => console.error(error))
233
-
234
- // Or convert Task results back to promises
235
- const taskResult = Task().Sync(() => "hello world")
236
- const promise = Task().toPromise(taskResult) // Promise<string>
237
- ```
238
-
239
- ## Type Safety
240
-
241
- Functype leverages TypeScript's advanced type system to provide compile-time safety for functional patterns, ensuring that your code is both robust and maintainable.
242
-
243
- ```typescript
244
- // Type inference works seamlessly
245
- const option = Option(42)
246
- // Inferred as number
247
- const mappedValue = option.map((x) => x.toString())
248
- // Inferred as string
249
- ```
250
-
251
- ## Contributing
252
-
253
- Contributions are welcome! Please feel free to submit a Pull Request.
254
-
255
- ## License
256
-
257
- MIT License
258
-
259
- Copyright (c) 2025 Jordan Burke
260
-
261
- Permission is hereby granted, free of charge, to any person obtaining a copy
262
- of this software and associated documentation files (the "Software"), to deal
263
- in the Software without restriction, including without limitation the rights
264
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
265
- copies of the Software, and to permit persons to whom the Software is
266
- furnished to do so, subject to the following conditions:
267
-
268
- The above copyright notice and this permission notice shall be included in all
269
- copies or substantial portions of the Software.
270
-
271
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
272
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
273
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
274
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
275
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
276
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
277
- SOFTWARE.
1
+ # Functype
2
+
3
+ ![NPM Version](https://img.shields.io/npm/v/functype?link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2Ffunctype)
4
+ [![Node.js Build](https://github.com/jordanburke/functype/actions/workflows/pnpm-build.yml/badge.svg)](https://github.com/jordanburke/functype/actions/workflows/pnpm-build.yml)
5
+
6
+ ## A Functional Programming Library for TypeScript
7
+
8
+ Functype is a lightweight functional programming library for TypeScript, drawing inspiration from functional programming paradigms, the Scala Standard Library, and ZIO. It provides a comprehensive set of utilities and abstractions designed to facilitate functional programming within TypeScript applications.
9
+
10
+ [API Documentation](https://jordanburke.github.io/functype/)
11
+
12
+ ## Core Principles
13
+
14
+ - **Immutability**: All data structures are immutable, promoting predictable and side-effect-free code
15
+ - **Type Safety**: Leverages TypeScript's type system to ensure compile-time safety
16
+ - **Composability**: Provides abstractions for building complex programs from simple components
17
+ - **Functional Paradigms**: Embraces concepts like monads, functors, and type classes
18
+
19
+ ## Key Features
20
+
21
+ - **Option Type**: Handle nullable values with `Some` and `None` types
22
+ - **Either Type**: Express computation results with potential failures using `Left` and `Right`
23
+ - **List, Set, Map**: Immutable collection types with functional operators
24
+ - **Try Type**: Safely execute operations that might throw exceptions
25
+ - **Task**: Handle synchronous and asynchronous operations with error handling
26
+ - **Tuple**: Type-safe fixed-length arrays
27
+ - **Typeable**: Runtime type identification with compile-time safety
28
+
29
+ ## Roadmap / TODO
30
+
31
+ ### Missing Functionality
32
+
33
+ - [ ] Add lazy evaluation structures (LazyList/Stream)
34
+ - [ ] Implement Validation type for applicative validation
35
+ - [ ] Add Reader/State/IO monads for more functional patterns
36
+ - [ ] Implement lens/optics for immutable updates
37
+ - [ ] Expand concurrent execution utilities beyond FPromise.all
38
+
39
+ ### Performance Optimizations
40
+
41
+ - [ ] Add memoization utilities
42
+ - [ ] Improve recursive operations for large collections
43
+ - [ ] Implement immutable data structures with structural sharing
44
+ - [ ] Add performance benchmarks
45
+ - [x] Optimize TreeShaking with sideEffects flag in package.json
46
+ - [x] Support selective module imports for smaller bundles
47
+ - [x] Add bundle size monitoring to CI/CD
48
+
49
+ ### API Consistency
50
+
51
+ - [ ] Ensure all modules follow the Scala-inspired pattern:
52
+ - Constructor functions that return objects with methods
53
+ - Object methods for common operations
54
+ - Companion functions for additional utilities
55
+ - [x] Align Task API with other monadic structures
56
+ - [ ] Standardize import patterns (@ imports vs relative paths)
57
+ - [x] Implement consistent error handling strategy for async operations
58
+
59
+ ### Testing and Documentation
60
+
61
+ - [ ] Add observable test coverage metrics
62
+ - [x] Implement property-based testing
63
+ - [ ] Expand error handling tests
64
+ - [ ] Add interoperability tests with other libraries
65
+
66
+ ### TypeScript Improvements
67
+
68
+ - [x] Enable stricter TypeScript settings (noImplicitAny: true)
69
+ - [x] Add noUncheckedIndexedAccess for safer array indexing
70
+ - [ ] Improve support for higher-kinded types:
71
+ - Current type parameters work well for first-order types
72
+ - Expand to support type constructors as parameters (F<A> => F<B>)
73
+ - [ ] Add branded/nominal types for stronger type safety
74
+ - [ ] Implement more type-level utilities (conditional types, template literals)
75
+ - [ ] Leverage newer TypeScript features (const type parameters, tuple manipulation)
76
+
77
+ ## Installation
78
+
79
+ ```bash
80
+ # NPM
81
+ npm install functype
82
+
83
+ # Yarn
84
+ yarn add functype
85
+
86
+ # PNPM
87
+ pnpm add functype
88
+
89
+ # Bun
90
+ bun add functype
91
+ ```
92
+
93
+ ### Bundle Size Optimization
94
+
95
+ Functype is optimized for tree-shaking and offers multiple import strategies to minimize bundle size:
96
+
97
+ ```typescript
98
+ // Selective module imports (recommended for production)
99
+ import { Option } from "functype/option"
100
+ import { Either } from "functype/either"
101
+
102
+ // Direct constructor imports (smallest bundle)
103
+ import { some, none } from "functype/option"
104
+ ```
105
+
106
+ For detailed optimization strategies, see the [Bundle Optimization Guide](docs/BUNDLE_OPTIMIZATION.md).
107
+
108
+ ## Usage Examples
109
+
110
+ ### Option
111
+
112
+ ```typescript
113
+ import { Option, Some, None } from "functype"
114
+
115
+ // Create options
116
+ const value = Option("hello") // Some("hello")
117
+ const empty = Option(null) // None
118
+ const explicit = Some(42) // Some(42)
119
+
120
+ // Transform values
121
+ const length = value.map((s) => s.length) // Some(5)
122
+ const nothing = empty.map((s) => s.length) // None
123
+
124
+ // Handle default values
125
+ const result = value.getOrElse("world") // "hello"
126
+ const fallback = empty.getOrElse("world") // "world"
127
+
128
+ // Conditionally filter
129
+ const filtered = value.filter((s) => s.length > 10) // None
130
+ ```
131
+
132
+ ### Either
133
+
134
+ ```typescript
135
+ import { Either, Right, Left } from "functype"
136
+
137
+ // Success case
138
+ const success = Right<string, number>(42)
139
+ // Error case
140
+ const failure = Left<string, number>("error")
141
+
142
+ // Transform values (map only applies to Right)
143
+ const doubled = success.map((x) => x * 2) // Right(84)
144
+ const stillError = failure.map((x) => x * 2) // Left("error")
145
+
146
+ // Handle errors
147
+ const value = success.getOrElse(0) // 42
148
+ const fallback = failure.getOrElse(0) // 0
149
+
150
+ // Pattern matching with fold
151
+ const result = success.fold(
152
+ (err) => `Error: ${err}`,
153
+ (val) => `Success: ${val}`,
154
+ ) // "Success: 42"
155
+ ```
156
+
157
+ ### List
158
+
159
+ ```typescript
160
+ import { List } from "functype"
161
+
162
+ const numbers = List([1, 2, 3, 4])
163
+
164
+ // Transform
165
+ const doubled = numbers.map((x) => x * 2) // List([2, 4, 6, 8])
166
+
167
+ // Filter
168
+ const evens = numbers.filter((x) => x % 2 === 0) // List([2, 4])
169
+
170
+ // Reduce
171
+ const sum = numbers.foldLeft(0)((acc, x) => acc + x) // 10
172
+
173
+ // Add/remove elements (immutably)
174
+ const withFive = numbers.add(5) // List([1, 2, 3, 4, 5])
175
+ const without3 = numbers.remove(3) // List([1, 2, 4])
176
+ ```
177
+
178
+ ### Try
179
+
180
+ ```typescript
181
+ import { Try } from "functype"
182
+
183
+ // Safely execute code that might throw
184
+ const result = Try(() => {
185
+ // Potentially throwing operation
186
+ return JSON.parse('{"name": "John"}')
187
+ })
188
+
189
+ // Handle success/failure
190
+ if (result.isSuccess()) {
191
+ console.log("Result:", result.get())
192
+ } else {
193
+ console.error("Error:", result.error)
194
+ }
195
+
196
+ // Transform with map (only applies on Success)
197
+ const name = result.map((obj) => obj.name)
198
+
199
+ // Convert to Either
200
+ const either = result.toEither()
201
+ ```
202
+
203
+ ### Task
204
+
205
+ ```typescript
206
+ import { Task } from "functype"
207
+
208
+ // Synchronous operations with error handling
209
+ const syncResult = Task().Sync(
210
+ () => "success",
211
+ (error) => new Error(`Failed: ${error}`),
212
+ )
213
+
214
+ // Asynchronous operations
215
+ const asyncTask = async () => {
216
+ const result = await Task().Async(
217
+ async () => await fetchData(),
218
+ async (error) => new Error(`Fetch failed: ${error}`),
219
+ )
220
+ return result
221
+ }
222
+
223
+ // Converting promise-based functions to Task
224
+ const fetchUserAPI = (userId: string): Promise<User> => fetch(`/api/users/${userId}`).then((r) => r.json())
225
+
226
+ // Use the adapter pattern for seamless integration
227
+ const fetchUser = Task({ name: "UserFetch" }).fromPromise(fetchUserAPI)
228
+
229
+ // Later use it with standard promise patterns
230
+ fetchUser("user123")
231
+ .then((user) => console.log(user))
232
+ .catch((error) => console.error(error))
233
+
234
+ // Or convert Task results back to promises
235
+ const taskResult = Task().Sync(() => "hello world")
236
+ const promise = Task().toPromise(taskResult) // Promise<string>
237
+ ```
238
+
239
+ ## Type Safety
240
+
241
+ Functype leverages TypeScript's advanced type system to provide compile-time safety for functional patterns, ensuring that your code is both robust and maintainable.
242
+
243
+ ```typescript
244
+ // Type inference works seamlessly
245
+ const option = Option(42)
246
+ // Inferred as number
247
+ const mappedValue = option.map((x) => x.toString())
248
+ // Inferred as string
249
+ ```
250
+
251
+ ## Contributing
252
+
253
+ Contributions are welcome! Please feel free to submit a Pull Request.
254
+
255
+ ## License
256
+
257
+ MIT License
258
+
259
+ Copyright (c) 2025 Jordan Burke
260
+
261
+ Permission is hereby granted, free of charge, to any person obtaining a copy
262
+ of this software and associated documentation files (the "Software"), to deal
263
+ in the Software without restriction, including without limitation the rights
264
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
265
+ copies of the Software, and to permit persons to whom the Software is
266
+ furnished to do so, subject to the following conditions:
267
+
268
+ The above copyright notice and this permission notice shall be included in all
269
+ copies or substantial portions of the Software.
270
+
271
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
272
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
273
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
274
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
275
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
276
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
277
+ SOFTWARE.
@@ -1,2 +1,2 @@
1
- export{a as Brand,g as BrandedBoolean,f as BrandedNumber,e as BrandedString,d as createBrander,c as hasBrand,b as unbrand}from'../chunk-TQJDL6YW.mjs';//# sourceMappingURL=index.mjs.map
1
+ export{a as Brand,g as BrandedBoolean,f as BrandedNumber,e as BrandedString,d as createBrander,c as hasBrand,b as unbrand}from'../chunk-42EDYQ3O.mjs';//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,2 @@
1
+ import {b as b$1,a,c as c$1}from'./chunk-DWRQQO3M.mjs';import z from'safe-stable-stringify';function $(e,t){return Object.assign(e,t)}function k(e,t){return {...a({_tag:e,impl:t}),toString(){return `${e}()`}}}var F="Throwable",R=class e extends Error{constructor(n,r){super(n,{cause:r?.cause});this._tag=F;this.name=F,Object.defineProperties(this,{_tag:{value:F,writable:false,configurable:false},data:{value:r?.data,writable:false,configurable:false},name:{value:F,writable:false,configurable:false}}),r?.cause&&Object.defineProperty(this,"cause",{value:r.cause,writable:false,configurable:false}),r?.stack?this.stack=r.stack:Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor);}static apply(n,r){if(n instanceof Error){let a=new e(n.message,{data:r,cause:n.cause||void 0,stack:n.stack||void 0});for(let p of Object.keys(n))p in a||(a[p]=n[p]);return a}if(n&&typeof n=="object"){let a=n,p=typeof a.message=="string"?a.message:typeof a.error=="string"?a.error:`Object error: ${JSON.stringify(a,Object.getOwnPropertyNames(a).filter(m=>a[m]!==void 0))}`,y=new e(p,{data:r||a});for(let m of Object.keys(a))m in y||(y[m]=a[m]);return y}if(typeof n=="function"){let a=n.name||"anonymous function",p=n.toString().substring(0,100)+(n.toString().length>100?"...":"");return new e(`Function error: ${a}`,{data:r||{functionType:typeof n,functionName:a,functionString:p}})}let s=typeof n,i=n===null?"null":n===void 0?"undefined":String(n);if(s==="number"){let a=n,p=Number.isNaN(a)?"Number error: NaN":Number.isFinite(a)?`Number error: ${a}`:`Number error: ${a>0?"Infinity":"-Infinity"}`;return new e(p,{data:r||{errorType:s,errorValue:a,originalError:n}})}if(s==="bigint")return new e(`BigInt error: ${n}n`,{data:r||{errorType:s,errorValue:String(n),originalError:n}});if(s==="boolean")return new e(`Boolean error: ${n}`,{data:r||{errorType:s,errorValue:n,originalError:n}});if(s==="symbol"){let a=n.description||"unnamed symbol";return new e(`Symbol error: Symbol(${a})`,{data:r||{errorType:s,symbolDescription:a,originalError:n}})}let o=typeof n=="string"?n:`${s.charAt(0).toUpperCase()+s.slice(1)} error: ${i}`;return new e(o,{data:r||{errorType:s,errorValue:i,originalError:n}})}};var _=Set;var B=e=>{let t=new _(e),n=d(t),r={...n,_tag:"Set",add:s=>B([...t,s]),remove:s=>{let i=new _(t);return i.delete(s),B(i)},contains:s=>t.has(s),has:s=>t.has(s),map:s=>B(n.map(s)),flatMap:s=>B(n.flatMap(s)),toList:()=>d(t),toSet:()=>r,toString:()=>`Set(${Array.from(t).toString()})`};return r},V=e=>B(e);var L=e=>{let t=Array.from(e||[]),n={_tag:"List",[Symbol.iterator]:()=>t[Symbol.iterator](),get size(){return t.length},get length(){return t.length},map:r=>L(t.map(r)),flatMap:r=>L(t.flatMap(s=>Array.from(r(s)))),flatMapAsync:async r=>{let s=await Promise.all(t.map(async i=>await r(i)));return L(s.flatMap(i=>Array.from(i)))},forEach:r=>t.forEach(r),count:r=>t.filter(r).length,exists:r=>t.some(r),filter:r=>L(t.filter(r)),filterNot:r=>L(t.filter(s=>!r(s))),filterType:r=>L(t.filter(s=>b$1(s,r))),find:(r,s)=>{let i=t.find(o=>r(o)&&(s?b$1(o,s):true));return E(i)},get head(){return t[0]},get headOption(){return t.length>0?E(t[0]):x()},get isEmpty(){return t.length===0},toArray:()=>[...t],reduce:r=>t.reduce(r),reduceRight:r=>t.reduceRight(r),foldLeft:r=>s=>t.reduce(s,r),foldRight:r=>s=>t.reduceRight((i,o)=>s(o,i),r),remove:r=>L(t.filter(s=>s!==r)),removeAt:r=>r<0||r>=t.length?n:L([...t.slice(0,r),...t.slice(r+1)]),add:r=>L([...t,r]),get:r=>E(t[r]),concat:r=>L([...t,...r.toArray()]),drop:r=>L(t.slice(r)),dropRight:r=>L(t.slice(0,-r)),dropWhile:r=>L(t.slice(t.findIndex(s=>!r(s)))),flatten:()=>L(t.flatMap(r=>Array.isArray(r)?r:[r])),toList:()=>n,toSet:()=>V(t),toString:()=>`List(${z(t)})`,toValue:()=>({_tag:"List",value:t})};return n},d=e=>L(e);var j=e=>({_tag:"Right",value:e,isLeft:()=>false,isRight:()=>true,getOrElse:t=>e,getOrThrow:()=>e,map:t=>T(t(e)),mapAsync:t=>t(e).then(n=>T(n)).catch(n=>Promise.resolve(u(n))),merge:t=>t.isLeft()?u(t.value):T([e,t.value]),flatMap:t=>t(e),flatMapAsync:t=>t(e).catch(n=>u(n)),toOption:()=>U(e),toList:()=>d([e]),toString:()=>`Right(${z(e)})`,[Symbol.iterator]:function*(){yield e;},yield:function*(){yield e;},traverse:t=>{let n=t(e);return n.isLeft()?u(n.value):T([n.value])},lazyMap:function*(t){yield T(t(e));},tap:t=>(t(e),T(e)),tapLeft:t=>T(e),mapLeft:t=>T(e),bimap:(t,n)=>T(n(e)),fold:(t,n)=>n(e),swap:()=>u(e),then:(t,n)=>Promise.resolve(e).then(t,n),toValue:()=>({_tag:"Right",value:e})}),q=e=>({_tag:"Left",value:e,isLeft:()=>true,isRight:()=>false,getOrElse:t=>t,getOrThrow:()=>{throw e},map:t=>u(e),mapAsync:t=>Promise.resolve(u(e)),merge:t=>u(e),flatMap:t=>u(e),flatMapAsync:t=>Promise.resolve(u(e)),toOption:()=>x(),toList:()=>d(),toString:()=>`Left(${z(e)})`,[Symbol.iterator]:function*(){},yield:function*(){},traverse:t=>u(e),lazyMap:function*(t){yield u(e);},tap:t=>u(e),tapLeft:t=>(t(e),u(e)),mapLeft:t=>u(t(e)),bimap:(t,n)=>u(t(e)),fold:(t,n)=>t(e),swap:()=>T(e),then:(t,n)=>Promise.reject(e).then(null,n),toValue:()=>({_tag:"Left",value:e})}),T=e=>j(e),u=e=>q(e),Se=e=>e.isRight(),Be=e=>e.isLeft(),Fe=(e,t)=>{try{return T(e())}catch(n){return u(t(n))}},ne=e=>j(e);console.assert(ne);var re=e=>q(e);console.assert(re);var Ve=async(e,t)=>{try{let n=await e();return T(n)}catch(n){return u(t(n))}},oe={sequence:e=>{let t=[];for(let n of e){if(n.isLeft())return u(n.value);t.push(n.value);}return T(t)},traverse:(e,t)=>oe.sequence(e.map(t)),fromNullable:(e,t)=>e==null?u(t):T(e),fromPredicate:(e,t,n)=>t(e)?T(e):u(n),ap:(e,t)=>e.flatMap(n=>t.map(n)),fromPromise:async(e,t)=>{try{let n=await e;return T(n)}catch(n){return u(t(n))}}};var c=e=>{let t=new Promise((n,r)=>{try{e(n,r);}catch(s){r(s);}});return {_tag:"FPromise",map:n=>c((r,s)=>{t.then(i=>{try{r(n(i));}catch(o){s(o);}}).catch(s);}),flatMap:n=>c((r,s)=>{t.then(i=>{try{let o=n(i);"_tag"in o&&o._tag==="FPromise"?o.then(r,s):Promise.resolve(o).then(r,s);}catch(o){s(o);}}).catch(s);}),flatMapAsync:async n=>{let r=await t,s=n(r);return s instanceof Promise?s:new Promise((i,o)=>{s.then(i,o);})},tap:n=>c((r,s)=>{t.then(i=>{try{n(i),r(i);}catch(o){s(o);}}).catch(s);}),mapError:n=>c((r,s)=>{t.then(r).catch(i=>{try{let o={originalError:i,stack:i instanceof Error?i.stack:void 0,timestamp:Date.now()};s(n(i,o));}catch(o){s(o);}});}),tapError:n=>c((r,s)=>{t.then(r).catch(i=>{try{n(i),s(i);}catch(o){s(o);}});}),recover:n=>c(r=>{t.then(r).catch(()=>r(n));}),recoverWith:n=>c(r=>{t.then(r).catch(s=>{try{r(n(s));}catch{r(null);}});}),recoverWithF:n=>c((r,s)=>{t.then(r).catch(i=>{try{n(i).then(r,s);}catch(o){s(o);}});}),filterError:(n,r)=>c((s,i)=>{t.then(s).catch(o=>{if(n(o))try{r(o).then(s,i);}catch(a){i(a);}else i(o);});}),logError:n=>c((r,s)=>{t.then(r).catch(i=>{try{let o={originalError:i,stack:i instanceof Error?i.stack:void 0,timestamp:Date.now()};n(i,o);}catch{}finally{s(i);}});}),then:(n,r)=>t.then(n,r),toPromise:()=>t,toEither:()=>t}},se={resolve:e=>c(t=>t(e)),reject:e=>c((t,n)=>n(e)),from:e=>c((t,n)=>{e.then(t).catch(n);}),fromEither:e=>e.isRight()?c(t=>t(e.value)):c((t,n)=>n(e.value)),all:e=>c((t,n)=>{Promise.all(e.map(r=>r instanceof Promise?r:Promise.resolve(r))).then(t).catch(n);}),allSettled:e=>c(t=>{let n=[],r=0;if(e.length===0){t([]);return}e.forEach((s,i)=>{Promise.resolve(s).then(o=>{n[i]=T(o),r++,r===e.length&&t(n);}).catch(o=>{n[i]=u(o),r++,r===e.length&&t(n);});});}),race:e=>c((t,n)=>{Promise.race(e).then(t,n);}),any:e=>c((t,n)=>{if(typeof Promise.any=="function")Promise.any(e).then(t,n);else {let r=0,s=[];if(e.length===0){n(new AggregateError([],"All promises were rejected"));return}e.forEach((i,o)=>{Promise.resolve(i).then(t).catch(a=>{s[o]=a,r++,r===e.length&&n(new AggregateError(s,"All promises were rejected"));});});}}),retryWithBackoff:(e,t)=>{let{maxRetries:n,baseDelay:r=100,shouldRetry:s=()=>true}=t;return c((i,o)=>{let a=0,p=()=>{e().toPromise().then(i).catch(y=>{if(a++,a<=n&&s(y,a)){let m=r*Math.pow(2,a-1);setTimeout(p,m);}else o(y);});};p();})}},W=$(c,se);var D=(e,t,n)=>{let r=n?.name||"TaskException",s=n?.description||"Unspecified TaskException",i=R.apply(e,t);return {...k("TaskException",u(i)),_task:{name:r,description:s}}},G=(e,t)=>{let n=t?.name||"TaskResult",r=t?.description||"Unspecified TaskResult";return {...k("TaskResult",T(e)),_task:{name:n,description:r}}},qe=e=>{let t=e?.name||"Task",n=e?.description||"",r={Async:(s,i=a=>a,o=()=>{})=>W(async(a,p)=>{try{let y=await s();try{await o();}catch(m){p(R.apply(m));return}a(y);}catch(y){try{await o();}catch(m){p(R.apply(m));return}try{let m=await i(y);p(R.apply(m));}catch(m){p(R.apply(m));}}}),Sync:(s,i=a=>a,o=()=>{})=>{try{return G(s(),{name:t,description:n})}catch(a){return D(i(a),{name:t,description:n})}finally{o();}},success:s=>G(s,{name:t,description:n}),fail:s=>D(s,{name:t,description:n}),fromPromise:s=>(...i)=>r.Async(()=>s(...i),o=>o),toPromise:s=>new Promise((i,o)=>{s.isRight()?i(s.value):o(s.value);})};return {...k("Task",r),_type:"Task"}};var H=e=>({_tag:"Success",error:void 0,isSuccess:()=>true,isFailure:()=>false,get:()=>e,getOrElse:t=>e,orElse:t=>H(e),orThrow:t=>e,toEither:()=>T(e),map:t=>ae(()=>t(e)),flatMap:t=>t(e),toString:()=>`Success(${z(e)})`,toValue:()=>({_tag:"Success",value:e})}),N=e=>({_tag:"Failure",error:e,isSuccess:()=>false,isFailure:()=>true,get:()=>{throw e},getOrElse:t=>t,orElse:t=>t,orThrow:t=>{throw t},toEither:()=>u(e),map:t=>N(e),flatMap:t=>N(e),toString:()=>`Failure(${z(e)}))`,toValue:()=>({_tag:"Failure",value:e})}),ae=e=>{try{return H(e())}catch(t){return N(t instanceof Error?t:new Error(String(t)))}};var A=e=>e!==null&&typeof e=="object"&&(e._tag==="Some"||e._tag==="None"),g=e=>e!==null&&typeof e=="object"&&e._tag==="List",b=e=>e!==null&&typeof e=="object"&&(e._tag==="Left"||e._tag==="Right"),P=e=>e!==null&&typeof e=="object"&&(e._tag==="Success"||e._tag==="Failure"),h=()=>{let e=(o,a)=>{if(A(o)||g(o)||b(o)||P(o))return o.map(a);throw new Error(`Unsupported functor type: ${JSON.stringify(o)}`)},t=o=>{if(A(o))return o.get();if(g(o)){let a=o.toArray();if(a.length>0&&g(a[0])){let p=[];for(let y of a)g(y)&&p.push(...y.toArray());return d(p)}return o.flatten()}if(b(o))return o.isRight()?o.fold(()=>null,a=>a):o;if(P(o))return o.isSuccess()?o.get():o;throw new Error(`Unsupported functor type for flatten: ${JSON.stringify(o)}`)},n=(o,a)=>{if(A(o)||g(o)||b(o)||P(o))return o.flatMap(a);throw new Error(`Unsupported functor type for flatMap: ${JSON.stringify(o)}`)},r=(o,a)=>{if(A(o)&&A(a))return o.flatMap(p=>a.map(p));if(g(o)&&g(a))return o.flatMap(p=>a.map(p));if(b(o)&&b(a))return o.flatMap(p=>a.map(p));if(P(o)&&P(a))return o.flatMap(p=>a.map(p));throw new Error(`Unsupported functor type for ap: ${JSON.stringify(o)}`)},s=o=>{if(A(o)){let a=o;if(a.isEmpty)return d([E.none()]);let p=a.get();if(g(p))return p.map(y=>E(y));throw new Error("Unsupported inner container type for sequence")}if(g(o)){let p=o.toArray();if(p.length===0)return E.none();let y=p[0];if(A(y)){for(let S of p)if(S.isEmpty)return E.none();let m=p.map(S=>S.get());return E(d(m))}throw new Error("Unsupported inner container type for sequence")}throw new Error(`Unsupported outer container type for sequence: ${JSON.stringify(o)}`)};return {...k("HKT",{map:e,flatten:t,flatMap:n,ap:r,sequence:s,traverse:(o,a)=>s(e(o,a))}),_type:"HKT"}};h.map=(e,t)=>h().map(e,t);h.flatten=e=>h().flatten(e);h.flatMap=(e,t)=>h().flatMap(e,t);h.ap=(e,t)=>h().ap(e,t);h.sequence=e=>h().sequence(e);h.traverse=(e,t)=>h().traverse(e,t);h.isOption=A;h.isList=g;h.isEither=b;h.isTry=P;function et(e){return {id:e,isSame:n=>n.id===e}}var O=Map;var w=e=>{let t="Map",n={values:new O(e)},r=()=>Array.from(n.values.entries()).map(([l,f])=>c$1([l,f])),s=l=>w(new O(n.values).set(l.toArray()[0],l.toArray()[1]).entries()),i=l=>{let f=new O(n.values);return f.delete(l)?w(f.entries()):w(n.values.entries())},o=l=>{let f=l.toArray();return n.values.get(f[0])===f[1]},a=()=>n.values.size,p=l=>w(Array.from(n.values.entries()).map(([f,ee])=>[f,l(ee)])),y=l=>{let f=w(n.values.entries()).toList();return w(f.flatMap(l).toArray())},m=l=>d(r()).reduce(l),S=l=>d(r()).reduceRight(l),M=l=>f=>d(r()).foldLeft(l)(f),Q=l=>f=>d(r()).foldRight(l)(f),X=l=>E(n.values.get(l)),Y=(l,f)=>E(n.values.get(l)).getOrElse(f),Z=()=>n.values.size===0;return {_tag:t,add:s,remove:i,contains:o,get size(){return a()},map:p,flatMap:y,reduce:m,reduceRight:S,foldLeft:M,foldRight:Q,get:X,getOrElse:Y,get isEmpty(){return Z()},orElse:(l,f)=>E(n.values.get(l)).orElse(f),toList:()=>d(r()),toSet:()=>V(r()),toString:()=>`Map(${r().toString()})`,toValue:()=>({_tag:"Map",value:n.values})}},pt=e=>w(e);var U=e=>({_tag:"Some",value:e,isEmpty:false,get:()=>e,getOrElse:()=>e,getOrThrow:()=>e,orElse:()=>U(e),orNull:()=>e,map:t=>U(t(e)),filter(t){return t(e)?U(e):v},fold:(t,n)=>n(e),flatMap:t=>t(e),flatMapAsync:async t=>await t(e),reduce:t=>t(void 0,e),reduceRight:t=>t(void 0,e),foldLeft:t=>n=>n(t,e),foldRight:t=>n=>n(e,t),toList:()=>d([e]),contains:t=>t===e,size:1,toEither:t=>T(e),toString:()=>`Some(${z(e)})`,toValue:()=>({_tag:"Some",value:e})}),v={_tag:"None",value:void 0,isEmpty:true,get:()=>{throw new Error("Cannot call get() on None")},getOrElse:e=>e,getOrThrow(e){throw e},orElse:e=>e,orNull:()=>null,map:e=>v,filter(e){return v},flatMap:e=>v,flatMapAsync:async e=>v,reduce:()=>{},reduceRight:()=>{},fold:(e,t)=>e(),foldLeft:e=>()=>e,foldRight:e=>()=>e,toList:()=>d([]),contains:()=>false,size:0,toEither:e=>u(e),toString:()=>"None",toValue:()=>({_tag:"None",value:void 0})},x=()=>v,E=e=>e!=null?U(e):x();E.from=e=>E(e);E.none=()=>x();export{$ as a,k as b,R as c,U as d,x as e,E as f,V as g,d as h,T as i,u as j,Se as k,Be as l,Fe as m,ne as n,re as o,Ve as p,oe as q,se as r,W as s,D as t,G as u,qe as v,ae as w,h as x,et as y,pt as z};//# sourceMappingURL=chunk-3KVYTZJT.mjs.map
2
+ //# sourceMappingURL=chunk-3KVYTZJT.mjs.map