functype 0.8.80 → 0.8.82

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.
@@ -1,107 +1,4 @@
1
- import { T as Type, F as Functor, a as Typeable, V as Valuable, A as AsyncFunctor, E as ExtractTag } from './Valuable-BI2O7E9Q.js';
2
-
3
- /**
4
- * Foldable type class represents data structures that can be folded to a summary value.
5
- *
6
- * @typeParam A - The type of elements in the data structure
7
- */
8
- type Foldable<A> = {
9
- /**
10
- * Pattern matches over the structure, applying specific handlers for each variant
11
- * @param onEmpty - Function to apply if the structure is empty or has no value
12
- * @param onValue - Function to apply if the structure has a value
13
- * @returns The result of applying the appropriate function
14
- */
15
- fold<B>(onEmpty: () => B, onValue: (value: A) => B): B;
16
- /**
17
- * Left-associative fold using the provided zero value and operation
18
- * @param z - Zero/identity value
19
- * @returns A function that takes an operation to apply
20
- */
21
- foldLeft<B>(z: B): (op: (b: B, a: A) => B) => B;
22
- /**
23
- * Right-associative fold using the provided zero value and operation
24
- * @param z - Zero/identity value
25
- * @returns A function that takes an operation to apply
26
- */
27
- foldRight<B>(z: B): (op: (a: A, b: B) => B) => B;
28
- };
29
-
30
- /**
31
- * Pattern matching interface for functional data types.
32
- *
33
- * @typeParam A - The type of elements in the data structure
34
- * @typeParam Tags - The type of tags used for pattern matching
35
- */
36
- type Matchable<A, Tags extends string = string> = {
37
- /**
38
- * Pattern matches against this data structure, applying handlers for each variant based on tag.
39
- * Similar to fold but with stronger type safety for tag-based variants.
40
- *
41
- * The return type is inferred from the pattern handlers when not explicitly specified.
42
- *
43
- * @param patterns - An object containing handler functions for each variant
44
- * @returns The result of applying the matching handler function
45
- */
46
- match<R>(patterns: Record<Tags, (value: A) => R>): R;
47
- };
48
- /**
49
- * Utility functions for working with Matchable data structures
50
- */
51
- declare const MatchableUtils: {
52
- /**
53
- * Helper function to create a default case for pattern matching
54
- *
55
- * @param handler - The default handler function to apply
56
- * @returns A function that always applies the default handler
57
- */
58
- default: <A, R>(handler: (value: A) => R) => (value: A) => R;
59
- /**
60
- * Helper function to create a match pattern that guards based on a predicate
61
- *
62
- * @param predicate - The predicate function for guarding
63
- * @param handler - The handler function to apply if the predicate passes
64
- * @returns A function that applies the handler only if the predicate passes
65
- */
66
- when: <A, R>(predicate: (value: A) => boolean, handler: (value: A) => R) => (value: A) => R | undefined;
67
- };
68
-
69
- /**
70
- * Pipe interface for functional data structures
71
- * @typeParam T - The type of value to pipe
72
- */
73
- type Pipe<T extends Type> = {
74
- /**
75
- * Pipes the value through the provided function
76
- * @param f - The function to apply to the value
77
- * @returns The result of applying the function to the value
78
- * @typeParam U - The return type of the function
79
- */
80
- pipe<U extends Type>(f: (value: T) => U): U;
81
- };
82
-
83
- /**
84
- * Methods for different serialization formats
85
- */
86
- type SerializationMethods<T> = {
87
- toJSON(): string;
88
- toYAML(): string;
89
- toBinary(): string;
90
- };
91
- type Serializable<T> = {
92
- serialize(): SerializationMethods<T>;
93
- };
94
-
95
- /**
96
- * Traversable typeclass for data structures that can be traversed through
97
- */
98
- type Traversable<A extends Type> = Functor<A> & {
99
- get size(): number;
100
- get isEmpty(): boolean;
101
- contains(value: A): boolean;
102
- reduce(f: (b: A, a: A) => A): A;
103
- reduceRight(f: (b: A, a: A) => A): A;
104
- };
1
+ import { T as Type, a as Typeable } from './Typeable-BBXrKPTY.js';
105
2
 
106
3
  /**
107
4
  * Creates a Some variant of Option containing a value.
@@ -134,9 +31,7 @@ declare const OptionConstructor: <T extends Type>(value: T | null | undefined) =
134
31
  * It's used to handle potentially null or undefined values in a type-safe way.
135
32
  * @typeParam T - The type of the value contained in the Option
136
33
  */
137
- type Option<T extends Type> = {
138
- /** Tag identifying if this is a Some or None variant */
139
- readonly _tag: "Some" | "None";
34
+ interface Option<T extends Type> extends Functype<T, "Some" | "None"> {
140
35
  /** The contained value (undefined for None) */
141
36
  readonly value: T | undefined;
142
37
  /** Whether this Option contains no value */
@@ -182,6 +77,12 @@ type Option<T extends Type> = {
182
77
  * @returns A new Option containing the mapped value, or None if this Option is None
183
78
  */
184
79
  map<U extends Type>(f: (value: T) => U): Option<U>;
80
+ /**
81
+ * Applies a wrapped function to a wrapped value (Applicative pattern)
82
+ * @param ff - An Option containing a function from T to U
83
+ * @returns A new Option containing the result of applying the function
84
+ */
85
+ ap<U extends Type>(ff: Option<(value: T) => U>): Option<U>;
185
86
  /**
186
87
  * Returns this Option if it contains a value that satisfies the predicate, otherwise returns None
187
88
  * @param predicate - The predicate function to test the value
@@ -272,7 +173,7 @@ type Option<T extends Type> = {
272
173
  Some: (value: T) => R;
273
174
  None: () => R;
274
175
  }): R;
275
- } & (Traversable<T> & Functor<T> & Typeable<"Some" | "None"> & Valuable<"Some" | "None", T> & AsyncFunctor<T> & Serializable<T> & Pipe<T> & Foldable<T> & Matchable<T, "Some" | "None">);
176
+ }
276
177
  declare const Option: (<T extends Type>(value: T | null | undefined) => Option<T>) & {
277
178
  /**
278
179
  * Creates an Option from any value. Alias for Option function.
@@ -307,120 +208,22 @@ declare const Option: (<T extends Type>(value: T | null | undefined) => Option<T
307
208
  fromBinary: <T>(binary: string) => Option<T>;
308
209
  };
309
210
 
310
- type IterableType<A extends Type> = {
311
- count(p: (x: A) => boolean): number;
312
- find(p: (a: A) => boolean): Option<A>;
313
- forEach(f: (a: A) => void): void;
314
- drop(n: number): IterableType<A>;
315
- dropRight(n: number): IterableType<A>;
316
- dropWhile(p: (a: A) => boolean): IterableType<A>;
317
- exists(p: (a: A) => boolean): boolean;
318
- filter(p: (a: A) => boolean): IterableType<A>;
319
- filterNot(p: (a: A) => boolean): IterableType<A>;
320
- flatten<B>(): IterableType<B>;
321
- reduce(f: (b: A, a: A) => A): A;
322
- reduceRight(f: (b: A, a: A) => A): A;
323
- foldLeft<B>(z: B): (op: (b: B, a: A) => B) => B;
324
- foldRight<B>(z: B): (op: (a: A, b: B) => B) => B;
325
- get head(): A | undefined;
326
- get headOption(): Option<A>;
327
- get isEmpty(): boolean;
328
- map<B extends Type>(f: (a: A) => B): IterableType<B>;
329
- flatMap<B extends Type>(f: (a: A) => IterableType<B>): IterableType<B>;
330
- get size(): number;
331
- toArray<B = A>(): readonly B[];
332
- } & Iterable<A> & Functor<A> & AsyncFunctor<A> & Traversable<A>;
333
-
334
- /**
335
- * Defines conversion methods for collection types
336
- * @interface
337
- * @module Collections
338
- * @category Core
339
- */
340
- type Converters<A> = {
341
- toList(): List<A>;
342
- toSet(): Set<A>;
343
- toString(): string;
344
- };
345
- /**
346
- * Represents a collection with conversion capabilities
347
- * @interface
348
- * @module Collections
349
- * @category Core
350
- */
351
- type Collection<A> = Converters<A>;
352
-
353
- type Set<A> = {
354
- add: (value: A) => Set<A>;
355
- remove: (value: A) => Set<A>;
356
- contains: (value: A) => boolean;
357
- has: (value: A) => boolean;
358
- map: <B>(f: (a: A) => B) => Set<B>;
359
- flatMap: <B>(f: (a: A) => IterableType<B>) => Set<B>;
360
- fold: <U extends Type>(onEmpty: () => U, onValue: (value: A) => U) => U;
361
- toList: () => List<A>;
362
- toSet: () => Set<A>;
363
- toString: () => string;
364
- } & IterableType<A> & Collection<A> & Typeable<"Set"> & Valuable<"Set", A[]> & Serializable<A[]> & Pipe<A[]> & Foldable<A>;
365
- declare const Set: (<A>(iterable?: Iterable<A> | IterableType<A>) => Set<A>) & {
366
- /**
367
- * Creates a Set from JSON string
368
- * @param json - The JSON string
369
- * @returns Set instance
370
- */
371
- fromJSON: <A>(json: string) => Set<A>;
372
- /**
373
- * Creates a Set from YAML string
374
- * @param yaml - The YAML string
375
- * @returns Set instance
376
- */
377
- fromYAML: <A>(yaml: string) => Set<A>;
378
- /**
379
- * Creates a Set from binary string
380
- * @param binary - The binary string
381
- * @returns Set instance
382
- */
383
- fromBinary: <A>(binary: string) => Set<A>;
384
- };
385
-
386
- type List<A> = {
211
+ interface List<A> extends FunctypeCollection<A, "List"> {
387
212
  readonly length: number;
388
213
  readonly [Symbol.iterator]: () => Iterator<A>;
389
214
  map: <B>(f: (a: A) => B) => List<B>;
390
- flatMap: <B>(f: (a: A) => IterableType<B>) => List<B>;
391
- flatMapAsync: <B>(f: (a: A) => PromiseLike<IterableType<B>>) => PromiseLike<List<B>>;
392
- forEach: (f: (a: A) => void) => void;
393
- count: (p: (x: A) => boolean) => number;
394
- exists: (p: (a: A) => boolean) => boolean;
215
+ ap: <B>(ff: List<(value: A) => B>) => List<B>;
216
+ flatMap: <B>(f: (a: A) => Iterable<B>) => List<B>;
217
+ flatMapAsync: <B>(f: (a: A) => PromiseLike<Iterable<B>>) => PromiseLike<List<B>>;
395
218
  filter<S extends A>(predicate: (a: A) => a is S): List<S>;
396
219
  filter(predicate: (a: A) => unknown): List<A>;
397
220
  filterNot: (p: (a: A) => boolean) => List<A>;
398
221
  filterType: <T extends Typeable<string, unknown>>(tag: string) => List<T & A>;
399
- find: <T extends A = A>(predicate: (a: A) => boolean, tag?: ExtractTag<T>) => Option<T>;
400
- readonly head: A | undefined;
401
- readonly headOption: Option<A>;
402
- readonly isEmpty: boolean;
403
- toArray: <B = A>() => B[];
404
- reduce: (f: (prev: A, curr: A) => A) => A;
405
- reduceRight: (f: (prev: A, curr: A) => A) => A;
406
- foldLeft: <B>(z: B) => (op: (b: B, a: A) => B) => B;
407
- foldRight: <B>(z: B) => (op: (a: A, b: B) => B) => B;
408
222
  remove: (value: A) => List<A>;
409
223
  removeAt: (index: number) => List<A>;
410
224
  add: (item: A) => List<A>;
411
225
  get: (index: number) => Option<A>;
412
226
  concat: (other: List<A>) => List<A>;
413
- toList: () => List<A>;
414
- toSet: () => Set<A>;
415
- toString: () => string;
416
- toValue: () => {
417
- _tag: "List";
418
- value: A[];
419
- };
420
- drop: (n: number) => List<A>;
421
- dropRight: (n: number) => List<A>;
422
- dropWhile: (p: (a: A) => boolean) => List<A>;
423
- flatten: <B>() => List<B>;
424
227
  /**
425
228
  * Pattern matches over the List, applying a handler function based on whether it's empty
426
229
  * @param patterns - Object with handler functions for Empty and NonEmpty variants
@@ -430,7 +233,7 @@ type List<A> = {
430
233
  Empty: () => R;
431
234
  NonEmpty: (values: A[]) => R;
432
235
  }): R;
433
- } & IterableType<A> & AsyncFunctor<A> & Typeable<"List"> & Serializable<A> & Pipe<A[]> & Foldable<A> & Matchable<A[], "Empty" | "NonEmpty">;
236
+ }
434
237
  declare const List: (<A>(values?: Iterable<A>) => List<A>) & {
435
238
  /**
436
239
  * Creates a List from JSON string
@@ -452,7 +255,361 @@ declare const List: (<A>(values?: Iterable<A>) => List<A>) & {
452
255
  fromBinary: <A>(binary: string) => List<A>;
453
256
  };
454
257
 
455
- type TestEither<L extends Type, R extends Type> = Either<L, R> & Functor<R> & AsyncFunctor<R>;
258
+ interface Set<A> extends FunctypeCollection<A, "Set">, Collection<A> {
259
+ add: (value: A) => Set<A>;
260
+ remove: (value: A) => Set<A>;
261
+ contains: (value: A) => boolean;
262
+ has: (value: A) => boolean;
263
+ map: <B>(f: (a: A) => B) => Set<B>;
264
+ flatMap: <B>(f: (a: A) => Iterable<B>) => Set<B>;
265
+ filter: (p: (a: A) => boolean) => Set<A>;
266
+ filterNot: (p: (a: A) => boolean) => Set<A>;
267
+ fold: <U extends Type>(onEmpty: () => U, onValue: (value: A) => U) => U;
268
+ toList: () => List<A>;
269
+ toSet: () => Set<A>;
270
+ toArray: <B = A>() => readonly B[];
271
+ toString: () => string;
272
+ }
273
+ declare const Set: (<A>(iterable?: Iterable<A>) => Set<A>) & {
274
+ /**
275
+ * Creates a Set from JSON string
276
+ * @param json - The JSON string
277
+ * @returns Set instance
278
+ */
279
+ fromJSON: <A>(json: string) => Set<A>;
280
+ /**
281
+ * Creates a Set from YAML string
282
+ * @param yaml - The YAML string
283
+ * @returns Set instance
284
+ */
285
+ fromYAML: <A>(yaml: string) => Set<A>;
286
+ /**
287
+ * Creates a Set from binary string
288
+ * @param binary - The binary string
289
+ * @returns Set instance
290
+ */
291
+ fromBinary: <A>(binary: string) => Set<A>;
292
+ };
293
+
294
+ /**
295
+ * Represents a collection with conversion capabilities
296
+ * @interface
297
+ * @module Collections
298
+ * @category Core
299
+ */
300
+ interface Collection<A> {
301
+ toList(): List<A>;
302
+ toSet(): Set<A>;
303
+ toString(): string;
304
+ }
305
+
306
+ /**
307
+ * Extractable type class for data structures that can extract their values
308
+ * with various fallback strategies.
309
+ *
310
+ * This interface is implemented by Option, Either, and other types that
311
+ * wrap values and need safe extraction methods.
312
+ */
313
+ interface Extractable<T extends Type> {
314
+ /**
315
+ * Extracts the value unsafely
316
+ * @throws Error if the container is empty
317
+ * @returns The contained value
318
+ */
319
+ get(): T;
320
+ /**
321
+ * Returns the contained value or a default value
322
+ * @param defaultValue - The value to return if extraction fails
323
+ * @returns The contained value or defaultValue
324
+ */
325
+ getOrElse(defaultValue: T): T;
326
+ /**
327
+ * Returns the contained value or throws an error
328
+ * @param error - Optional error to throw (implementations may have defaults)
329
+ * @returns The contained value
330
+ * @throws The specified error if extraction fails
331
+ */
332
+ getOrThrow(error?: Error): T;
333
+ /**
334
+ * Returns this container if it has a value, otherwise returns the alternative
335
+ * @param alternative - The alternative container
336
+ * @returns This container or the alternative
337
+ */
338
+ orElse(alternative: Extractable<T>): Extractable<T>;
339
+ /**
340
+ * Returns the contained value or null
341
+ * @returns The contained value or null
342
+ */
343
+ orNull(): T | null;
344
+ /**
345
+ * Returns the contained value or undefined
346
+ * @returns The contained value or undefined
347
+ */
348
+ orUndefined(): T | undefined;
349
+ }
350
+
351
+ /**
352
+ * Foldable type class represents data structures that can be folded to a summary value.
353
+ *
354
+ * @typeParam A - The type of elements in the data structure
355
+ */
356
+ interface Foldable<A> {
357
+ /**
358
+ * Pattern matches over the structure, applying specific handlers for each variant
359
+ * @param onEmpty - Function to apply if the structure is empty or has no value
360
+ * @param onValue - Function to apply if the structure has a value
361
+ * @returns The result of applying the appropriate function
362
+ */
363
+ fold<B>(onEmpty: () => B, onValue: (value: A) => B): B;
364
+ /**
365
+ * Left-associative fold using the provided zero value and operation
366
+ * @param z - Zero/identity value
367
+ * @returns A function that takes an operation to apply
368
+ */
369
+ foldLeft<B>(z: B): (op: (b: B, a: A) => B) => B;
370
+ /**
371
+ * Right-associative fold using the provided zero value and operation
372
+ * @param z - Zero/identity value
373
+ * @returns A function that takes an operation to apply
374
+ */
375
+ foldRight<B>(z: B): (op: (a: A, b: B) => B) => B;
376
+ }
377
+
378
+ /**
379
+ * Pattern matching interface for functional data types.
380
+ *
381
+ * @typeParam A - The type of elements in the data structure
382
+ * @typeParam Tags - The type of tags used for pattern matching
383
+ */
384
+ interface Matchable<A, Tags extends string = string> {
385
+ /**
386
+ * Pattern matches against this data structure, applying handlers for each variant based on tag.
387
+ * Similar to fold but with stronger type safety for tag-based variants.
388
+ *
389
+ * The return type is inferred from the pattern handlers when not explicitly specified.
390
+ *
391
+ * @param patterns - An object containing handler functions for each variant
392
+ * @returns The result of applying the matching handler function
393
+ */
394
+ match<R>(patterns: Record<Tags, (value: A) => R>): R;
395
+ }
396
+ /**
397
+ * Utility functions for working with Matchable data structures
398
+ */
399
+ declare const MatchableUtils: {
400
+ /**
401
+ * Helper function to create a default case for pattern matching
402
+ *
403
+ * @param handler - The default handler function to apply
404
+ * @returns A function that always applies the default handler
405
+ */
406
+ default: <A, R>(handler: (value: A) => R) => (value: A) => R;
407
+ /**
408
+ * Helper function to create a match pattern that guards based on a predicate
409
+ *
410
+ * @param predicate - The predicate function for guarding
411
+ * @param handler - The handler function to apply if the predicate passes
412
+ * @returns A function that applies the handler only if the predicate passes
413
+ */
414
+ when: <A, R>(predicate: (value: A) => boolean, handler: (value: A) => R) => (value: A) => R | undefined;
415
+ };
416
+
417
+ /**
418
+ * Pipe interface for functional data structures
419
+ * @typeParam T - The type of value to pipe
420
+ */
421
+ interface Pipe<T extends Type> {
422
+ /**
423
+ * Pipes the value through the provided function
424
+ * @param f - The function to apply to the value
425
+ * @returns The result of applying the function to the value
426
+ * @typeParam U - The return type of the function
427
+ */
428
+ pipe<U extends Type>(f: (value: T) => U): U;
429
+ }
430
+
431
+ /**
432
+ * Methods for different serialization formats
433
+ */
434
+ interface SerializationMethods<T> {
435
+ toJSON(): string;
436
+ toYAML(): string;
437
+ toBinary(): string;
438
+ }
439
+ interface Serializable<T> {
440
+ serialize(): SerializationMethods<T>;
441
+ }
442
+
443
+ /**
444
+ * Universal operations that work on any container (single-value or collection).
445
+ * These operations make sense for Option, Either, Try, List, Set, etc.
446
+ *
447
+ * @typeParam A - The type of value(s) in the container
448
+ */
449
+ interface ContainerOps<A extends Type> {
450
+ /**
451
+ * Counts elements that satisfy the predicate.
452
+ * For single-value containers: returns 0 or 1
453
+ * For collections: returns the count of matching elements
454
+ */
455
+ count(p: (x: A) => boolean): number;
456
+ /**
457
+ * Finds the first element that satisfies the predicate.
458
+ * For single-value containers: returns Some(value) if predicate matches, None otherwise
459
+ * For collections: returns the first matching element wrapped in Option
460
+ */
461
+ find(p: (a: A) => boolean): Option<A>;
462
+ /**
463
+ * Tests whether any element satisfies the predicate.
464
+ * For single-value containers: tests the single value
465
+ * For collections: returns true if any element matches
466
+ */
467
+ exists(p: (a: A) => boolean): boolean;
468
+ /**
469
+ * Applies an effect function to each element.
470
+ * For single-value containers: applies to the value if present
471
+ * For collections: applies to each element
472
+ */
473
+ forEach(f: (a: A) => void): void;
474
+ }
475
+ /**
476
+ * Operations specific to collections (List, Set, etc.).
477
+ * These operations don't make sense for single-value containers.
478
+ *
479
+ * @typeParam A - The element type
480
+ * @typeParam Self - The collection type itself for proper return types
481
+ */
482
+ interface CollectionOps<A extends Type, Self> {
483
+ /**
484
+ * Drops the first n elements from the collection.
485
+ */
486
+ drop(n: number): Self;
487
+ /**
488
+ * Drops the last n elements from the collection.
489
+ */
490
+ dropRight(n: number): Self;
491
+ /**
492
+ * Drops elements from the start while the predicate is true.
493
+ */
494
+ dropWhile(p: (a: A) => boolean): Self;
495
+ /**
496
+ * Flattens a collection of collections into a single collection.
497
+ */
498
+ flatten<B>(): Self;
499
+ /**
500
+ * Gets the first element of the collection.
501
+ */
502
+ get head(): A | undefined;
503
+ /**
504
+ * Gets the first element wrapped in Option.
505
+ */
506
+ get headOption(): Option<A>;
507
+ /**
508
+ * Converts the collection to an array.
509
+ */
510
+ toArray<B = A>(): readonly B[];
511
+ }
512
+
513
+ /**
514
+ * Functor type class - supports mapping over wrapped values
515
+ *
516
+ * Laws:
517
+ * - Identity: fa.map(x => x) ≡ fa
518
+ * - Composition: fa.map(f).map(g) ≡ fa.map(x => g(f(x)))
519
+ */
520
+ interface Functor<A extends Type> {
521
+ map<B extends Type>(f: (value: A) => B): Functor<B>;
522
+ }
523
+ /**
524
+ * Applicative functor - supports applying wrapped functions to wrapped values
525
+ *
526
+ * Laws:
527
+ * - Identity: pure(x => x).ap(v) ≡ v
528
+ * - Composition: pure(compose).ap(u).ap(v).ap(w) ≡ u.ap(v.ap(w))
529
+ * - Homomorphism: pure(f).ap(pure(x)) ≡ pure(f(x))
530
+ * - Interchange: u.ap(pure(y)) ≡ pure(f => f(y)).ap(u)
531
+ */
532
+ interface Applicative<A extends Type> extends Functor<A> {
533
+ ap<B extends Type>(ff: Applicative<(value: A) => B>): Applicative<B>;
534
+ }
535
+ /**
536
+ * Monad type class - supports flat mapping (chaining) operations
537
+ *
538
+ * Laws:
539
+ * - Left identity: pure(a).flatMap(f) ≡ f(a)
540
+ * - Right identity: m.flatMap(pure) ≡ m
541
+ * - Associativity: m.flatMap(f).flatMap(g) ≡ m.flatMap(x => f(x).flatMap(g))
542
+ */
543
+ interface Monad<A extends Type> extends Applicative<A> {
544
+ flatMap<B extends Type>(f: (value: A) => Monad<B>): Monad<B>;
545
+ }
546
+ /**
547
+ * Async monad - supports asynchronous monadic operations
548
+ * Extends Monad so it has map, ap, and flatMap in addition to flatMapAsync
549
+ */
550
+ interface AsyncMonad<A extends Type> extends Monad<A> {
551
+ flatMapAsync<B extends Type>(f: (value: A) => PromiseLike<AsyncMonad<B>>): PromiseLike<AsyncMonad<B>>;
552
+ }
553
+
554
+ /**
555
+ * Traversable typeclass for data structures that can be traversed through
556
+ */
557
+ interface Traversable<A extends Type> extends AsyncMonad<A> {
558
+ get size(): number;
559
+ get isEmpty(): boolean;
560
+ contains(value: A): boolean;
561
+ reduce(f: (b: A, a: A) => A): A;
562
+ reduceRight(f: (b: A, a: A) => A): A;
563
+ }
564
+
565
+ /**
566
+ * Base interface for all functype data structures.
567
+ * This provides a standard contract with core functional programming traits.
568
+ *
569
+ * @typeParam A - The type of value contained in the functor
570
+ * @typeParam Tag - The type tag for pattern matching (e.g., "Some" | "None" for Option)
571
+ *
572
+ * @example
573
+ * ```typescript
574
+ * // Implementing FunctypeBase for a custom data structure
575
+ * class MyContainer<T> implements FunctypeBase<T, "Empty" | "Full"> {
576
+ * // Implementation of all required methods...
577
+ * }
578
+ * ```
579
+ */
580
+ interface FunctypeBase<A, Tag extends string = string> extends AsyncMonad<A>, Traversable<A>, Serializable<A>, Foldable<A>, Typeable<Tag>, ContainerOps<A> {
581
+ readonly _tag: Tag;
582
+ }
583
+ /**
584
+ * Interface for single-value containers like Option, Either, Try.
585
+ * Extends FunctypeBase with extraction methods and Pipe.
586
+ *
587
+ * @typeParam A - The type of value contained
588
+ * @typeParam Tag - The type tag for pattern matching
589
+ */
590
+ interface Functype<A, Tag extends string = string> extends FunctypeBase<A, Tag>, Extractable<A>, Pipe<A>, Matchable<A, Tag> {
591
+ toValue(): {
592
+ _tag: Tag;
593
+ value: A;
594
+ };
595
+ }
596
+ /**
597
+ * A version of Functype for collection types that need iteration support.
598
+ * Extends FunctypeBase with Iterable protocol but without Extractable.
599
+ *
600
+ * @typeParam A - The element type of the collection
601
+ * @typeParam Tag - The type tag for pattern matching
602
+ */
603
+ interface FunctypeCollection<A, Tag extends string = string> extends Omit<FunctypeBase<A, Tag>, "flatMapAsync" | "flatMap">, Iterable<A>, Pipe<A[]>, Collection<A>, CollectionOps<A, FunctypeCollection<A, Tag>> {
604
+ toValue(): {
605
+ _tag: Tag;
606
+ value: A[];
607
+ };
608
+ flatMap<B extends Type>(f: (value: A) => Iterable<B>): FunctypeCollection<B, Tag>;
609
+ flatMapAsync<B extends Type>(f: (value: A) => PromiseLike<Iterable<B>>): PromiseLike<FunctypeCollection<B, Tag>>;
610
+ }
611
+
612
+ type TestEither<L extends Type, R extends Type> = Either<L, R> & AsyncMonad<R>;
456
613
  declare const Right: <L extends Type, R extends Type>(value: R) => Either<L, R>;
457
614
  declare const Left: <L extends Type, R extends Type>(value: L) => Either<L, R>;
458
615
  declare const isRight: <L extends Type, R extends Type>(either: Either<L, R>) => either is Either<L, R> & {
@@ -470,14 +627,19 @@ declare const tryCatchAsync: <L extends Type, R extends Type>(f: () => Promise<R
470
627
  * @module Either
471
628
  * @category Core
472
629
  */
473
- type Either<L extends Type, R extends Type> = {
630
+ interface Either<L extends Type, R extends Type> extends FunctypeBase<R, "Left" | "Right">, PromiseLike<R> {
474
631
  readonly _tag: "Left" | "Right";
475
632
  value: L | R;
476
633
  isLeft: () => boolean;
477
634
  isRight: () => boolean;
635
+ get: () => R;
478
636
  getOrElse: (defaultValue: R) => R;
479
- getOrThrow: () => R;
637
+ getOrThrow: (error?: Error) => R;
638
+ orElse(alternative: Either<L, R>): Either<L, R>;
639
+ orNull: () => R | null;
640
+ orUndefined: () => R | undefined;
480
641
  map: <U extends Type>(f: (value: R) => U) => Either<L, U>;
642
+ ap: <U extends Type>(ff: Either<L, (value: R) => U>) => Either<L, U>;
481
643
  merge: <L1 extends Type, R1 extends Type>(other: Either<L1, R1>) => Either<L | L1, [R, R1]>;
482
644
  mapAsync: <U extends Type>(f: (value: R) => Promise<U>) => Promise<Either<L, U>>;
483
645
  flatMap: <U extends Type>(f: (value: R) => Either<L, U>) => Either<L, U>;
@@ -504,7 +666,7 @@ type Either<L extends Type, R extends Type> = {
504
666
  pipeEither<U extends Type>(onLeft: (value: L) => U, onRight: (value: R) => U): U;
505
667
  /**
506
668
  * Pipes the Either value through the provided function
507
- * @param f - The function to apply to the value
669
+ * @param f - The function to apply to the value (Left or Right)
508
670
  * @returns The result of applying the function to the value
509
671
  */
510
672
  pipe<U extends Type>(f: (value: L | R) => U): U;
@@ -517,7 +679,21 @@ type Either<L extends Type, R extends Type> = {
517
679
  Left: (value: L) => T;
518
680
  Right: (value: R) => T;
519
681
  }): T;
520
- } & Typeable<"Left" | "Right"> & Valuable<"Left" | "Right", L | R> & PromiseLike<R> & AsyncFunctor<R> & Serializable<R> & Pipe<L | R> & Foldable<R> & Matchable<L | R, "Left" | "Right">;
682
+ /**
683
+ * Returns the value and tag for inspection
684
+ */
685
+ toValue(): {
686
+ _tag: "Left" | "Right";
687
+ value: L | R;
688
+ };
689
+ /**
690
+ * Custom JSON serialization that excludes getter properties
691
+ */
692
+ toJSON(): {
693
+ _tag: "Left" | "Right";
694
+ value: L | R;
695
+ };
696
+ }
521
697
  declare const Either: {
522
698
  sequence: <L extends Type, R extends Type>(eithers: Either<L, R>[]) => Either<L, R[]>;
523
699
  traverse: <L extends Type, R extends Type, U extends Type>(arr: R[], f: (value: R) => Either<L, U>) => Either<L, U[]>;
@@ -530,4 +706,4 @@ declare const Either: {
530
706
  fromBinary: <L extends Type, R extends Type>(binary: string) => Either<L, R>;
531
707
  };
532
708
 
533
- export { type Converters as C, Either as E, type Foldable as F, type IterableType as I, List as L, type Matchable as M, None as N, Option as O, type Pipe as P, Right as R, type Serializable as S, type Traversable as T, type Collection as a, type TestEither as b, Left as c, isLeft as d, TypeCheckRight as e, TypeCheckLeft as f, tryCatchAsync as g, MatchableUtils as h, isRight as i, Some as j, OptionConstructor as k, type SerializationMethods as l, Set as m, tryCatch as t };
709
+ export { type AsyncMonad as A, type Collection as C, Either as E, type Foldable as F, List as L, type Matchable as M, None as N, Option as O, type Pipe as P, Right as R, type Serializable as S, type Traversable as T, type FunctypeBase as a, type Extractable as b, type TestEither as c, Left as d, isLeft as e, TypeCheckRight as f, TypeCheckLeft as g, tryCatchAsync as h, isRight as i, type Functype as j, type FunctypeCollection as k, MatchableUtils as l, Some as m, OptionConstructor as n, type SerializationMethods as o, Set as p, type CollectionOps as q, type ContainerOps as r, type Applicative as s, tryCatch as t, type Functor as u, type Monad as v };