functype 0.18.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +13 -11
  2. package/README.processed.md +2 -11
  3. package/dist/Brand-B-0nKo7I.d.ts +55 -0
  4. package/dist/Brand-Cfr5zy8F.js +2 -0
  5. package/dist/Brand-Cfr5zy8F.js.map +1 -0
  6. package/dist/Tuple-CKxIyX7l.d.ts +178 -0
  7. package/dist/Tuple-CgX4p79w.js +2 -0
  8. package/dist/Tuple-CgX4p79w.js.map +1 -0
  9. package/dist/branded/index.d.ts +2 -54
  10. package/dist/branded/index.js +1 -0
  11. package/dist/cli/index.d.ts +1 -0
  12. package/dist/cli/index.js +660 -0
  13. package/dist/cli/index.js.map +1 -0
  14. package/dist/do/index.d.ts +4 -240
  15. package/dist/do/index.js +1 -0
  16. package/dist/either/index.d.ts +4 -2
  17. package/dist/either/index.js +1 -0
  18. package/dist/fpromise/index.d.ts +4 -373
  19. package/dist/fpromise/index.js +1 -0
  20. package/dist/index-Bnjlo4cT.d.ts +3575 -0
  21. package/dist/index.d.ts +4 -1934
  22. package/dist/index.js +1 -0
  23. package/dist/list/index.d.ts +4 -2
  24. package/dist/list/index.js +1 -0
  25. package/dist/map/index.d.ts +4 -58
  26. package/dist/map/index.js +1 -0
  27. package/dist/option/index.d.ts +4 -2
  28. package/dist/option/index.js +1 -0
  29. package/dist/set/index.d.ts +4 -2
  30. package/dist/set/index.js +1 -0
  31. package/dist/src-BOxI0-73.js +20 -0
  32. package/dist/src-BOxI0-73.js.map +1 -0
  33. package/dist/try/index.d.ts +4 -2
  34. package/dist/try/index.js +1 -0
  35. package/dist/tuple/index.d.ts +2 -75
  36. package/dist/tuple/index.js +1 -0
  37. package/package.json +31 -42
  38. package/dist/Either-Ccg0S1uS.d.ts +0 -1015
  39. package/dist/Typeable-DiGVtDnq.d.ts +0 -96
  40. package/dist/branded/index.mjs +0 -2
  41. package/dist/branded/index.mjs.map +0 -1
  42. package/dist/chunk-6ZIR6EKC.mjs +0 -38
  43. package/dist/chunk-6ZIR6EKC.mjs.map +0 -1
  44. package/dist/chunk-7JJIUQXK.mjs +0 -3
  45. package/dist/chunk-7JJIUQXK.mjs.map +0 -1
  46. package/dist/chunk-OR6V4TCO.mjs +0 -2
  47. package/dist/chunk-OR6V4TCO.mjs.map +0 -1
  48. package/dist/do/index.mjs +0 -2
  49. package/dist/do/index.mjs.map +0 -1
  50. package/dist/either/index.mjs +0 -2
  51. package/dist/either/index.mjs.map +0 -1
  52. package/dist/fpromise/index.mjs +0 -2
  53. package/dist/fpromise/index.mjs.map +0 -1
  54. package/dist/index.mjs +0 -2
  55. package/dist/index.mjs.map +0 -1
  56. package/dist/list/index.mjs +0 -2
  57. package/dist/list/index.mjs.map +0 -1
  58. package/dist/map/index.mjs +0 -2
  59. package/dist/map/index.mjs.map +0 -1
  60. package/dist/option/index.mjs +0 -2
  61. package/dist/option/index.mjs.map +0 -1
  62. package/dist/set/index.mjs +0 -2
  63. package/dist/set/index.mjs.map +0 -1
  64. package/dist/try/index.mjs +0 -2
  65. package/dist/try/index.mjs.map +0 -1
  66. package/dist/tuple/index.mjs +0 -2
  67. package/dist/tuple/index.mjs.map +0 -1
package/README.md CHANGED
@@ -9,6 +9,17 @@ Functype is a lightweight functional programming library for TypeScript, drawing
9
9
 
10
10
  [API Documentation](https://jordanburke.github.io/functype/)
11
11
 
12
+ ### CLI Documentation
13
+
14
+ Get LLM-optimized API reference directly in your terminal:
15
+
16
+ ```bash
17
+ npx functype # Overview of all types
18
+ npx functype Option # Detailed info for Option type
19
+ npx functype interfaces # All interface definitions
20
+ npx functype --json # JSON output for programmatic use
21
+ ```
22
+
12
23
  ## Core Principles
13
24
 
14
25
  - **Immutability**: All data structures are immutable, promoting predictable and side-effect-free code
@@ -597,12 +608,7 @@ All data structures implement the `Functype` hierarchy:
597
608
  ```typescript
598
609
  // Base interface for all data structures
599
610
  interface FunctypeBase<A, Tag>
600
- extends AsyncMonad<A>,
601
- Traversable<A>,
602
- Serializable<A>,
603
- Foldable<A>,
604
- Typeable<Tag>,
605
- ContainerOps<A> {
611
+ extends AsyncMonad<A>, Traversable<A>, Serializable<A>, Foldable<A>, Typeable<Tag>, ContainerOps<A> {
606
612
  readonly _tag: Tag
607
613
  }
608
614
 
@@ -613,11 +619,7 @@ interface Functype<A, Tag> extends FunctypeBase<A, Tag>, Extractable<A>, Pipe<A>
613
619
 
614
620
  // For collections (List, Set, Map)
615
621
  interface FunctypeCollection<A, Tag>
616
- extends FunctypeBase<A, Tag>,
617
- Iterable<A>,
618
- Pipe<A[]>,
619
- Collection<A>,
620
- CollectionOps<A, FunctypeCollection<A, Tag>> {
622
+ extends FunctypeBase<A, Tag>, Iterable<A>, Pipe<A[]>, Collection<A>, CollectionOps<A, FunctypeCollection<A, Tag>> {
621
623
  toValue(): { _tag: Tag; value: A[] }
622
624
  // Collections work with Iterable instead of Monad
623
625
  flatMap<B>(f: (value: A) => Iterable<B>): FunctypeCollection<B, Tag>
@@ -639,12 +639,7 @@ All data structures implement the `Functype` hierarchy:
639
639
  ```typescript
640
640
  // Base interface for all data structures
641
641
  interface FunctypeBase<A, Tag>
642
- extends AsyncMonad<A>,
643
- Traversable<A>,
644
- Serializable<A>,
645
- Foldable<A>,
646
- Typeable<Tag>,
647
- ContainerOps<A> {
642
+ extends AsyncMonad<A>, Traversable<A>, Serializable<A>, Foldable<A>, Typeable<Tag>, ContainerOps<A> {
648
643
  readonly _tag: Tag
649
644
  }
650
645
 
@@ -655,11 +650,7 @@ interface Functype<A, Tag> extends FunctypeBase<A, Tag>, Extractable<A>, Pipe<A>
655
650
 
656
651
  // For collections (List, Set, Map)
657
652
  interface FunctypeCollection<A, Tag>
658
- extends FunctypeBase<A, Tag>,
659
- Iterable<A>,
660
- Pipe<A[]>,
661
- Collection<A>,
662
- CollectionOps<A, FunctypeCollection<A, Tag>> {
653
+ extends FunctypeBase<A, Tag>, Iterable<A>, Pipe<A[]>, Collection<A>, CollectionOps<A, FunctypeCollection<A, Tag>> {
663
654
  toValue(): { _tag: Tag; value: A[] }
664
655
  // Collections work with Iterable instead of Monad
665
656
  flatMap<B>(f: (value: A) => Iterable<B>): FunctypeCollection<B, Tag>
@@ -0,0 +1,55 @@
1
+ //#region src/branded/Brand.d.ts
2
+ type Brand<K$1 extends string, T> = T & {
3
+ readonly __brand: K$1;
4
+ };
5
+ type Unwrap<T> = T extends Brand<string, infer U> ? U : T;
6
+ type ExtractBrand<T> = T extends Brand<infer K, unknown> ? K : never;
7
+ /**
8
+ * Brand is a utility for creating nominal typing in TypeScript.
9
+ * It creates phantom types that exist only at compile time.
10
+ * At runtime, the branded value IS the primitive value.
11
+ *
12
+ * @param _brand
13
+ * @param value - The value to brand
14
+ * @returns The value with phantom type brand
15
+ */
16
+ declare function Brand<K$1 extends string, T>(_brand: K$1, value: T): Brand<K$1, T>;
17
+ /**
18
+ * Helper to unwrap a branded value to its underlying type
19
+ * Works with both Brand and ValidatedBrand
20
+ * @param branded - The branded value (can be null or undefined)
21
+ * @returns The original value without the brand
22
+ *
23
+ * Note: Also exported as 'unwrap' from 'functype/branded' for convenience
24
+ */
25
+ declare function unwrapBrand<K$1 extends string, T>(branded: Brand<K$1, T>): T;
26
+ declare function unwrapBrand<K$1 extends string, T>(branded: Brand<K$1, T> | null): T | null;
27
+ declare function unwrapBrand<K$1 extends string, T>(branded: Brand<K$1, T> | undefined): T | undefined;
28
+ declare function unwrapBrand<K$1 extends string, T>(branded: Brand<K$1, T> | null | undefined): T | null | undefined;
29
+ /**
30
+ * Type guard for checking if a value has a specific brand
31
+ * @param value - The value to check
32
+ * @param _brand - The brand to check for (unused at runtime)
33
+ * @returns True if the value has the specified brand
34
+ *
35
+ * Note: Since brands are phantom types that exist only at compile time,
36
+ * this function can only provide a runtime approximation. It always returns true
37
+ * for non-null values, as we have no way to actually check the brand at runtime.
38
+ * This function is primarily for API consistency and documentation purposes.
39
+ */
40
+ declare function hasBrand<K$1 extends string, T>(value: unknown, _brand: K$1): value is Brand<K$1, T>;
41
+ /**
42
+ * Create a branded type constructor for a specific brand
43
+ * @param brand - The brand name
44
+ * @returns A function that brands values with the specified brand
45
+ */
46
+ declare function createBrander<K$1 extends string, T>(brand: K$1): (value: T) => Brand<K$1, T>;
47
+ type BrandedString<K$1 extends string> = Brand<K$1, string>;
48
+ type BrandedNumber<K$1 extends string> = Brand<K$1, number>;
49
+ type BrandedBoolean<K$1 extends string> = Brand<K$1, boolean>;
50
+ declare const BrandedString: <K$1 extends string>(brand: K$1) => (value: string) => BrandedString<K$1>;
51
+ declare const BrandedNumber: <K$1 extends string>(brand: K$1) => (value: number) => BrandedNumber<K$1>;
52
+ declare const BrandedBoolean: <K$1 extends string>(brand: K$1) => (value: boolean) => BrandedBoolean<K$1>;
53
+ //#endregion
54
+ export { ExtractBrand as a, hasBrand as c, BrandedString as i, unwrapBrand as l, BrandedBoolean as n, Unwrap as o, BrandedNumber as r, createBrander as s, Brand as t };
55
+ //# sourceMappingURL=Brand-B-0nKo7I.d.ts.map
@@ -0,0 +1,2 @@
1
+ function e(e,t){return t}function t(e){return e??e}function n(e,t){return e!=null}function r(t){return n=>e(t,n)}const i=t=>n=>e(t,n),a=t=>n=>e(t,n),o=t=>n=>e(t,n);export{r as a,i,o as n,n as o,a as r,t as s,e as t};
2
+ //# sourceMappingURL=Brand-Cfr5zy8F.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Brand-Cfr5zy8F.js","names":[],"sources":["../src/branded/Brand.ts"],"sourcesContent":["// Phantom type brand - exists only at compile time\n// Must use type alias (not interface) because we need intersection with primitives\nexport type Brand<K extends string, T> = T & {\n readonly __brand: K\n}\n\n// Utility type to extract the underlying type from a branded type\n// Handles both Brand and ValidatedBrand\nexport type Unwrap<T> = T extends Brand<string, infer U> ? U : T\n\n// Utility type to extract the brand from a branded type\nexport type ExtractBrand<T> = T extends Brand<infer K, unknown> ? K : never\n\n/**\n * Brand is a utility for creating nominal typing in TypeScript.\n * It creates phantom types that exist only at compile time.\n * At runtime, the branded value IS the primitive value.\n *\n * @param _brand\n * @param value - The value to brand\n * @returns The value with phantom type brand\n */\nexport function Brand<K extends string, T>(_brand: K, value: T): Brand<K, T> {\n // Just return the value with a type assertion\n // No runtime modification - the brand exists only in TypeScript\n return value as Brand<K, T>\n}\n\n/**\n * Helper to unwrap a branded value to its underlying type\n * Works with both Brand and ValidatedBrand\n * @param branded - The branded value (can be null or undefined)\n * @returns The original value without the brand\n *\n * Note: Also exported as 'unwrap' from 'functype/branded' for convenience\n */\nexport function unwrapBrand<K extends string, T>(branded: Brand<K, T>): T\nexport function unwrapBrand<K extends string, T>(branded: Brand<K, T> | null): T | null\nexport function unwrapBrand<K extends string, T>(branded: Brand<K, T> | undefined): T | undefined\nexport function unwrapBrand<K extends string, T>(branded: Brand<K, T> | null | undefined): T | null | undefined\nexport function unwrapBrand<K extends string, T>(branded: Brand<K, T> | null | undefined): T | null | undefined {\n // Handle null/undefined\n if (branded === null || branded === undefined) {\n return branded\n }\n // Since branded values (both Brand and ValidatedBrand) ARE their primitives, just return as-is\n return branded as unknown as T\n}\n\n// Convenience alias for branded module users\nexport { unwrapBrand as unwrap }\n\n/**\n * Type guard for checking if a value has a specific brand\n * @param value - The value to check\n * @param _brand - The brand to check for (unused at runtime)\n * @returns True if the value has the specified brand\n *\n * Note: Since brands are phantom types that exist only at compile time,\n * this function can only provide a runtime approximation. It always returns true\n * for non-null values, as we have no way to actually check the brand at runtime.\n * This function is primarily for API consistency and documentation purposes.\n */\nexport function hasBrand<K extends string, T>(value: unknown, _brand: K): value is Brand<K, T> {\n // In a phantom type system, we can't actually check the brand at runtime\n // We can only verify the value exists\n return value !== null && value !== undefined\n}\n\n/**\n * Create a branded type constructor for a specific brand\n * @param brand - The brand name\n * @returns A function that brands values with the specified brand\n */\nexport function createBrander<K extends string, T>(brand: K) {\n return (value: T): Brand<K, T> => Brand(brand, value)\n}\n\n// Common branded primitive types\nexport type BrandedString<K extends string> = Brand<K, string>\nexport type BrandedNumber<K extends string> = Brand<K, number>\nexport type BrandedBoolean<K extends string> = Brand<K, boolean>\n\n// Factory for common primitive branded types\nexport const BrandedString =\n <K extends string>(brand: K) =>\n (value: string): BrandedString<K> =>\n Brand(brand, value)\n\nexport const BrandedNumber =\n <K extends string>(brand: K) =>\n (value: number): BrandedNumber<K> =>\n Brand(brand, value)\n\nexport const BrandedBoolean =\n <K extends string>(brand: K) =>\n (value: boolean): BrandedBoolean<K> =>\n Brand(brand, value)\n"],"mappings":"AAsBA,SAAgB,EAA2B,EAAW,EAAuB,CAG3E,OAAO,EAeT,SAAgB,EAAiC,EAA+D,CAM9G,OAJI,GACK,EAoBX,SAAgB,EAA8B,EAAgB,EAAiC,CAG7F,OAAO,GAAU,KAQnB,SAAgB,EAAmC,EAAU,CAC3D,MAAQ,IAA0B,EAAM,EAAO,EAAM,CASvD,MAAa,EACQ,GAClB,GACC,EAAM,EAAO,EAAM,CAEV,EACQ,GAClB,GACC,EAAM,EAAO,EAAM,CAEV,EACQ,GAClB,GACC,EAAM,EAAO,EAAM"}
@@ -0,0 +1,178 @@
1
+ //#region src/types/index.d.ts
2
+ type Type = unknown;
3
+ //#endregion
4
+ //#region src/foldable/Foldable.d.ts
5
+ /**
6
+ * Foldable type class represents data structures that can be folded to a summary value.
7
+ *
8
+ * @typeParam A - The type of elements in the data structure
9
+ */
10
+ interface Foldable<A> {
11
+ /**
12
+ * Pattern matches over the structure, applying specific handlers for each variant
13
+ * @param onEmpty - Function to apply if the structure is empty or has no value
14
+ * @param onValue - Function to apply if the structure has a value
15
+ * @returns The result of applying the appropriate function
16
+ */
17
+ fold<B>(onEmpty: () => B, onValue: (value: A) => B): B;
18
+ /**
19
+ * Left-associative fold using the provided zero value and operation
20
+ * @param z - Zero/identity value
21
+ * @returns A function that takes an operation to apply
22
+ */
23
+ foldLeft<B>(z: B): (op: (b: B, a: A) => B) => B;
24
+ /**
25
+ * Right-associative fold using the provided zero value and operation
26
+ * @param z - Zero/identity value
27
+ * @returns A function that takes an operation to apply
28
+ */
29
+ foldRight<B>(z: B): (op: (a: A, b: B) => B) => B;
30
+ }
31
+ //#endregion
32
+ //#region src/pipe/index.d.ts
33
+ /**
34
+ * Pipe interface for functional data structures
35
+ * @typeParam T - The type of value to pipe
36
+ */
37
+ interface Pipe<T extends Type> {
38
+ /**
39
+ * Pipes the value through the provided function
40
+ * @param f - The function to apply to the value
41
+ * @returns The result of applying the function to the value
42
+ * @typeParam U - The return type of the function
43
+ */
44
+ pipe<U extends Type>(f: (value: T) => U): U;
45
+ }
46
+ //#endregion
47
+ //#region src/serializable/Serializable.d.ts
48
+ /**
49
+ * Methods for different serialization formats
50
+ */
51
+ interface SerializationMethods<T> {
52
+ toJSON(): string;
53
+ toYAML(): string;
54
+ toBinary(): string;
55
+ }
56
+ interface Serializable<T> {
57
+ serialize(): SerializationMethods<T>;
58
+ }
59
+ //#endregion
60
+ //#region src/typeable/Typeable.d.ts
61
+ /**
62
+ * Base interface for objects with a type tag
63
+ * @internal
64
+ */
65
+ interface TypeableBase<Tag$1 extends string> {
66
+ readonly _tag: Tag$1;
67
+ }
68
+ type Typeable<Tag$1 extends string, T = object> = T & TypeableBase<Tag$1>;
69
+ /**
70
+ * Parameters for creating a Typeable instance
71
+ * @internal
72
+ */
73
+ type TypeableParams<Tag$1 extends string, T> = {
74
+ _tag: Tag$1;
75
+ impl: T;
76
+ };
77
+ /**
78
+ * Utility type to extract the Tag from a Typeable type
79
+ * @typeParam T - The Typeable type to extract the tag from
80
+ * @internal
81
+ */
82
+ type ExtractTag<T> = T extends Typeable<infer Tag, unknown> ? Tag : never;
83
+ /**
84
+ * Core utility for creating nominal typing in TypeScript by adding a type tag to any object.
85
+ * This allows for creating distinct types that are structurally identical but considered different by TypeScript's type system.
86
+ *
87
+ * @param params - The parameters containing the tag and implementation
88
+ * @returns A Typeable object with the specified tag
89
+ * @typeParam Tag - The string literal type used as the discriminator
90
+ * @typeParam T - The base type to extend with the tag
91
+ */
92
+ declare function Typeable<Tag$1 extends string, T>({
93
+ _tag,
94
+ impl
95
+ }: TypeableParams<Tag$1, T>): Typeable<Tag$1, T>;
96
+ /**
97
+ * Type guard with automatic type inference using the full type
98
+ * @param value - The value to check
99
+ * @param tag - The tag to check for
100
+ * @returns Whether the value is a Typeable with the specified tag
101
+ */
102
+ declare function isTypeable<T>(value: unknown, tag: string): value is T;
103
+ //#endregion
104
+ //#region src/tuple/Tuple.d.ts
105
+ interface Tuple<T extends Type[]> extends Foldable<T[number]>, Pipe<Tuple<T>>, Serializable<Tuple<T>>, Typeable<"Tuple"> {
106
+ get<K extends number>(index: K): T[K];
107
+ map<U extends Type[]>(f: (value: T) => U): Tuple<U>;
108
+ flatMap<U extends Type[]>(f: (value: T) => Tuple<U>): Tuple<U>;
109
+ toArray(): T;
110
+ length: number;
111
+ [Symbol.iterator](): Iterator<T[number]>;
112
+ toString(): string;
113
+ toValue(): {
114
+ _tag: "Tuple";
115
+ value: T;
116
+ };
117
+ }
118
+ /**
119
+ * Tuple provides a type-safe, fixed-length array with functional operations.
120
+ *
121
+ * @example
122
+ * // Creating tuples
123
+ * const t1 = Tuple([1, "hello", true])
124
+ * const t2 = Tuple.of(1, "hello", true)
125
+ * const pair = Tuple.pair("key", 42)
126
+ *
127
+ * @example
128
+ * // Type-safe access
129
+ * const triple = Tuple.triple("x", 10, true)
130
+ * const first = triple.get(0) // string
131
+ * const second = triple.get(1) // number
132
+ * const third = triple.get(2) // boolean
133
+ *
134
+ * @example
135
+ * // Functional operations
136
+ * const doubled = Tuple([1, 2, 3])
137
+ * .map(arr => arr.map(x => x * 2))
138
+ * .toArray() // [2, 4, 6]
139
+ */
140
+ declare const Tuple: (<T extends Type[]>(values: T) => Tuple<T>) & {
141
+ /**
142
+ * Create a Tuple from multiple arguments
143
+ * @example
144
+ * const t = Tuple.of(1, "hello", true)
145
+ * // TypeScript infers: Tuple<[number, string, boolean]>
146
+ */
147
+ of: <T extends Type[]>(...values: T) => Tuple<T>;
148
+ /**
149
+ * Create a Tuple of size 2 (pair)
150
+ * @example
151
+ * const pair = Tuple.pair("key", 42)
152
+ * // TypeScript infers: Tuple<[string, number]>
153
+ */
154
+ pair: <A extends Type, B extends Type>(first: A, second: B) => Tuple<[A, B]>;
155
+ /**
156
+ * Create a Tuple of size 3 (triple)
157
+ * @example
158
+ * const triple = Tuple.triple("x", 10, true)
159
+ * // TypeScript infers: Tuple<[string, number, boolean]>
160
+ */
161
+ triple: <A extends Type, B extends Type, C extends Type>(first: A, second: B, third: C) => Tuple<[A, B, C]>;
162
+ /**
163
+ * Create an empty Tuple
164
+ * @example
165
+ * const empty = Tuple.empty()
166
+ * // TypeScript infers: Tuple<[]>
167
+ */
168
+ empty: () => Tuple<[]>;
169
+ /**
170
+ * Create a Tuple from an array (alias for constructor)
171
+ * @example
172
+ * const t = Tuple.from([1, 2, 3])
173
+ */
174
+ from: <T extends Type[]>(values: T) => Tuple<T>;
175
+ };
176
+ //#endregion
177
+ export { isTypeable as a, Pipe as c, TypeableParams as i, Foldable as l, ExtractTag as n, Serializable as o, Typeable as r, SerializationMethods as s, Tuple as t, Type as u };
178
+ //# sourceMappingURL=Tuple-CKxIyX7l.d.ts.map
@@ -0,0 +1,2 @@
1
+ import e from"safe-stable-stringify";function t(e,t){return Object.assign(e,t)}const n=t=>{let n={_tag:`Tuple`,map:e=>r(e(t)),flatMap:e=>e(t),get:e=>t[e],toArray:()=>t,length:t.length,[Symbol.iterator](){let e=0;return{next:()=>e<t.length?{value:t[e++],done:!1}:{value:void 0,done:!0}}},fold:(e,n)=>t.length===0?e():n(t[0]),foldLeft:e=>n=>t.reduce(n,e),foldRight:e=>n=>t.reduceRight((e,t)=>n(t,e),e),pipe:e=>e(n),serialize:()=>({toJSON:()=>JSON.stringify({_tag:`Tuple`,value:t}),toYAML:()=>`_tag: Tuple\nvalue: ${e(t)}`,toBinary:()=>Buffer.from(JSON.stringify({_tag:`Tuple`,value:t})).toString(`base64`)}),toValue:()=>({_tag:`Tuple`,value:t}),toString:()=>`Tuple(${t.map(e=>String(e)).join(`, `)})`};return n},r=t(e=>n(e),{of:(...e)=>n(e),pair:(e,t)=>n([e,t]),triple:(e,t,r)=>n([e,t,r]),empty:()=>n([]),from:e=>n(e)});export{t as n,r as t};
2
+ //# sourceMappingURL=Tuple-CgX4p79w.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tuple-CgX4p79w.js","names":["tuple: Tuple<T>"],"sources":["../src/companion/Companion.ts","../src/tuple/Tuple.ts"],"sourcesContent":["/**\n * Creates a function-object hybrid similar to Scala's companion objects.\n * This utility allows creating TypeScript function objects with attached methods,\n * mimicking Scala's class + companion object pattern without using classes.\n *\n * @param object The main function that will be invoked when the object is called\n * @param companion Additional static methods to attach to the function\n * @returns A function with the attached methods\n *\n * @example\n * const greet = (name: string) => `Hello, ${name}!`;\n * const methods = {\n * formal: (name: string) => `Good day, ${name}.`,\n * casual: (name: string) => `Hey ${name}!`\n * };\n * const Greeter = createCompanionObject(greet, methods);\n *\n * // Usage:\n * Greeter(\"World\"); // Hello, World!\n * Greeter.formal(\"Sir\"); // Good day, Sir.\n * Greeter.casual(\"Friend\"); // Hey Friend!\n */\nexport function Companion<ObjectF extends object, CompanionF extends object>(\n object: ObjectF,\n companion: CompanionF,\n): ObjectF & CompanionF {\n // eslint-disable-next-line functional/immutable-data\n return Object.assign(object, companion)\n}\n","import stringify from \"safe-stable-stringify\"\n\nimport { Companion } from \"@/companion/Companion\"\nimport type { Foldable } from \"@/foldable/Foldable\"\nimport type { Pipe } from \"@/pipe\"\nimport type { Serializable } from \"@/serializable/Serializable\"\nimport type { Typeable } from \"@/typeable/Typeable\"\nimport type { Type } from \"@/types\"\n\nexport interface Tuple<T extends Type[]>\n extends Foldable<T[number]>, Pipe<Tuple<T>>, Serializable<Tuple<T>>, Typeable<\"Tuple\"> {\n get<K extends number>(index: K): T[K]\n\n map<U extends Type[]>(f: (value: T) => U): Tuple<U>\n\n flatMap<U extends Type[]>(f: (value: T) => Tuple<U>): Tuple<U>\n\n toArray(): T\n\n length: number\n\n [Symbol.iterator](): Iterator<T[number]>\n\n toString(): string\n\n toValue(): { _tag: \"Tuple\"; value: T }\n}\n\nconst TupleObject = <T extends Type[]>(values: T): Tuple<T> => {\n const tuple: Tuple<T> = {\n _tag: \"Tuple\",\n map: <U extends Type[]>(f: (value: T) => U): Tuple<U> => {\n const mapValue = f(values)\n return Tuple(mapValue)\n },\n\n flatMap: <U extends Type[]>(f: (value: T) => Tuple<U>): Tuple<U> => {\n return f(values)\n },\n\n get: <K extends number>(index: K): T[K] => {\n return values[index]\n },\n\n toArray: (): T => {\n return values\n },\n\n length: values.length,\n\n [Symbol.iterator](): Iterator<T[number]> {\n let index = 0\n return {\n next: (): IteratorResult<T[number]> => {\n if (index < values.length) {\n return {\n value: values[index++],\n done: false,\n }\n } else {\n return {\n value: undefined,\n done: true,\n }\n }\n },\n }\n },\n\n // Foldable implementation\n fold: <B>(onEmpty: () => B, onValue: (value: T[number]) => B): B => {\n return values.length === 0 ? onEmpty() : onValue(values[0]!)\n },\n\n foldLeft:\n <B>(z: B) =>\n (op: (b: B, a: T[number]) => B) => {\n return values.reduce(op, z)\n },\n\n foldRight:\n <B>(z: B) =>\n (op: (a: T[number], b: B) => B): B => {\n return values.reduceRight<B>((acc, value) => op(value, acc), z)\n },\n\n // Pipe implementation\n pipe: <U>(f: (value: Tuple<T>) => U): U => f(tuple),\n\n // Serializable implementation\n serialize: () => {\n return {\n toJSON: () => JSON.stringify({ _tag: \"Tuple\", value: values }),\n toYAML: () => `_tag: Tuple\\nvalue: ${stringify(values)}`,\n toBinary: () => Buffer.from(JSON.stringify({ _tag: \"Tuple\", value: values })).toString(\"base64\"),\n }\n },\n\n // Valuable implementation\n toValue: () => ({ _tag: \"Tuple\", value: values }),\n\n toString: () => `Tuple(${values.map((v) => String(v)).join(\", \")})`,\n }\n\n return tuple\n}\n\nconst TupleConstructor = <T extends Type[]>(values: T): Tuple<T> => {\n return TupleObject(values)\n}\n\nconst TupleCompanion = {\n /**\n * Create a Tuple from multiple arguments\n * @example\n * const t = Tuple.of(1, \"hello\", true)\n * // TypeScript infers: Tuple<[number, string, boolean]>\n */\n of: <T extends Type[]>(...values: T): Tuple<T> => {\n return TupleObject(values)\n },\n\n /**\n * Create a Tuple of size 2 (pair)\n * @example\n * const pair = Tuple.pair(\"key\", 42)\n * // TypeScript infers: Tuple<[string, number]>\n */\n pair: <A extends Type, B extends Type>(first: A, second: B): Tuple<[A, B]> => {\n return TupleObject([first, second] as [A, B])\n },\n\n /**\n * Create a Tuple of size 3 (triple)\n * @example\n * const triple = Tuple.triple(\"x\", 10, true)\n * // TypeScript infers: Tuple<[string, number, boolean]>\n */\n triple: <A extends Type, B extends Type, C extends Type>(first: A, second: B, third: C): Tuple<[A, B, C]> => {\n return TupleObject([first, second, third] as [A, B, C])\n },\n\n /**\n * Create an empty Tuple\n * @example\n * const empty = Tuple.empty()\n * // TypeScript infers: Tuple<[]>\n */\n empty: (): Tuple<[]> => {\n return TupleObject([] as [])\n },\n\n /**\n * Create a Tuple from an array (alias for constructor)\n * @example\n * const t = Tuple.from([1, 2, 3])\n */\n from: <T extends Type[]>(values: T): Tuple<T> => {\n return TupleObject(values)\n },\n}\n\n/**\n * Tuple provides a type-safe, fixed-length array with functional operations.\n *\n * @example\n * // Creating tuples\n * const t1 = Tuple([1, \"hello\", true])\n * const t2 = Tuple.of(1, \"hello\", true)\n * const pair = Tuple.pair(\"key\", 42)\n *\n * @example\n * // Type-safe access\n * const triple = Tuple.triple(\"x\", 10, true)\n * const first = triple.get(0) // string\n * const second = triple.get(1) // number\n * const third = triple.get(2) // boolean\n *\n * @example\n * // Functional operations\n * const doubled = Tuple([1, 2, 3])\n * .map(arr => arr.map(x => x * 2))\n * .toArray() // [2, 4, 6]\n */\nexport const Tuple = Companion(TupleConstructor, TupleCompanion)\n"],"mappings":"qCAsBA,SAAgB,EACd,EACA,EACsB,CAEtB,OAAO,OAAO,OAAO,EAAQ,EAAU,CCCzC,MAAM,EAAiC,GAAwB,CAC7D,IAAMA,EAAkB,CACtB,KAAM,QACN,IAAwB,GAEf,EADU,EAAE,EAAO,CACJ,CAGxB,QAA4B,GACnB,EAAE,EAAO,CAGlB,IAAwB,GACf,EAAO,GAGhB,YACS,EAGT,OAAQ,EAAO,OAEf,CAAC,OAAO,WAAiC,CACvC,IAAI,EAAQ,EACZ,MAAO,CACL,SACM,EAAQ,EAAO,OACV,CACL,MAAO,EAAO,KACd,KAAM,GACP,CAEM,CACL,MAAO,IAAA,GACP,KAAM,GACP,CAGN,EAIH,MAAU,EAAkB,IACnB,EAAO,SAAW,EAAI,GAAS,CAAG,EAAQ,EAAO,GAAI,CAG9D,SACM,GACH,GACQ,EAAO,OAAO,EAAI,EAAE,CAG/B,UACM,GACH,GACQ,EAAO,aAAgB,EAAK,IAAU,EAAG,EAAO,EAAI,CAAE,EAAE,CAInE,KAAU,GAAiC,EAAE,EAAM,CAGnD,eACS,CACL,WAAc,KAAK,UAAU,CAAE,KAAM,QAAS,MAAO,EAAQ,CAAC,CAC9D,WAAc,uBAAuB,EAAU,EAAO,GACtD,aAAgB,OAAO,KAAK,KAAK,UAAU,CAAE,KAAM,QAAS,MAAO,EAAQ,CAAC,CAAC,CAAC,SAAS,SAAS,CACjG,EAIH,aAAgB,CAAE,KAAM,QAAS,MAAO,EAAQ,EAEhD,aAAgB,SAAS,EAAO,IAAK,GAAM,OAAO,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,GAClE,CAED,OAAO,GAgFI,EAAQ,EA7EuB,GACnC,EAAY,EAAO,CAGL,CAOrB,IAAuB,GAAG,IACjB,EAAY,EAAO,CAS5B,MAAuC,EAAU,IACxC,EAAY,CAAC,EAAO,EAAO,CAAW,CAS/C,QAAyD,EAAU,EAAW,IACrE,EAAY,CAAC,EAAO,EAAQ,EAAM,CAAc,CASzD,UACS,EAAY,EAAE,CAAO,CAQ9B,KAAyB,GAChB,EAAY,EAAO,CAE7B,CAwB+D"}
@@ -1,54 +1,2 @@
1
- type Unwrap<T> = T extends Brand<string, infer U> ? U : T;
2
- type ExtractBrand<T> = T extends Brand<infer K, unknown> ? K : never;
3
- type Brand<K extends string, T> = T & {
4
- readonly __brand: K;
5
- };
6
- /**
7
- * Brand is a utility for creating nominal typing in TypeScript.
8
- * It creates phantom types that exist only at compile time.
9
- * At runtime, the branded value IS the primitive value.
10
- *
11
- * @param _brand
12
- * @param value - The value to brand
13
- * @returns The value with phantom type brand
14
- */
15
- declare function Brand<K extends string, T>(_brand: K, value: T): Brand<K, T>;
16
- /**
17
- * Helper to unwrap a branded value to its underlying type
18
- * Works with both Brand and ValidatedBrand
19
- * @param branded - The branded value (can be null or undefined)
20
- * @returns The original value without the brand
21
- *
22
- * Note: Also exported as 'unwrap' from 'functype/branded' for convenience
23
- */
24
- declare function unwrapBrand<K extends string, T>(branded: Brand<K, T>): T;
25
- declare function unwrapBrand<K extends string, T>(branded: Brand<K, T> | null): T | null;
26
- declare function unwrapBrand<K extends string, T>(branded: Brand<K, T> | undefined): T | undefined;
27
- declare function unwrapBrand<K extends string, T>(branded: Brand<K, T> | null | undefined): T | null | undefined;
28
-
29
- /**
30
- * Type guard for checking if a value has a specific brand
31
- * @param value - The value to check
32
- * @param _brand - The brand to check for (unused at runtime)
33
- * @returns True if the value has the specified brand
34
- *
35
- * Note: Since brands are phantom types that exist only at compile time,
36
- * this function can only provide a runtime approximation. It always returns true
37
- * for non-null values, as we have no way to actually check the brand at runtime.
38
- * This function is primarily for API consistency and documentation purposes.
39
- */
40
- declare function hasBrand<K extends string, T>(value: unknown, _brand: K): value is Brand<K, T>;
41
- /**
42
- * Create a branded type constructor for a specific brand
43
- * @param brand - The brand name
44
- * @returns A function that brands values with the specified brand
45
- */
46
- declare function createBrander<K extends string, T>(brand: K): (value: T) => Brand<K, T>;
47
- type BrandedString<K extends string> = Brand<K, string>;
48
- declare const BrandedString: <K extends string>(brand: K) => (value: string) => BrandedString<K>;
49
- type BrandedNumber<K extends string> = Brand<K, number>;
50
- declare const BrandedNumber: <K extends string>(brand: K) => (value: number) => BrandedNumber<K>;
51
- type BrandedBoolean<K extends string> = Brand<K, boolean>;
52
- declare const BrandedBoolean: <K extends string>(brand: K) => (value: boolean) => BrandedBoolean<K>;
53
-
54
- export { Brand, BrandedBoolean, BrandedNumber, BrandedString, type ExtractBrand, type Unwrap, createBrander, hasBrand, unwrapBrand as unwrap, unwrapBrand };
1
+ import { a as ExtractBrand, c as hasBrand, i as BrandedString, l as unwrapBrand, n as BrandedBoolean, o as Unwrap, r as BrandedNumber, s as createBrander, t as Brand } from "../Brand-B-0nKo7I.js";
2
+ export { Brand, BrandedBoolean, BrandedNumber, BrandedString, ExtractBrand, Unwrap, createBrander, hasBrand, unwrapBrand as unwrap, unwrapBrand };
@@ -0,0 +1 @@
1
+ import{a as e,i as t,n,o as r,r as i,s as a,t as o}from"../Brand-Cfr5zy8F.js";export{o as Brand,n as BrandedBoolean,i as BrandedNumber,t as BrandedString,e as createBrander,r as hasBrand,a as unwrap,a as unwrapBrand};
@@ -0,0 +1 @@
1
+ export { };