functype 2.1.0 → 2.2.1

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/README.md CHANGED
@@ -5,16 +5,16 @@
5
5
  </picture>
6
6
  </p>
7
7
 
8
- # Functype
8
+ # functype
9
9
 
10
10
  [![NPM Version](https://img.shields.io/npm/v/functype)](https://www.npmjs.com/package/functype)
11
11
  [![CI](https://github.com/jordanburke/functype/actions/workflows/ci.yml/badge.svg)](https://github.com/jordanburke/functype/actions/workflows/ci.yml)
12
12
 
13
13
  ## A Functional Programming Library for TypeScript
14
14
 
15
- 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.
15
+ 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.
16
16
 
17
- [API Documentation](https://jordanburke.github.io/functype/) · [Cheatsheet for Scala / cats / fp-ts users](./CHEATSHEET.md)
17
+ [Website](https://functype.org/) · [API Documentation](https://functype.org/api-docs/) · [Cheatsheet for Scala / cats / Effect users](./CHEATSHEET.md)
18
18
 
19
19
  ### CLI Documentation
20
20
 
@@ -30,7 +30,7 @@ npx functype --json # JSON output for programmatic use
30
30
  ## Core Principles
31
31
 
32
32
  - **Zero Dependencies**: No third-party runtime dependencies — just TypeScript
33
- - **Immutability**: All data structures are immutable, promoting predictable and side-effect-free code
33
+ - **Immutability**: All data structures are immutable, promoting predictable and side-effect-free code. The types mark every field read-only, and eslint-plugin-functype's `no-container-mutation` reports a write through a cast. Under `NODE_ENV=development` collections also freeze each value, so a write from untyped code throws; `FUNCTYPE_FREEZE=1` turns that on anywhere, such as a test suite, and `FUNCTYPE_FREEZE=0` turns it off. Production doesn't freeze, because freezing was most of what building a collection cost
34
34
  - **Type Safety**: Leverages TypeScript's type system to ensure compile-time safety
35
35
  - **Composability**: Provides abstractions for building complex programs from simple components
36
36
  - **Functional Paradigms**: Embraces concepts like monads, functors, and type classes
@@ -87,6 +87,7 @@ bun add functype
87
87
 
88
88
  ```typescript
89
89
  import { Option } from "functype/option" // bundles the same as importing from "functype"
90
+ import { Either, IO, List, Option } from "functype/core" // the 17 names most code needs, in one import
90
91
  ```
91
92
 
92
93
  For the measured sizes and how they are checked, see the [Bundle Size guide](docs/BUNDLE_OPTIMIZATION.md).
@@ -180,7 +181,7 @@ const result = Lazy(() => 10)
180
181
 
181
182
  ### Do-notation (High-Performance For-Comprehensions)
182
183
 
183
- Functype provides generator-based Do-notation for monadic composition, similar to Scala's for-comprehensions, with **significant performance advantages for List operations**:
184
+ functype provides generator-based Do-notation for monadic composition, similar to Scala's for-comprehensions, with **significant performance advantages for List operations**:
184
185
 
185
186
  ```typescript
186
187
  import { Do, DoAsync, $ } from "functype"
@@ -272,7 +273,7 @@ const asyncResult = await DoAsync(async function* () {
272
273
  ```typescript
273
274
  import { IO } from "functype"
274
275
 
275
- type User = { id: string; name: string }
276
+ type User = { id: string; name: string; settings: string }
276
277
 
277
278
  const loadUser = (id: string) =>
278
279
  IO.tryPromise({
@@ -288,6 +289,12 @@ const user = await loadUser("42").retry(2).timeout(5000).run()
288
289
  const { result, cancel } = loadUser("42").runCancellable()
289
290
  const controller = new AbortController()
290
291
  const exit = await loadUser("42").runExit({ signal: controller.signal }) // Success | Failure | Die | Interrupted
292
+
293
+ // A callback that may throw: in map a throw is a defect and run() rejects; mapTry makes it a typed error
294
+ const settings = loadUser("42").mapTry(
295
+ (user) => JSON.parse(user.settings) as unknown,
296
+ (error) => new Error(`Bad settings: ${String(error)}`),
297
+ )
291
298
  ```
292
299
 
293
300
  #### Tracing
@@ -387,7 +394,7 @@ TracedOption(user, tracer, "span-1")
387
394
 
388
395
  ## Conditional Programming
389
396
 
390
- Functype provides `Cond` and `Match` for functional conditional logic without early returns:
397
+ functype provides `Cond` and `Match` for functional conditional logic without early returns:
391
398
 
392
399
  ### Cond
393
400
 
@@ -494,7 +501,7 @@ const classifier = Match.builder<Animal, string>()
494
501
 
495
502
  ## Fold
496
503
 
497
- Functype includes a powerful `fold` operation for pattern matching and extracting values:
504
+ functype includes a powerful `fold` operation for pattern matching and extracting values:
498
505
 
499
506
  ```typescript
500
507
  import { Option, Either, Try, List } from "functype"
@@ -527,7 +534,7 @@ const listResult = list.foldLeft(0)((acc, num) => acc + num) // 6
527
534
 
528
535
  ## Foldable
529
536
 
530
- Functype includes a `Foldable` type class that all data structures implement:
537
+ functype includes a `Foldable` type class that all data structures implement:
531
538
 
532
539
  ```typescript
533
540
  import { FoldableUtils, Option, List, Try } from "functype"
@@ -558,7 +565,7 @@ const convertedToEither = FoldableUtils.toEither(tryVal, "Error") // Right(10)
558
565
 
559
566
  ## Matchable
560
567
 
561
- Functype includes a `Matchable` type class for enhanced pattern matching:
568
+ functype includes a `Matchable` type class for enhanced pattern matching:
562
569
 
563
570
  ```typescript
564
571
  import { Option, Either, Try, List, MatchableUtils } from "functype"
@@ -606,11 +613,11 @@ const result = isPositive(num) ?? defaultCase(num) // "Positive: 42"
606
613
 
607
614
  ## Interface Hierarchy
608
615
 
609
- All data structures in Functype implement a unified hierarchy of interfaces, providing consistent behavior across the library:
616
+ All data structures in functype implement a unified hierarchy of interfaces, providing consistent behavior across the library:
610
617
 
611
618
  ### Type Classes
612
619
 
613
- Functype leverages type classes to provide common operations:
620
+ functype leverages type classes to provide common operations:
614
621
 
615
622
  - **Functor**: Supports `map` operation for transforming wrapped values
616
623
  - **Applicative**: Extends Functor with `ap` for applying wrapped functions
@@ -677,11 +684,11 @@ list.forEach(console.log) // Logs: 1, 2, 3, 4, 5
677
684
 
678
685
  ## Feature Matrix
679
686
 
680
- For a comprehensive overview of which interfaces are supported by each data structure, see the [Functype Feature Matrix](docs/FUNCTYPE_FEATURE_MATRIX.md).
687
+ For a comprehensive overview of which interfaces are supported by each data structure, see the [functype Feature Matrix](docs/FUNCTYPE_FEATURE_MATRIX.md).
681
688
 
682
689
  ## Type Safety
683
690
 
684
- Functype leverages TypeScript's advanced type system to provide compile-time safety for functional patterns, ensuring that your code is both robust and maintainable.
691
+ functype leverages TypeScript's advanced type system to provide compile-time safety for functional patterns, ensuring that your code is both robust and maintainable.
685
692
 
686
693
  ```typescript
687
694
  // Type inference works seamlessly
@@ -693,7 +700,7 @@ const mappedValue = option.map((x) => x.toString())
693
700
 
694
701
  ## Error Formatting
695
702
 
696
- Functype provides utilities for improved error visualization and logging:
703
+ functype provides utilities for improved error visualization and logging:
697
704
 
698
705
  ```typescript
699
706
  import { Throwable, createErrorSerializer, formatError, formatErrorChain } from "functype"
@@ -750,7 +757,7 @@ For more details, see the [Error Formatting Guide](docs/error-formatting.md).
750
757
  - ✓ Add Pipe interface for composition
751
758
  - ✓ Add Serializable for persistence
752
759
  - ✓ Add Typeable support
753
- - [ ] Implement NonEmptyList<A>
760
+ - [ ] Implement `NonEmptyList<A>`
754
761
  - List guaranteed to have at least one element
755
762
  - Prevents empty list errors at compile time
756
763
  - Full standard interface implementation
@@ -758,7 +765,7 @@ For more details, see the [Error Formatting Guide](docs/error-formatting.md).
758
765
 
759
766
  ### Medium Priority
760
767
 
761
- - [ ] Implement ValidatedNel<E, A> for validation with error accumulation
768
+ - [ ] Implement `ValidatedNel<E, A>` for validation with error accumulation
762
769
  - Unlike Either, collects multiple errors
763
770
  - Uses NonEmptyList for error collection
764
771
  - Applicative instance combines errors
@@ -768,7 +775,7 @@ For more details, see the [Error Formatting Guide](docs/error-formatting.md).
768
775
  - ✓ Add guard clauses (when conditions)
769
776
  - ✓ Support destructuring patterns
770
777
  - ✓ Consolidated into unified Match implementation
771
- - [x] Implement IO<R,E,A> effect type
778
+ - [x] Implement `IO<R,E,A>` effect type
772
779
  - ✓ Lazy execution with typed errors
773
780
  - ✓ Dependency injection (Tag, Context, Layer)
774
781
  - ✓ Composable operations (map, flatMap, zip, race)
@@ -783,7 +790,7 @@ For more details, see the [Error Formatting Guide](docs/error-formatting.md).
783
790
  - ✓ Add Serializable for persistence
784
791
  - ✓ Add Companion pattern with utility methods
785
792
  - ✓ Added specialized pair() and triple() constructors
786
- - [ ] Implement Lens<S, A> for immutable updates
793
+ - [ ] Implement `Lens<S, A>` for immutable updates
787
794
  - Composable property access
788
795
  - Type-safe nested updates
789
796
  - Works with all functype data structures
@@ -829,7 +836,7 @@ For more details, see the [Error Formatting Guide](docs/error-formatting.md).
829
836
  - [x] Add noUncheckedIndexedAccess for safer array indexing
830
837
  - [ ] Improve support for higher-kinded types:
831
838
  - Current type parameters work well for first-order types
832
- - Expand to support type constructors as parameters (F<A> => F<B>)
839
+ - Expand to support type constructors as parameters (`F<A> => F<B>`)
833
840
  - [x] Add branded/nominal types for stronger type safety
834
841
  - [x] Implement more type-level utilities — partial (`Widen<A, B>` conditional-type helper in `src/typeclass/variance.ts`; more in `src/types/`, `src/typeable/`)
835
842
  - [ ] Leverage newer TypeScript features (const type parameters, tuple manipulation)
@@ -861,9 +868,9 @@ Work that shipped but wasn't captured in the planned roadmap above:
861
868
 
862
869
  ## Claude Code Skills
863
870
 
864
- Functype provides two specialized Claude Code skills to enhance your development experience:
871
+ functype provides two specialized Claude Code skills to enhance your development experience:
865
872
 
866
- ### Functype User Guide
873
+ ### functype User Guide
867
874
 
868
875
  Help for developers using functype in their projects:
869
876
 
@@ -873,7 +880,7 @@ Help for developers using functype in their projects:
873
880
 
874
881
  **Install**: Download from [dist/skills/functype-user.zip](./dist/skills/functype-user.zip)
875
882
 
876
- ### Functype Library Developer
883
+ ### functype Library Developer
877
884
 
878
885
  Guide for contributors developing functype itself:
879
886
 
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `functype/core`: the names most code needs, as one short import. The root `functype` import exports
3
+ * everything, over a hundred values; reach for it when you need more, such as Layer, Http, Match, Cond, Lazy,
4
+ * branded types, validation or serialization.
5
+ *
6
+ * This is for discoverability, not bundle size: since 2.0 a root import tree-shakes to the same bundle
7
+ * as a subpath import. Every name here is the same value as the root export of that name.
8
+ */
9
+ import { Either, Left, Right, isLeft, isRight, tryCatch, tryCatchAsync } from "../either/index.js";
10
+ import { IO } from "../io/IO.js";
11
+ import { Tag } from "../io/Tag.js";
12
+ import { None, Option, Some } from "../option/index.js";
13
+ import { Try } from "../try/index.js";
14
+ import { List } from "../list/index.js";
15
+ import { Map } from "../map/index.js";
16
+ import { Set } from "../set/index.js";
17
+ import { Tuple } from "../tuple/index.js";
18
+ export { Either, IO, Left, List, Map, None, Option, Right, Set, Some, Tag, Try, Tuple, isLeft, isRight, tryCatch, tryCatchAsync };
@@ -0,0 +1 @@
1
+ import{Either as e,Left as t,Right as n,isLeft as r,isRight as i,tryCatch as a,tryCatchAsync as o}from"../either/index.js";import{IO as s}from"../io/IO.js";import{Tag as c}from"../io/Tag.js";import{None as l,Option as u,Some as d}from"../option/index.js";import{Try as f}from"../try/index.js";import{List as p}from"../list/index.js";import{Map as m}from"../map/index.js";import{Set as h}from"../set/index.js";import{Tuple as g}from"../tuple/index.js";export{e as Either,s as IO,t as Left,p as List,m as Map,l as None,u as Option,n as Right,h as Set,d as Some,c as Tag,f as Try,g as Tuple,r as isLeft,i as isRight,a as tryCatch,o as tryCatchAsync};
@@ -4,10 +4,10 @@
4
4
  *
5
5
  * ## Scala Equivalents
6
6
  *
7
- * Functype: `const x = yield* $(Option(5))`
7
+ * functype: `const x = yield* $(Option(5))`
8
8
  * Scala: `x <- Some(5)`
9
9
  *
10
- * Functype: `return x + y`
10
+ * functype: `return x + y`
11
11
  * Scala: `yield x + y`
12
12
  *
13
13
  * ## Core Concepts
@@ -8,7 +8,7 @@ import { Type } from "../types/index.js";
8
8
  */
9
9
  export type Kind<F, A> = F extends ((arg: infer T) => infer R) ? R : never;
10
10
  /**
11
- * Type constructors for common Functype data types
11
+ * Type constructors for common functype data types
12
12
  */
13
13
  export type OptionKind = <A>(a: A) => Option<A>;
14
14
  export type ListKind = <A>(a: A) => List<A>;
@@ -0,0 +1 @@
1
+ const e=e=>{try{return globalThis.process?.env?.[e]}catch{return}},t=(()=>{let t=e(`FUNCTYPE_FREEZE`)?.trim().toLowerCase();return t===`1`||t===`true`?!0:t===`0`||t===`false`?!1:e(`NODE_ENV`)===`development`})(),n=e=>t?Object.freeze(e):e;export{t as FREEZE_VALUES,n as freezeInDevelopment};
@@ -1 +1 @@
1
- import{Companion as e}from"../companion/Companion.js";import{define as t}from"../internal/define.js";import{Counter as n}from"../internal/mutation-utils.js";import{Option as r}from"../option/index.js";import{Ref as i}from"../ref/Ref.js";import{createSerializer as a}from"../serialization/SerializationCompanion.js";import{List as o}from"./index.js";const s=t()(`LazyList`,{[Symbol.toStringTag]:`LazyList`,[Symbol.iterator](){return this.source[Symbol.iterator]()},head(){let e=this.source[Symbol.iterator]().next();return e.done?void 0:e.value},headOption(){let e=this.source[Symbol.iterator]().next();return e.done?r.none():r(e.value)},last(){let e;for(let t of this.source)e=t;return e},lastOption(){let e=i(void 0),t=i(!1);for(let n of this.source)e.set(n),t.set(!0);return t.get()?r(e.get()):r.none()},tail(){let{source:e}=this;return c((function*(){let t=e[Symbol.iterator]();t.next();let n=t.next();for(;!n.done;)yield n.value,n=t.next()})())},init(){let e=Array.from(this.source);return c(e.length===0?[]:e.slice(0,-1))},map(e){let{source:t}=this;return c((function*(){for(let n of t)yield e(n)})())},flatMap(e){let{source:t}=this;return c((function*(){for(let n of t)yield*e(n)})())},filter(e){let{source:t}=this;return c((function*(){for(let n of t)e(n)&&(yield n)})())},take(e){let{source:t}=this;return c((function*(){let r=n(0);for(let n of t){if(!(r.get()<e))break;yield n,r.increment()}})())},drop(e){let{source:t}=this;return c((function*(){let r=n(0);for(let n of t)r.get()>=e&&(yield n),r.increment()})())},takeWhile(e){let{source:t}=this;return c((function*(){for(let n of t){if(!e(n))break;yield n}})())},dropWhile(e){let{source:t}=this;return c((function*(){let n=i(!0);for(let r of t)n.get()&&e(r)||(n.set(!1),yield r)})())},concat(e){let{source:t}=this;return c((function*(){yield*t,yield*e})())},zip(e){let{source:t}=this;return c((function*(){let n=t[Symbol.iterator](),r=e[Symbol.iterator]();for(;;){let e=n.next(),t=r.next();if(e.done||t.done)break;yield[e.value,t.value]}})())},toList(){return o(Array.from(this.source))},toArray(){return Array.from(this.source)},forEach(e){for(let t of this.source)e(t)},reduce(e,t){let n=i(t);for(let t of this.source)n.set(e(n.get(),t));return n.get()},find(e){for(let t of this.source)if(e(t))return r(t);return r.none()},some(e){for(let t of this.source)if(e(t))return!0;return!1},every(e){for(let t of this.source)if(!e(t))return!1;return!0},count(){let e=n(0);for(let t of this.source)e.increment();return e.get()},takeRight(e){let t=Array.from(this.source);return c(e>0?t.slice(-e):[])},reverse(){return c(Array.from(this.source).reverse())},distinct(){let{source:e}=this;return c((function*(){let t=new globalThis.Set;for(let n of e)t.has(n)||(t.add(n),yield n)})())},zipWithIndex(){let{source:e}=this;return c((function*(){let t=n(0);for(let n of e)yield[n,t.get()],t.increment()})())},fold(e,t){let n=e;for(let e of this.source)n=t(n,e);return n},foldLeft(e){return t=>{let n=i(e);for(let e of this.source)n.set(t(n.get(),e));return n.get()}},foldRight(e){return t=>Array.from(this.source).reduceRight((e,n)=>t(n,e),e)},pipe(e){return e(this)},serialize(){return a(`LazyList`,Array.from(this.source))},toJSON(){return{"@functype":`LazyList`,_tag:`LazyList`,value:Array.from(this.source)}},toString(){let e=[],t=n(0),r=i(!1);for(let n of this.source)if(t.get()<10)e.push(n),t.increment();else{r.set(!0);break}let a=e.map(e=>String(e)).join(`, `);return r.get()?`LazyList(${a}, ...)`:`LazyList(${a})`}}),c=e=>{let t=Object.create(s);return t._tag=`LazyList`,t.source=e,Object.freeze(t)},l=e(e=>c(e),{empty:()=>c([]),of:(...e)=>c(e),from:(...e)=>c(e),fromJSON:e=>{let t=JSON.parse(e);if(t[`@functype`]!==void 0&&t[`@functype`]!==`LazyList`)throw Error(`LazyList.fromJSON: expected @functype="LazyList", got ${JSON.stringify(t[`@functype`])}`);return c(t.value)},iterate:(e,t)=>c((function*(){let n=i(e);for(;;)yield n.get(),n.set(t(n.get()))})()),generate:e=>c((function*(){for(;;)yield e()})()),range:(e,t,n=1)=>c((function*(){if(n===0)throw Error(`Step cannot be zero`);let r=i(e);if(n>0)for(;r.get()<t;)yield r.get(),r.set(r.get()+n);else for(;r.get()>t;)yield r.get(),r.set(r.get()+n)})()),repeat:(e,t)=>c((function*(){if(t===void 0)for(;;)yield e;else{let r=n(0);for(;r.get()<t;)yield e,r.increment()}})()),cycle:e=>c((function*(){let t=Array.from(e);if(t.length!==0)for(;;)yield*t})())});export{l as LazyList};
1
+ import{Companion as e}from"../companion/Companion.js";import{define as t}from"../internal/define.js";import{freezeInDevelopment as n}from"../internal/freeze.js";import{Counter as r}from"../internal/mutation-utils.js";import{Option as i}from"../option/index.js";import{Ref as a}from"../ref/Ref.js";import{createSerializer as o}from"../serialization/SerializationCompanion.js";import{List as s}from"./index.js";const c=t()(`LazyList`,{[Symbol.toStringTag]:`LazyList`,[Symbol.iterator](){return this.source[Symbol.iterator]()},head(){let e=this.source[Symbol.iterator]().next();return e.done?void 0:e.value},headOption(){let e=this.source[Symbol.iterator]().next();return e.done?i.none():i(e.value)},last(){let e;for(let t of this.source)e=t;return e},lastOption(){let e=a(void 0),t=a(!1);for(let n of this.source)e.set(n),t.set(!0);return t.get()?i(e.get()):i.none()},tail(){let{source:e}=this;return l((function*(){let t=e[Symbol.iterator]();t.next();let n=t.next();for(;!n.done;)yield n.value,n=t.next()})())},init(){let e=Array.from(this.source);return l(e.length===0?[]:e.slice(0,-1))},map(e){let{source:t}=this;return l((function*(){for(let n of t)yield e(n)})())},flatMap(e){let{source:t}=this;return l((function*(){for(let n of t)yield*e(n)})())},filter(e){let{source:t}=this;return l((function*(){for(let n of t)e(n)&&(yield n)})())},take(e){let{source:t}=this;return l((function*(){let n=r(0);for(let r of t){if(!(n.get()<e))break;yield r,n.increment()}})())},drop(e){let{source:t}=this;return l((function*(){let n=r(0);for(let r of t)n.get()>=e&&(yield r),n.increment()})())},takeWhile(e){let{source:t}=this;return l((function*(){for(let n of t){if(!e(n))break;yield n}})())},dropWhile(e){let{source:t}=this;return l((function*(){let n=a(!0);for(let r of t)n.get()&&e(r)||(n.set(!1),yield r)})())},concat(e){let{source:t}=this;return l((function*(){yield*t,yield*e})())},zip(e){let{source:t}=this;return l((function*(){let n=t[Symbol.iterator](),r=e[Symbol.iterator]();for(;;){let e=n.next(),t=r.next();if(e.done||t.done)break;yield[e.value,t.value]}})())},toList(){return s(Array.from(this.source))},toArray(){return Array.from(this.source)},forEach(e){for(let t of this.source)e(t)},reduce(e,t){let n=a(t);for(let t of this.source)n.set(e(n.get(),t));return n.get()},find(e){for(let t of this.source)if(e(t))return i(t);return i.none()},some(e){for(let t of this.source)if(e(t))return!0;return!1},every(e){for(let t of this.source)if(!e(t))return!1;return!0},count(){let e=r(0);for(let t of this.source)e.increment();return e.get()},takeRight(e){let t=Array.from(this.source);return l(e>0?t.slice(-e):[])},reverse(){return l(Array.from(this.source).reverse())},distinct(){let{source:e}=this;return l((function*(){let t=new globalThis.Set;for(let n of e)t.has(n)||(t.add(n),yield n)})())},zipWithIndex(){let{source:e}=this;return l((function*(){let t=r(0);for(let n of e)yield[n,t.get()],t.increment()})())},fold(e,t){let n=e;for(let e of this.source)n=t(n,e);return n},foldLeft(e){return t=>{let n=a(e);for(let e of this.source)n.set(t(n.get(),e));return n.get()}},foldRight(e){return t=>Array.from(this.source).reduceRight((e,n)=>t(n,e),e)},pipe(e){return e(this)},serialize(){return o(`LazyList`,Array.from(this.source))},toJSON(){return{"@functype":`LazyList`,_tag:`LazyList`,value:Array.from(this.source)}},toString(){let e=[],t=r(0),n=a(!1);for(let r of this.source)if(t.get()<10)e.push(r),t.increment();else{n.set(!0);break}let i=e.map(e=>String(e)).join(`, `);return n.get()?`LazyList(${i}, ...)`:`LazyList(${i})`}}),l=e=>{let t=Object.create(c);return t._tag=`LazyList`,t.source=e,n(t)},u=e(e=>l(e),{empty:()=>l([]),of:(...e)=>l(e),from:(...e)=>l(e),fromJSON:e=>{let t=JSON.parse(e);if(t[`@functype`]!==void 0&&t[`@functype`]!==`LazyList`)throw Error(`LazyList.fromJSON: expected @functype="LazyList", got ${JSON.stringify(t[`@functype`])}`);return l(t.value)},iterate:(e,t)=>l((function*(){let n=a(e);for(;;)yield n.get(),n.set(t(n.get()))})()),generate:e=>l((function*(){for(;;)yield e()})()),range:(e,t,n=1)=>l((function*(){if(n===0)throw Error(`Step cannot be zero`);let r=a(e);if(n>0)for(;r.get()<t;)yield r.get(),r.set(r.get()+n);else for(;r.get()>t;)yield r.get(),r.set(r.get()+n)})()),repeat:(e,t)=>l((function*(){if(t===void 0)for(;;)yield e;else{let n=r(0);for(;n.get()<t;)yield e,n.increment()}})()),cycle:e=>l((function*(){let t=Array.from(e);if(t.length!==0)for(;;)yield*t})())});export{u as LazyList};
@@ -106,7 +106,7 @@ declare const ListConstructor: <A>(values?: Iterable<A>) => List<A>;
106
106
  declare const ListStatics: {
107
107
  /**
108
108
  * Creates an empty List
109
- * Returns one shared instance, whose backing array is frozen
109
+ * Returns one shared instance. It and its backing array are frozen, though other Lists are not
110
110
  * @returns An empty List instance
111
111
  */
112
112
  empty: <A extends Type>() => List<A>;
@@ -1 +1 @@
1
- import{Companion as e}from"../companion/Companion.js";import{Left as t,Right as n}from"../either/index.js";import{base64ToUtf8 as r}from"../internal/base64.js";import{traverseWithConcurrency as i}from"../internal/concurrency.js";import{define as a}from"../internal/define.js";import{safeStringify as o}from"../internal/stringify.js";import{None as s,Option as c}from"../option/index.js";import{createSerializer as l,expectMarker as u}from"../serialization/SerializationCompanion.js";import{Set as d}from"../set/index.js";import{Try as f}from"../try/index.js";import{isTypeable as p}from"../typeable/Typeable.js";import{reduceRightWiden as m,reduceWiden as h}from"../typeclass/variance.js";const g=e=>Array.isArray(e)||typeof e==`object`&&!!e&&Symbol.iterator in e,_=a()(`List`,{[Symbol.toStringTag]:`List`,get size(){return this.value.length},get length(){return this.value.length},get isEmpty(){return this.value.length===0},[Symbol.iterator](){return this.value[Symbol.iterator]()},head(){return this.value[0]},headOption(){return c(this.value[0])},last(){return this.value[this.value.length-1]},lastOption(){return c(this.value[this.value.length-1])},tail(){return v(this.value.slice(1))},init(){return v(this.value.slice(0,-1))},map(e){return v(this.value.map(e))},ap(e){let t=e.toArray();return v(this.value.flatMap(e=>t.map(t=>t(e))))},flatMap(e){return v(this.value.flatMap(t=>Array.from(e(t))))},async flatMapAsync(e,t){let n=await i(this.value,e,t?.concurrency??`unbounded`);return v(n.flatMap(e=>Array.from(e)))},async mapAsync(e,t){return v(await i(this.value,e,t?.concurrency??1))},forEach(e){this.value.forEach(e)},contains(e){return this.value.includes(e)},count(e){return this.value.filter(e).length},exists(e){return this.value.some(e)},every(e){return this.value.every(e)},filter(e){return v(this.value.filter(e))},filterNot(e){return v(this.value.filter(t=>!e(t)))},filterType(e){return v(this.value.filter(t=>p(t,e)))},find(e,t){let n=this.value.find(n=>e(n)&&(!t||p(n,t)));return c(n)},toArray(){return[...this.value]},reduce(e){return h(this.value,e)},reduceRight(e){return m(this.value,e)},fold(e,t){return this.value.reduce(t,e)},foldLeft(e){return t=>this.value.reduce(t,e)},foldRight(e){return t=>this.value.reduceRight((e,n)=>t(n,e),e)},match(e){return this.value.length===0?e.Empty():e.NonEmpty([...this.value])},remove(e){return v(this.value.filter(t=>t!==e))},removeAt(e){return e<0||e>=this.value.length?this:v([...this.value.slice(0,e),...this.value.slice(e+1)])},add(e){return v([...this.value,e])},get(e){return c(this.value[e])},concat(e){return v([...this.value,...e.toArray()])},take(e){return v(this.value.slice(0,Math.max(0,e)))},takeWhile(e){let t=[];for(let n of this.value){if(!e(n))break;t.push(n)}return v(t)},takeRight(e){return v(e>0?this.value.slice(-e):[])},reverse(){return v([...this.value].reverse())},indexOf(e){return this.value.indexOf(e)},prepend(e){return v([e,...this.value])},distinct(){let e=new globalThis.Set,t=[];for(let n of this.value)e.has(n)||(e.add(n),t.push(n));return v(t)},sorted(e){return v([...this.value].sort(e))},sortBy(e,t){return v([...this.value].sort((n,r)=>{let i=e(n),a=e(r);return t?t(i,a):i<a?-1:+(i>a)}))},zip(e){let t=e.toArray(),n=Math.min(this.value.length,t.length),r=[];for(let e=0;e<n;e++)r.push([this.value[e],t[e]]);return v(r)},zipWithIndex(){return v(this.value.map((e,t)=>[e,t]))},groupBy(e){let t=new globalThis.Map;for(let n of this.value){let r=e(n),i=t.get(r)??[];i.push(n),t.set(r,i)}let n=new globalThis.Map;for(let[e,r]of t)n.set(e,v(r));return n},partition(e){let t=[],n=[];for(let r of this.value)e(r)?t.push(r):n.push(r);return[v(t),v(n)]},span(e){let t=this.value.findIndex(t=>!e(t));return t===-1?[this,v([])]:[v(this.value.slice(0,t)),v(this.value.slice(t))]},slice(e,t){return v(this.value.slice(e,t))},drop(e){return v(this.value.slice(Math.max(0,e)))},dropRight(e){return e>0?v(this.value.slice(0,Math.max(0,this.value.length-Math.trunc(e)))):this},dropWhile(e){let t=this.value.findIndex(t=>!e(t));return v(t===-1?[]:this.value.slice(t))},flatten(){return v(this.value.flatMap(e=>g(e)?[...e]:[e]))},toList(){return this},toSet(){return d(this.value)},toOption(){return this.value.length>0?c(this.value[0]):s()},toEither(e){return this.value.length>0?n(this.value[0]):t(e)},toTry(){let e=this.value;return e.length>0?f(()=>e[0]):f(()=>{throw Error(`Empty list`)})},toString(){return`List(${o(this.value)})`},toValue(){return{_tag:`List`,value:[...this.value]}},toJSON(){return{"@functype":`List`,_tag:`List`,value:[...this.value]}},pipe(e){return e([...this.value])},serialize(){return l(`List`,this.value)},doUnwrap(){return this.value.length===0?{ok:!1,empty:!0}:{ok:!0,value:this.value[0]}}}),v=e=>{let t=Object.create(_);return t._tag=`List`,t.value=e,Object.freeze(t)},y=e=>v(Array.from(e??[])),b=v(Object.freeze([])),x=(e,t)=>(u(e,`List`,t),C(e.value??[])),S={empty:()=>b,of:(...e)=>v(e),fromJSON:e=>x(JSON.parse(e),`fromJSON`),fromBinary:e=>{let t=r(e);return S.fromJSON(t)}},C=e(y,S);export{C as List};
1
+ import{Companion as e}from"../companion/Companion.js";import{Left as t,Right as n}from"../either/index.js";import{base64ToUtf8 as r}from"../internal/base64.js";import{traverseWithConcurrency as i}from"../internal/concurrency.js";import{define as a}from"../internal/define.js";import{freezeInDevelopment as o}from"../internal/freeze.js";import{safeStringify as s}from"../internal/stringify.js";import{None as c,Option as l}from"../option/index.js";import{createSerializer as u,expectMarker as d}from"../serialization/SerializationCompanion.js";import{Set as f}from"../set/index.js";import{Try as p}from"../try/index.js";import{isTypeable as m}from"../typeable/Typeable.js";import{reduceRightWiden as h,reduceWiden as g}from"../typeclass/variance.js";const _=e=>Array.isArray(e)||typeof e==`object`&&!!e&&Symbol.iterator in e,v=a()(`List`,{[Symbol.toStringTag]:`List`,get size(){return this.value.length},get length(){return this.value.length},get isEmpty(){return this.value.length===0},[Symbol.iterator](){return this.value[Symbol.iterator]()},head(){return this.value[0]},headOption(){return l(this.value[0])},last(){return this.value[this.value.length-1]},lastOption(){return l(this.value[this.value.length-1])},tail(){return y(this.value.slice(1))},init(){return y(this.value.slice(0,-1))},map(e){return y(this.value.map(e))},ap(e){let t=e.toArray();return y(this.value.flatMap(e=>t.map(t=>t(e))))},flatMap(e){return y(this.value.flatMap(t=>Array.from(e(t))))},async flatMapAsync(e,t){let n=await i(this.value,e,t?.concurrency??`unbounded`);return y(n.flatMap(e=>Array.from(e)))},async mapAsync(e,t){return y(await i(this.value,e,t?.concurrency??1))},forEach(e){this.value.forEach(e)},contains(e){return this.value.includes(e)},count(e){return this.value.filter(e).length},exists(e){return this.value.some(e)},every(e){return this.value.every(e)},filter(e){return y(this.value.filter(e))},filterNot(e){return y(this.value.filter(t=>!e(t)))},filterType(e){return y(this.value.filter(t=>m(t,e)))},find(e,t){let n=this.value.find(n=>e(n)&&(!t||m(n,t)));return l(n)},toArray(){return[...this.value]},reduce(e){return g(this.value,e)},reduceRight(e){return h(this.value,e)},fold(e,t){return this.value.reduce(t,e)},foldLeft(e){return t=>this.value.reduce(t,e)},foldRight(e){return t=>this.value.reduceRight((e,n)=>t(n,e),e)},match(e){return this.value.length===0?e.Empty():e.NonEmpty([...this.value])},remove(e){return y(this.value.filter(t=>t!==e))},removeAt(e){return e<0||e>=this.value.length?this:y([...this.value.slice(0,e),...this.value.slice(e+1)])},add(e){return y([...this.value,e])},get(e){return l(this.value[e])},concat(e){return y([...this.value,...e.toArray()])},take(e){return y(this.value.slice(0,Math.max(0,e)))},takeWhile(e){let t=[];for(let n of this.value){if(!e(n))break;t.push(n)}return y(t)},takeRight(e){return y(e>0?this.value.slice(-e):[])},reverse(){return y([...this.value].reverse())},indexOf(e){return this.value.indexOf(e)},prepend(e){return y([e,...this.value])},distinct(){let e=new globalThis.Set,t=[];for(let n of this.value)e.has(n)||(e.add(n),t.push(n));return y(t)},sorted(e){return y([...this.value].sort(e))},sortBy(e,t){return y([...this.value].sort((n,r)=>{let i=e(n),a=e(r);return t?t(i,a):i<a?-1:+(i>a)}))},zip(e){let t=e.toArray(),n=Math.min(this.value.length,t.length),r=[];for(let e=0;e<n;e++)r.push([this.value[e],t[e]]);return y(r)},zipWithIndex(){return y(this.value.map((e,t)=>[e,t]))},groupBy(e){let t=new globalThis.Map;for(let n of this.value){let r=e(n),i=t.get(r)??[];i.push(n),t.set(r,i)}let n=new globalThis.Map;for(let[e,r]of t)n.set(e,y(r));return n},partition(e){let t=[],n=[];for(let r of this.value)e(r)?t.push(r):n.push(r);return[y(t),y(n)]},span(e){let t=this.value.findIndex(t=>!e(t));return t===-1?[this,y([])]:[y(this.value.slice(0,t)),y(this.value.slice(t))]},slice(e,t){return y(this.value.slice(e,t))},drop(e){return y(this.value.slice(Math.max(0,e)))},dropRight(e){return e>0?y(this.value.slice(0,Math.max(0,this.value.length-Math.trunc(e)))):this},dropWhile(e){let t=this.value.findIndex(t=>!e(t));return y(t===-1?[]:this.value.slice(t))},flatten(){return y(this.value.flatMap(e=>_(e)?[...e]:[e]))},toList(){return this},toSet(){return f(this.value)},toOption(){return this.value.length>0?l(this.value[0]):c()},toEither(e){return this.value.length>0?n(this.value[0]):t(e)},toTry(){let e=this.value;return e.length>0?p(()=>e[0]):p(()=>{throw Error(`Empty list`)})},toString(){return`List(${s(this.value)})`},toValue(){return{_tag:`List`,value:[...this.value]}},toJSON(){return{"@functype":`List`,_tag:`List`,value:[...this.value]}},pipe(e){return e([...this.value])},serialize(){return u(`List`,this.value)},doUnwrap(){return this.value.length===0?{ok:!1,empty:!0}:{ok:!0,value:this.value[0]}}}),y=e=>{let t=Object.create(v);return t._tag=`List`,t.value=e,o(t)},b=e=>y(Array.from(e??[])),x=Object.freeze(y(Object.freeze([]))),S=(e,t)=>(d(e,`List`,t),w(e.value??[])),C={empty:()=>x,of:(...e)=>y(e),fromJSON:e=>S(JSON.parse(e),`fromJSON`),fromBinary:e=>{let t=r(e);return C.fromJSON(t)}},w=e(b,C);export{w as List};
package/dist/map/index.js CHANGED
@@ -1 +1 @@
1
- import{Companion as e}from"../companion/Companion.js";import{base64ToUtf8 as t}from"../internal/base64.js";import{define as n}from"../internal/define.js";import{List as r}from"../list/index.js";import{Option as i}from"../option/index.js";import{createSerializer as a,expectMarker as o}from"../serialization/SerializationCompanion.js";import{Set as s}from"../set/index.js";import{Tuple as c}from"../tuple/index.js";import{ESMap as l}from"./shim.js";const u=e=>Array.from(e,([e,t])=>c([e,t])),d=n()(`Map`,{[Symbol.toStringTag]:`FunctypeMap`,get size(){return this.value.size},get isEmpty(){return this.value.size===0},[Symbol.iterator](){return this.value.entries()},add(e){let[t,n]=e.toArray();return f(new l(this.value).set(t,n))},remove(e){if(!this.value.has(e))return this;let t=new l(this.value);return t.delete(e),f(t)},contains(e){if(!e||typeof e.toArray!=`function`)return!1;let[t,n]=e.toArray();return this.value.get(t)===n},map(e){return f(new l(Array.from(this.value,([t,n])=>[t,e(n)])))},flatMap(e){return f(new l(u(this.value).flatMap(t=>Array.from(e(t)))))},ap(e){let t=[];for(let[n,r]of this.value){let i=e.get(n);i._tag===`Some`&&i.value&&t.push([n,i.value(r)])}return f(new l(t))},async flatMapAsync(e){let t=new l;for(let n of this.value.values()){let r=await e(n);for(let[e,n]of r)t.set(e,n)}return f(t)},reduce(e){return r(u(this.value)).reduce(e)},reduceRight(e){return r(u(this.value)).reduceRight(e)},foldLeft(e){return t=>u(this.value).reduce(t,e)},foldRight(e){return t=>u(this.value).reduceRight((e,n)=>t(n,e),e)},fold(e,t){return u(this.value).reduce(t,e)},match(e){return this.value.size===0?e.Empty():e.NonEmpty(u(this.value))},get(e){return i(this.value.get(e))},has(e){return this.value.has(e)},keys(){return r(this.value.keys())},values(){return r(this.value.values())},getOrElse(e,t){return i(this.value.get(e)).getOrElse(t)},orElse(e,t){return i(this.value.get(e)).orElse(t)},toList(){return r(u(this.value))},toSet(){return s(u(this.value))},toString(){return`Map(${u(this.value).toString()})`},toValue(){return{_tag:`Map`,value:Array.from(this.value.entries())}},toJSON(){return{"@functype":`Map`,_tag:`Map`,value:Array.from(this.value.entries())}},pipe(e){return e(Array.from(this.value.entries()))},serialize(){return a(`Map`,Array.from(this.value.entries()))}}),f=e=>{let t=Object.create(d);return t._tag=`Map`,t.value=e,Object.freeze(t)},p=e=>f(new l(e)),m=(e,t)=>(o(e,`Map`,t),g(e.value??[])),h={empty:()=>f(new l),of:(...e)=>f(new l(e)),fromJSON:e=>m(JSON.parse(e),`fromJSON`),fromBinary:e=>{let n=t(e);return h.fromJSON(n)}},g=e(p,h);export{g as Map};
1
+ import{Companion as e}from"../companion/Companion.js";import{base64ToUtf8 as t}from"../internal/base64.js";import{define as n}from"../internal/define.js";import{freezeInDevelopment as r}from"../internal/freeze.js";import{List as i}from"../list/index.js";import{Option as a}from"../option/index.js";import{createSerializer as o,expectMarker as s}from"../serialization/SerializationCompanion.js";import{Set as c}from"../set/index.js";import{Tuple as l}from"../tuple/index.js";import{ESMap as u}from"./shim.js";const d=e=>Array.from(e,([e,t])=>l([e,t])),f=n()(`Map`,{[Symbol.toStringTag]:`FunctypeMap`,get size(){return this.value.size},get isEmpty(){return this.value.size===0},[Symbol.iterator](){return this.value.entries()},add(e){let[t,n]=e.toArray();return p(new u(this.value).set(t,n))},remove(e){if(!this.value.has(e))return this;let t=new u(this.value);return t.delete(e),p(t)},contains(e){if(!e||typeof e.toArray!=`function`)return!1;let[t,n]=e.toArray();return this.value.get(t)===n},map(e){return p(new u(Array.from(this.value,([t,n])=>[t,e(n)])))},flatMap(e){return p(new u(d(this.value).flatMap(t=>Array.from(e(t)))))},ap(e){let t=[];for(let[n,r]of this.value){let i=e.get(n);i._tag===`Some`&&i.value&&t.push([n,i.value(r)])}return p(new u(t))},async flatMapAsync(e){let t=new u;for(let n of this.value.values()){let r=await e(n);for(let[e,n]of r)t.set(e,n)}return p(t)},reduce(e){return i(d(this.value)).reduce(e)},reduceRight(e){return i(d(this.value)).reduceRight(e)},foldLeft(e){return t=>d(this.value).reduce(t,e)},foldRight(e){return t=>d(this.value).reduceRight((e,n)=>t(n,e),e)},fold(e,t){return d(this.value).reduce(t,e)},match(e){return this.value.size===0?e.Empty():e.NonEmpty(d(this.value))},get(e){return a(this.value.get(e))},has(e){return this.value.has(e)},keys(){return i(this.value.keys())},values(){return i(this.value.values())},getOrElse(e,t){return a(this.value.get(e)).getOrElse(t)},orElse(e,t){return a(this.value.get(e)).orElse(t)},toList(){return i(d(this.value))},toSet(){return c(d(this.value))},toString(){return`Map(${d(this.value).toString()})`},toValue(){return{_tag:`Map`,value:Array.from(this.value.entries())}},toJSON(){return{"@functype":`Map`,_tag:`Map`,value:Array.from(this.value.entries())}},pipe(e){return e(Array.from(this.value.entries()))},serialize(){return o(`Map`,Array.from(this.value.entries()))}}),p=e=>{let t=Object.create(f);return t._tag=`Map`,t.value=e,r(t)},m=e=>p(new u(e)),h=(e,t)=>(s(e,`Map`,t),_(e.value??[])),g={empty:()=>p(new u),of:(...e)=>p(new u(e)),fromJSON:e=>h(JSON.parse(e),`fromJSON`),fromBinary:e=>{let n=t(e);return g.fromJSON(n)}},_=e(m,g);export{_ as Map};
package/dist/obj/Obj.js CHANGED
@@ -1 +1 @@
1
- import{Companion as e}from"../companion/Companion.js";import{base64ToUtf8 as t}from"../internal/base64.js";import{define as n}from"../internal/define.js";import{safeStringify as r}from"../internal/stringify.js";import{Option as i}from"../option/index.js";import{createSerializer as a}from"../serialization/SerializationCompanion.js";import{Tuple as o}from"../tuple/index.js";import{List as s}from"../list/index.js";import{Right as c}from"../either/index.js";import{Try as l}from"../try/index.js";const u=n()(`Obj`,{[Symbol.toStringTag]:`Obj`,get isEmpty(){return Object.keys(this.data).length===0},get size(){return Object.keys(this.data).length},get(e){return i(this.data[e])},set(e,t){return d({...this.data,[e]:t})},assign(e){return d({...this.data,...e})},merge(e){return d({...this.data,...e})},when(e,t){return(typeof e==`function`?e():e)?d({...this.data,...t}):d(this.data)},omit(...e){let t={...this.data};for(let n of e)delete t[n];return d(t)},pick(...e){let t={};for(let n of e)n in this.data&&(t[n]=this.data[n]);return d(t)},keys(){return s(Object.keys(this.data))},values(){return s(Object.values(this.data))},entries(){return s(Object.entries(this.data).map(([e,t])=>o([e,t])))},has(e){return e in this.data},value(){return this.data},map(e){return d(e(this.data))},flatMap(e){return e(this.data)},async flatMapAsync(e){return await e(this.data)},ap(e){let t=e.data;return d(t(this.data))},fold(e,t){return Object.keys(this.data).length===0?e():t(this.data)},match(e){return e.Obj(this.data)},foldLeft(e){return t=>t(e,this.data)},foldRight(e){return t=>t(this.data,e)},count(e){return+!!e(this.data)},find(e){return e(this.data)?i(this.data):i(void 0)},exists(e){return e(this.data)},forEach(e){e(this.data)},reduce(e){return this.data},reduceRight(e){return this.data},contains(e){return JSON.stringify(this.data)===JSON.stringify(e)},getOrElse(){return this.data},orThrow(){return this.data},orElse(e){return d(this.data)},orNull(){return this.data},orUndefined(){return this.data},toOption(){return i(this.data)},toEither(e){return c(this.data)},toList(){return s([this.data])},toTry(){let{data:e}=this;return l(()=>e)},toPromise(){return Promise.resolve(this.data)},toString(){return`Obj(${r(this.data)})`},toValue(){return{_tag:`Obj`,value:this.data}},toJSON(){return{"@functype":`Obj`,_tag:`Obj`,value:this.data}},pipe(e){return e(this.data)},serialize(){return a(`Obj`,this.data)},doUnwrap(){return{ok:!0,value:this.data}}}),d=e=>{let t=Object.create(u);return t._tag=`Obj`,t.data=e,Object.freeze(t)},f=e=>d(e),p={of:e=>d(e),empty:()=>d({}),fromJSON:e=>{let t=JSON.parse(e);if(t[`@functype`]!==void 0&&t[`@functype`]!==`Obj`)throw Error(`Obj.fromJSON: expected @functype="Obj", got ${JSON.stringify(t[`@functype`])}`);return d(t.value)},fromBinary:e=>{let n=t(e);return p.fromJSON(n)}},m=e(f,p);export{m as Obj};
1
+ import{Companion as e}from"../companion/Companion.js";import{base64ToUtf8 as t}from"../internal/base64.js";import{define as n}from"../internal/define.js";import{freezeInDevelopment as r}from"../internal/freeze.js";import{safeStringify as i}from"../internal/stringify.js";import{Option as a}from"../option/index.js";import{createSerializer as o}from"../serialization/SerializationCompanion.js";import{Tuple as s}from"../tuple/index.js";import{List as c}from"../list/index.js";import{Right as l}from"../either/index.js";import{Try as u}from"../try/index.js";const d=n()(`Obj`,{[Symbol.toStringTag]:`Obj`,get isEmpty(){return Object.keys(this.data).length===0},get size(){return Object.keys(this.data).length},get(e){return a(this.data[e])},set(e,t){return f({...this.data,[e]:t})},assign(e){return f({...this.data,...e})},merge(e){return f({...this.data,...e})},when(e,t){return(typeof e==`function`?e():e)?f({...this.data,...t}):f(this.data)},omit(...e){let t={...this.data};for(let n of e)delete t[n];return f(t)},pick(...e){let t={};for(let n of e)n in this.data&&(t[n]=this.data[n]);return f(t)},keys(){return c(Object.keys(this.data))},values(){return c(Object.values(this.data))},entries(){return c(Object.entries(this.data).map(([e,t])=>s([e,t])))},has(e){return e in this.data},value(){return this.data},map(e){return f(e(this.data))},flatMap(e){return e(this.data)},async flatMapAsync(e){return await e(this.data)},ap(e){let t=e.data;return f(t(this.data))},fold(e,t){return Object.keys(this.data).length===0?e():t(this.data)},match(e){return e.Obj(this.data)},foldLeft(e){return t=>t(e,this.data)},foldRight(e){return t=>t(this.data,e)},count(e){return+!!e(this.data)},find(e){return e(this.data)?a(this.data):a(void 0)},exists(e){return e(this.data)},forEach(e){e(this.data)},reduce(e){return this.data},reduceRight(e){return this.data},contains(e){return JSON.stringify(this.data)===JSON.stringify(e)},getOrElse(){return this.data},orThrow(){return this.data},orElse(e){return f(this.data)},orNull(){return this.data},orUndefined(){return this.data},toOption(){return a(this.data)},toEither(e){return l(this.data)},toList(){return c([this.data])},toTry(){let{data:e}=this;return u(()=>e)},toPromise(){return Promise.resolve(this.data)},toString(){return`Obj(${i(this.data)})`},toValue(){return{_tag:`Obj`,value:this.data}},toJSON(){return{"@functype":`Obj`,_tag:`Obj`,value:this.data}},pipe(e){return e(this.data)},serialize(){return o(`Obj`,this.data)},doUnwrap(){return{ok:!0,value:this.data}}}),f=e=>{let t=Object.create(d);return t._tag=`Obj`,t.data=e,r(t)},p=e=>f(e),m={of:e=>f(e),empty:()=>f({}),fromJSON:e=>{let t=JSON.parse(e);if(t[`@functype`]!==void 0&&t[`@functype`]!==`Obj`)throw Error(`Obj.fromJSON: expected @functype="Obj", got ${JSON.stringify(t[`@functype`])}`);return f(t.value)},fromBinary:e=>{let n=t(e);return m.fromJSON(n)}},h=e(p,m);export{h as Obj};
@@ -1 +1 @@
1
- var e=`2.1.0`;export{e as version};
1
+ var e=`2.2.1`;export{e as version};
package/dist/set/index.js CHANGED
@@ -1 +1 @@
1
- import{Companion as e}from"../companion/Companion.js";import{base64ToUtf8 as t}from"../internal/base64.js";import{traverseWithConcurrency as n}from"../internal/concurrency.js";import{define as r}from"../internal/define.js";import{List as i}from"../list/index.js";import{Option as a}from"../option/index.js";import{createSerializer as o,expectMarker as s}from"../serialization/SerializationCompanion.js";import{reduceRightWiden as c,reduceWiden as l}from"../typeclass/variance.js";const u=globalThis.Set,d=r()(`Set`,{[Symbol.toStringTag]:`FunctypeSet`,get size(){return this.value.size},get isEmpty(){return this.value.size===0},[Symbol.iterator](){return this.value[Symbol.iterator]()},head(){return this.value.values().next().value},headOption(){return a(this.value.values().next().value)},last(){return Array.from(this.value).at(-1)},lastOption(){return a(Array.from(this.value).at(-1))},tail(){return f(new u(Array.from(this.value).slice(1)))},init(){return f(new u(Array.from(this.value).slice(0,-1)))},add(e){return f(new u([...this.value,e]))},remove(e){let t=new u(this.value);return t.delete(e),f(t)},contains(e){return this.value.has(e)},has(e){return this.value.has(e)},union(e){return f(new u([...this.value,...e]))},intersection(e){let t=new u(e);return f(new u([...this.value].filter(e=>t.has(e))))},difference(e){let t=new u(e);return f(new u([...this.value].filter(e=>!t.has(e))))},symmetricDifference(e){let t=this.value,n=[...new u(e)],r=new u(n);return f(new u([...[...this.value].filter(e=>!r.has(e)),...n.filter(e=>!t.has(e))]))},isSubsetOf(e){let t=new u(e);return[...this.value].every(e=>t.has(e))},isSupersetOf(e){let t=this.value;for(let n of e)if(!t.has(n))return!1;return!0},isDisjointFrom(e){let t=this.value;for(let n of e)if(t.has(n))return!1;return!0},map(e){return f(new u(Array.from(this.value).map(e)))},ap(e){let t=new u;for(let n of this.value)for(let r of e)t.add(r(n));return f(t)},flatMap(e){let t=new u;for(let n of this.value)for(let r of e(n))t.add(r);return f(t)},async mapAsync(e,t){return f(new u(await n(this.value,e,t?.concurrency??1)))},async flatMapAsync(e,t){let r=await n(this.value,e,t?.concurrency??1);return f(new u(r.flatMap(e=>Array.from(e))))},fold(e,t){let n=e;for(let e of this.value)n=t(n,e);return n},foldLeft(e){return t=>{let n=e;for(let e of this.value)n=t(n,e);return n}},foldRight(e){return t=>Array.from(this.value).reduceRight((e,n)=>t(n,e),e)},reduce(e){let t=Array.from(this.value);if(t.length===0)throw Error(`Cannot reduce empty Set`);return l(t,e)},reduceRight(e){let t=Array.from(this.value);if(t.length===0)throw Error(`Cannot reduceRight empty Set`);return c(t,e)},count(e){let t=0;for(let n of this.value)e(n)&&t++;return t},find(e){for(let t of this.value)if(e(t))return a(t);return a(null)},exists(e){for(let t of this.value)if(e(t))return!0;return!1},every(e){for(let t of this.value)if(!e(t))return!1;return!0},forEach(e){this.value.forEach(e)},filter(e){let t=new u;for(let n of this.value)e(n)&&t.add(n);return f(t)},filterNot(e){let t=new u;for(let n of this.value)e(n)||t.add(n);return f(t)},drop(e){return f(new u(Array.from(this.value).slice(Math.max(0,e))))},dropRight(e){if(!(e>0))return this;let t=Array.from(this.value);return f(new u(t.slice(0,Math.max(0,t.length-Math.trunc(e)))))},dropWhile(e){let t=Array.from(this.value),n=t.findIndex(t=>!e(t));return f(new u(n===-1?[]:t.slice(n)))},flatten(){let e=new u;for(let t of this.value)if(Array.isArray(t))for(let n of t)e.add(n);else if(t&&typeof t==`object`&&Symbol.iterator in t)for(let n of t)e.add(n);else e.add(t);return f(e)},take(e){return f(new u(Array.from(this.value).slice(0,Math.max(0,e))))},takeWhile(e){let t=new u;for(let n of this.value){if(!e(n))break;t.add(n)}return f(t)},takeRight(e){return f(new u(e>0?Array.from(this.value).slice(-e):[]))},toList(){return i(this.value)},toSet(){return this},toArray(){return Array.from(this.value)},toString(){return`Set(${Array.from(this.value).toString()})`},toValue(){return{_tag:`Set`,value:Array.from(this.value)}},toJSON(){return{"@functype":`Set`,_tag:`Set`,value:Array.from(this.value)}},pipe(e){return e(Array.from(this.value))},serialize(){return o(`Set`,Array.from(this.value))}}),f=e=>{let t=Object.create(d);return t._tag=`Set`,t.value=e,Object.freeze(t)},p=e=>f(new u(e)),m=(e,t)=>(s(e,`Set`,t),g(e.value??[])),h={empty:()=>f(new u),of:(...e)=>f(new u(e)),fromJSON:e=>m(JSON.parse(e),`fromJSON`),fromBinary:e=>{let n=t(e);return h.fromJSON(n)}},g=e(p,h);export{g as Set};
1
+ import{Companion as e}from"../companion/Companion.js";import{base64ToUtf8 as t}from"../internal/base64.js";import{traverseWithConcurrency as n}from"../internal/concurrency.js";import{define as r}from"../internal/define.js";import{freezeInDevelopment as i}from"../internal/freeze.js";import{List as a}from"../list/index.js";import{Option as o}from"../option/index.js";import{createSerializer as s,expectMarker as c}from"../serialization/SerializationCompanion.js";import{reduceRightWiden as l,reduceWiden as u}from"../typeclass/variance.js";const d=globalThis.Set,f=r()(`Set`,{[Symbol.toStringTag]:`FunctypeSet`,get size(){return this.value.size},get isEmpty(){return this.value.size===0},[Symbol.iterator](){return this.value[Symbol.iterator]()},head(){return this.value.values().next().value},headOption(){return o(this.value.values().next().value)},last(){return Array.from(this.value).at(-1)},lastOption(){return o(Array.from(this.value).at(-1))},tail(){return p(new d(Array.from(this.value).slice(1)))},init(){return p(new d(Array.from(this.value).slice(0,-1)))},add(e){return p(new d([...this.value,e]))},remove(e){let t=new d(this.value);return t.delete(e),p(t)},contains(e){return this.value.has(e)},has(e){return this.value.has(e)},union(e){return p(new d([...this.value,...e]))},intersection(e){let t=new d(e);return p(new d([...this.value].filter(e=>t.has(e))))},difference(e){let t=new d(e);return p(new d([...this.value].filter(e=>!t.has(e))))},symmetricDifference(e){let t=this.value,n=[...new d(e)],r=new d(n);return p(new d([...[...this.value].filter(e=>!r.has(e)),...n.filter(e=>!t.has(e))]))},isSubsetOf(e){let t=new d(e);return[...this.value].every(e=>t.has(e))},isSupersetOf(e){let t=this.value;for(let n of e)if(!t.has(n))return!1;return!0},isDisjointFrom(e){let t=this.value;for(let n of e)if(t.has(n))return!1;return!0},map(e){return p(new d(Array.from(this.value).map(e)))},ap(e){let t=new d;for(let n of this.value)for(let r of e)t.add(r(n));return p(t)},flatMap(e){let t=new d;for(let n of this.value)for(let r of e(n))t.add(r);return p(t)},async mapAsync(e,t){return p(new d(await n(this.value,e,t?.concurrency??1)))},async flatMapAsync(e,t){let r=await n(this.value,e,t?.concurrency??1);return p(new d(r.flatMap(e=>Array.from(e))))},fold(e,t){let n=e;for(let e of this.value)n=t(n,e);return n},foldLeft(e){return t=>{let n=e;for(let e of this.value)n=t(n,e);return n}},foldRight(e){return t=>Array.from(this.value).reduceRight((e,n)=>t(n,e),e)},reduce(e){let t=Array.from(this.value);if(t.length===0)throw Error(`Cannot reduce empty Set`);return u(t,e)},reduceRight(e){let t=Array.from(this.value);if(t.length===0)throw Error(`Cannot reduceRight empty Set`);return l(t,e)},count(e){let t=0;for(let n of this.value)e(n)&&t++;return t},find(e){for(let t of this.value)if(e(t))return o(t);return o(null)},exists(e){for(let t of this.value)if(e(t))return!0;return!1},every(e){for(let t of this.value)if(!e(t))return!1;return!0},forEach(e){this.value.forEach(e)},filter(e){let t=new d;for(let n of this.value)e(n)&&t.add(n);return p(t)},filterNot(e){let t=new d;for(let n of this.value)e(n)||t.add(n);return p(t)},drop(e){return p(new d(Array.from(this.value).slice(Math.max(0,e))))},dropRight(e){if(!(e>0))return this;let t=Array.from(this.value);return p(new d(t.slice(0,Math.max(0,t.length-Math.trunc(e)))))},dropWhile(e){let t=Array.from(this.value),n=t.findIndex(t=>!e(t));return p(new d(n===-1?[]:t.slice(n)))},flatten(){let e=new d;for(let t of this.value)if(Array.isArray(t))for(let n of t)e.add(n);else if(t&&typeof t==`object`&&Symbol.iterator in t)for(let n of t)e.add(n);else e.add(t);return p(e)},take(e){return p(new d(Array.from(this.value).slice(0,Math.max(0,e))))},takeWhile(e){let t=new d;for(let n of this.value){if(!e(n))break;t.add(n)}return p(t)},takeRight(e){return p(new d(e>0?Array.from(this.value).slice(-e):[]))},toList(){return a(this.value)},toSet(){return this},toArray(){return Array.from(this.value)},toString(){return`Set(${Array.from(this.value).toString()})`},toValue(){return{_tag:`Set`,value:Array.from(this.value)}},toJSON(){return{"@functype":`Set`,_tag:`Set`,value:Array.from(this.value)}},pipe(e){return e(Array.from(this.value))},serialize(){return s(`Set`,Array.from(this.value))}}),p=e=>{let t=Object.create(f);return t._tag=`Set`,t.value=e,i(t)},m=e=>p(new d(e)),h=(e,t)=>(c(e,`Set`,t),_(e.value??[])),g={empty:()=>p(new d),of:(...e)=>p(new d(e)),fromJSON:e=>h(JSON.parse(e),`fromJSON`),fromBinary:e=>{let n=t(e);return g.fromJSON(n)}},_=e(m,g);export{_ as Set};
@@ -1 +1 @@
1
- import{Companion as e}from"../companion/Companion.js";import{base64ToUtf8 as t}from"../internal/base64.js";import{define as n}from"../internal/define.js";import{List as r}from"../list/index.js";import{Option as i}from"../option/index.js";import{createSerializer as a,expectMarker as o}from"../serialization/SerializationCompanion.js";import{reduceRightWiden as s,reduceWiden as c}from"../typeclass/variance.js";const l=n()(`Stack`,{[Symbol.toStringTag]:`Stack`,get size(){return this.value.length},get isEmpty(){return this.value.length===0},contains(e){return this.value.includes(e)},reduce(e){if(this.value.length===0)throw Error(`Cannot reduce an empty stack`);return c(this.value,e)},reduceRight(e){if(this.value.length===0)throw Error(`Cannot reduce an empty stack`);return s(this.value,e)},push(e){return u([...this.value,e])},pop(){return this.value.length===0?[this,i(null)]:[u(this.value.slice(0,-1)),i(this.value[this.value.length-1])]},peek(){return i(this.value[this.value.length-1])},map(e){return u(this.value.map(e))},flatMap(e){return u(this.value.flatMap(t=>e(t).toArray()))},ap(e){let t=e.toArray();return u(this.value.flatMap(e=>t.map(t=>t(e))))},async flatMapAsync(e){let t=await Promise.all(this.value.map(async t=>await e(t)));return u(t.flatMap(e=>e.toArray()))},toList(){return r(this.value)},toArray(){return[...this.value]},toString(){return`Stack(${this.value.join(`, `)})`},fold(e,t){return this.value.reduce(t,e)},foldLeft(e){return t=>this.value.reduce(t,e)},foldRight(e){return t=>this.value.reduceRight((e,n)=>t(n,e),e)},match(e){return this.value.length===0?e.Empty():e.NonEmpty([...this.value])},toValue(){return{_tag:`Stack`,value:[...this.value]}},toJSON(){return{"@functype":`Stack`,_tag:`Stack`,value:[...this.value]}},pipe(e){return e([...this.value])},serialize(){return a(`Stack`,this.value)}}),u=e=>{let t=Object.create(l);return t._tag=`Stack`,t.value=e,Object.freeze(t)},d=(e=[])=>u([...e]),f=(e,t)=>(o(e,`Stack`,t),m(e.value??[])),p={empty:()=>u([]),of:(...e)=>u(e),fromJSON:e=>f(JSON.parse(e),`fromJSON`),fromBinary:e=>{let n=t(e);return p.fromJSON(n)}},m=e(d,p);export{m as Stack};
1
+ import{Companion as e}from"../companion/Companion.js";import{base64ToUtf8 as t}from"../internal/base64.js";import{define as n}from"../internal/define.js";import{freezeInDevelopment as r}from"../internal/freeze.js";import{List as i}from"../list/index.js";import{Option as a}from"../option/index.js";import{createSerializer as o,expectMarker as s}from"../serialization/SerializationCompanion.js";import{reduceRightWiden as c,reduceWiden as l}from"../typeclass/variance.js";const u=n()(`Stack`,{[Symbol.toStringTag]:`Stack`,get size(){return this.value.length},get isEmpty(){return this.value.length===0},contains(e){return this.value.includes(e)},reduce(e){if(this.value.length===0)throw Error(`Cannot reduce an empty stack`);return l(this.value,e)},reduceRight(e){if(this.value.length===0)throw Error(`Cannot reduce an empty stack`);return c(this.value,e)},push(e){return d([...this.value,e])},pop(){return this.value.length===0?[this,a(null)]:[d(this.value.slice(0,-1)),a(this.value[this.value.length-1])]},peek(){return a(this.value[this.value.length-1])},map(e){return d(this.value.map(e))},flatMap(e){return d(this.value.flatMap(t=>e(t).toArray()))},ap(e){let t=e.toArray();return d(this.value.flatMap(e=>t.map(t=>t(e))))},async flatMapAsync(e){let t=await Promise.all(this.value.map(async t=>await e(t)));return d(t.flatMap(e=>e.toArray()))},toList(){return i(this.value)},toArray(){return[...this.value]},toString(){return`Stack(${this.value.join(`, `)})`},fold(e,t){return this.value.reduce(t,e)},foldLeft(e){return t=>this.value.reduce(t,e)},foldRight(e){return t=>this.value.reduceRight((e,n)=>t(n,e),e)},match(e){return this.value.length===0?e.Empty():e.NonEmpty([...this.value])},toValue(){return{_tag:`Stack`,value:[...this.value]}},toJSON(){return{"@functype":`Stack`,_tag:`Stack`,value:[...this.value]}},pipe(e){return e([...this.value])},serialize(){return o(`Stack`,this.value)}}),d=e=>{let t=Object.create(u);return t._tag=`Stack`,t.value=e,r(t)},f=(e=[])=>d([...e]),p=(e,t)=>(s(e,`Stack`,t),h(e.value??[])),m={empty:()=>d([]),of:(...e)=>d(e),fromJSON:e=>p(JSON.parse(e),`fromJSON`),fromBinary:e=>{let n=t(e);return m.fromJSON(n)}},h=e(f,m);export{h as Stack};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functype",
3
- "version": "2.1.0",
3
+ "version": "2.2.1",
4
4
  "type": "module",
5
5
  "description": "A functional programming library for TypeScript, using immutable data structures and type classes",
6
6
  "keywords": [
@@ -34,10 +34,10 @@
34
34
  "@eslint/compat": "^2.1.1",
35
35
  "@eslint/eslintrc": "^3.3.7",
36
36
  "@types/node": "~24.19.2",
37
- "eslint-config-functype": "2.201.0",
37
+ "eslint-config-functype": "2.202.1",
38
38
  "esbuild": "^0.28.2",
39
39
  "eslint-plugin-functional": "^10.0.1",
40
- "fast-check": "^4.10.2",
40
+ "fast-check": "^4.10.3",
41
41
  "globals": "^17.14.0",
42
42
  "ts-builds": "^5.0.0",
43
43
  "tsdown": "^0.23.7",
@@ -58,6 +58,11 @@
58
58
  "import": "./dist/cli/exports.js",
59
59
  "default": "./dist/cli/exports.js"
60
60
  },
61
+ "./core": {
62
+ "types": "./dist/core/exports.d.ts",
63
+ "import": "./dist/core/exports.js",
64
+ "default": "./dist/core/exports.js"
65
+ },
61
66
  "./option": {
62
67
  "types": "./dist/option/index.d.ts",
63
68
  "import": "./dist/option/index.js",