functype 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/dist/core/exports.d.ts +18 -0
- package/dist/core/exports.js +1 -0
- package/dist/internal/freeze.js +1 -0
- package/dist/list/LazyList.js +1 -1
- package/dist/list/index.d.ts +1 -1
- package/dist/list/index.js +1 -1
- package/dist/map/index.js +1 -1
- package/dist/obj/Obj.js +1 -1
- package/dist/package.json.js +1 -1
- package/dist/set/index.js +1 -1
- package/dist/stack/Stack.js +1 -1
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -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).
|
|
@@ -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
|
|
@@ -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};
|
|
@@ -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};
|
package/dist/list/LazyList.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Companion as e}from"../companion/Companion.js";import{define as t}from"../internal/define.js";import{
|
|
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};
|
package/dist/list/index.d.ts
CHANGED
|
@@ -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
|
|
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>;
|
package/dist/list/index.js
CHANGED
|
@@ -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{
|
|
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{
|
|
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{
|
|
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};
|
package/dist/package.json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=`2.
|
|
1
|
+
var e=`2.2.0`;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{
|
|
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};
|
package/dist/stack/Stack.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{
|
|
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.
|
|
3
|
+
"version": "2.2.0",
|
|
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.
|
|
37
|
+
"eslint-config-functype": "2.202.0",
|
|
38
38
|
"esbuild": "^0.28.2",
|
|
39
39
|
"eslint-plugin-functional": "^10.0.1",
|
|
40
|
-
"fast-check": "^4.10.
|
|
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",
|