functype 0.8.70 → 0.8.80
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 +181 -3
- package/dist/{Either-DlOLCe3b.d.ts → Either-CfG7OVB-.d.ts} +1 -1
- package/dist/{Map-R4vpSnzG.d.ts → Map-wkGSJvYa.d.ts} +2 -2
- package/dist/{Valuable-D4BtNlTV.d.ts → Valuable-BI2O7E9Q.d.ts} +1 -1
- package/dist/chunk-JIVKCD74.mjs +42 -0
- package/dist/chunk-JIVKCD74.mjs.map +1 -0
- package/dist/either/index.d.ts +2 -2
- package/dist/either/index.mjs +1 -1
- package/dist/fpromise/index.d.ts +2 -2
- package/dist/fpromise/index.mjs +1 -1
- package/dist/index.d.ts +254 -205
- package/dist/index.mjs +1 -1
- package/dist/list/index.d.ts +2 -2
- package/dist/list/index.mjs +1 -1
- package/dist/map/index.d.ts +3 -3
- package/dist/map/index.mjs +1 -1
- package/dist/option/index.d.ts +2 -2
- package/dist/option/index.mjs +1 -1
- package/dist/set/index.d.ts +2 -2
- package/dist/set/index.mjs +1 -1
- package/dist/try/index.d.ts +2 -2
- package/dist/try/index.mjs +1 -1
- package/dist/tuple/index.d.ts +1 -1
- package/package.json +25 -7
- package/readme/TUPLE-EXAMPLES.md +0 -3
- package/readme/task-error-handling.md +0 -1
- package/dist/chunk-5ABR3A24.mjs +0 -49
- package/dist/chunk-5ABR3A24.mjs.map +0 -1
package/dist/either/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { E as Either, c as Left, R as Right, b as TestEither, f as TypeCheckLeft, e as TypeCheckRight, d as isLeft, i as isRight, t as tryCatch, g as tryCatchAsync } from '../Either-
|
|
2
|
-
import '../Valuable-
|
|
1
|
+
export { E as Either, c as Left, R as Right, b as TestEither, f as TypeCheckLeft, e as TypeCheckRight, d as isLeft, i as isRight, t as tryCatch, g as tryCatchAsync } from '../Either-CfG7OVB-.js';
|
|
2
|
+
import '../Valuable-BI2O7E9Q.js';
|
package/dist/either/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{p as Either,i as Left,h as Right,n as TypeCheckLeft,m as TypeCheckRight,k as isLeft,j as isRight,l as tryCatch,o as tryCatchAsync}from'../chunk-
|
|
1
|
+
export{p as Either,i as Left,h as Right,n as TypeCheckLeft,m as TypeCheckRight,k as isLeft,j as isRight,l as tryCatch,o as tryCatchAsync}from'../chunk-JIVKCD74.mjs';import'../chunk-7PQA3W7W.mjs';import'../chunk-TQJDL6YW.mjs';//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/fpromise/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as Either } from '../Either-
|
|
2
|
-
import { T as Type } from '../Valuable-
|
|
1
|
+
import { E as Either } from '../Either-CfG7OVB-.js';
|
|
2
|
+
import { T as Type } from '../Valuable-BI2O7E9Q.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Error context information that provides additional metadata about errors.
|
package/dist/fpromise/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{J as FPromise,I as FPromiseCompanion}from'../chunk-
|
|
1
|
+
export{J as FPromise,I as FPromiseCompanion}from'../chunk-JIVKCD74.mjs';import'../chunk-7PQA3W7W.mjs';import'../chunk-TQJDL6YW.mjs';//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Brand } from './branded/index.js';
|
|
2
2
|
export { BrandedBoolean, BrandedNumber, BrandedString, ExtractBrand, Unbrand, createBrander, hasBrand, unbrand } from './branded/index.js';
|
|
3
|
-
import { O as Option, E as Either, F as Foldable, L as List,
|
|
4
|
-
export { a as Collection, C as Converters, I as IterableType, c as Left, h as MatchableUtils, N as None, k as OptionConstructor, R as Right, l as SerializationMethods, m as Set, j as Some, b as TestEither, f as TypeCheckLeft, e as TypeCheckRight, d as isLeft, i as isRight, t as tryCatch, g as tryCatchAsync } from './Either-
|
|
5
|
-
import { T as Type, a as Typeable, F as Functor, V as Valuable } from './Valuable-
|
|
6
|
-
export {
|
|
3
|
+
import { O as Option, E as Either, F as Foldable, L as List, P as Pipe, S as Serializable, M as Matchable, T as Traversable } from './Either-CfG7OVB-.js';
|
|
4
|
+
export { a as Collection, C as Converters, I as IterableType, c as Left, h as MatchableUtils, N as None, k as OptionConstructor, R as Right, l as SerializationMethods, m as Set, j as Some, b as TestEither, f as TypeCheckLeft, e as TypeCheckRight, d as isLeft, i as isRight, t as tryCatch, g as tryCatchAsync } from './Either-CfG7OVB-.js';
|
|
5
|
+
import { T as Type, a as Typeable, F as Functor, A as AsyncFunctor, V as Valuable } from './Valuable-BI2O7E9Q.js';
|
|
6
|
+
export { b as AbstractFunctor, c as ArrayFunctor, E as ExtractTag, d as TypeableParams, e as ValuableParams, i as isTypeable } from './Valuable-BI2O7E9Q.js';
|
|
7
7
|
import { FPromise } from './fpromise/index.js';
|
|
8
8
|
export { ErrorContext, FPromiseCompanion } from './fpromise/index.js';
|
|
9
9
|
import { Try } from './try/index.js';
|
|
10
10
|
export { TypeNames } from './try/index.js';
|
|
11
|
-
export { a as ESMap, E as ESMapType, M as Map, S as SafeTraversable } from './Map-
|
|
11
|
+
export { a as ESMap, E as ESMapType, M as Map, S as SafeTraversable } from './Map-wkGSJvYa.js';
|
|
12
12
|
export { Tuple } from './tuple/index.js';
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -645,205 +645,6 @@ declare const Task: (<T = unknown>(params?: TaskParams) => {
|
|
|
645
645
|
};
|
|
646
646
|
type Task = ReturnType<typeof Task>;
|
|
647
647
|
|
|
648
|
-
/**
|
|
649
|
-
* Code context for LLM-based self-healing and analysis
|
|
650
|
-
*/
|
|
651
|
-
type CodeContext = {
|
|
652
|
-
/** The source code being executed */
|
|
653
|
-
source: string;
|
|
654
|
-
/** File path or identifier */
|
|
655
|
-
filePath?: string;
|
|
656
|
-
/** Function/method name */
|
|
657
|
-
functionName?: string;
|
|
658
|
-
/** Line number where error occurred */
|
|
659
|
-
lineNumber?: number;
|
|
660
|
-
/** Input parameters that caused the issue */
|
|
661
|
-
inputParams?: Record<string, unknown>;
|
|
662
|
-
/** Expected output type/shape */
|
|
663
|
-
expectedOutput?: unknown;
|
|
664
|
-
/** Stack trace at time of error */
|
|
665
|
-
stackTrace?: string;
|
|
666
|
-
/** Previous execution attempts */
|
|
667
|
-
attempts?: Array<{
|
|
668
|
-
timestamp: Date;
|
|
669
|
-
error: string;
|
|
670
|
-
modifications?: string;
|
|
671
|
-
}>;
|
|
672
|
-
/** Additional context for LLM */
|
|
673
|
-
llmContext?: {
|
|
674
|
-
/** Description of what the code should do */
|
|
675
|
-
intent: string;
|
|
676
|
-
/** Known constraints or requirements */
|
|
677
|
-
constraints?: string[];
|
|
678
|
-
/** Related code/dependencies */
|
|
679
|
-
dependencies?: string[];
|
|
680
|
-
/** Business rules or domain knowledge */
|
|
681
|
-
domain?: string;
|
|
682
|
-
};
|
|
683
|
-
};
|
|
684
|
-
/**
|
|
685
|
-
* Fitness function result for code quality assessment
|
|
686
|
-
*/
|
|
687
|
-
type FitnessResult = {
|
|
688
|
-
/** Overall fitness score (0-100) */
|
|
689
|
-
score: number;
|
|
690
|
-
/** Individual metric scores */
|
|
691
|
-
metrics: {
|
|
692
|
-
/** Correctness score (0-100) */
|
|
693
|
-
correctness: number;
|
|
694
|
-
/** Performance score (0-100) */
|
|
695
|
-
performance: number;
|
|
696
|
-
/** Maintainability score (0-100) */
|
|
697
|
-
maintainability: number;
|
|
698
|
-
/** Security score (0-100) */
|
|
699
|
-
security: number;
|
|
700
|
-
/** Type safety score (0-100) */
|
|
701
|
-
typeSafety: number;
|
|
702
|
-
};
|
|
703
|
-
/** Detailed feedback for improvement */
|
|
704
|
-
feedback: string[];
|
|
705
|
-
/** Suggestions for self-healing */
|
|
706
|
-
suggestions: string[];
|
|
707
|
-
};
|
|
708
|
-
/**
|
|
709
|
-
* Partial fitness result from individual functions
|
|
710
|
-
*/
|
|
711
|
-
type PartialFitnessResult = {
|
|
712
|
-
/** Partial metric scores */
|
|
713
|
-
metrics?: Partial<FitnessResult["metrics"]>;
|
|
714
|
-
/** Detailed feedback for improvement */
|
|
715
|
-
feedback?: string[];
|
|
716
|
-
/** Suggestions for self-healing */
|
|
717
|
-
suggestions?: string[];
|
|
718
|
-
};
|
|
719
|
-
/**
|
|
720
|
-
* Configuration for self-healing behavior
|
|
721
|
-
*/
|
|
722
|
-
type SelfHealingConfig = {
|
|
723
|
-
/** Maximum number of self-healing attempts */
|
|
724
|
-
maxAttempts: number;
|
|
725
|
-
/** Whether to use LLM for code generation */
|
|
726
|
-
enableLLMHealing: boolean;
|
|
727
|
-
/** Minimum fitness score to accept */
|
|
728
|
-
minFitnessScore: number;
|
|
729
|
-
/** Custom fitness functions */
|
|
730
|
-
customFitnessFunctions?: Array<(context: CodeContext, result?: unknown) => Promise<PartialFitnessResult>>;
|
|
731
|
-
/** LLM provider configuration */
|
|
732
|
-
llmConfig?: {
|
|
733
|
-
provider: "openai" | "anthropic" | "custom";
|
|
734
|
-
apiKey?: string;
|
|
735
|
-
model?: string;
|
|
736
|
-
temperature?: number;
|
|
737
|
-
customEndpoint?: string;
|
|
738
|
-
};
|
|
739
|
-
};
|
|
740
|
-
/**
|
|
741
|
-
* Self-healing attempt result
|
|
742
|
-
*/
|
|
743
|
-
type HealingAttempt = {
|
|
744
|
-
/** Attempt number */
|
|
745
|
-
attempt: number;
|
|
746
|
-
/** Timestamp of attempt */
|
|
747
|
-
timestamp: Date;
|
|
748
|
-
/** Error that triggered healing */
|
|
749
|
-
error: string;
|
|
750
|
-
/** Generated/modified code */
|
|
751
|
-
healedCode?: string;
|
|
752
|
-
/** Fitness score of healed code */
|
|
753
|
-
fitnessScore?: number;
|
|
754
|
-
/** Whether healing was successful */
|
|
755
|
-
success: boolean;
|
|
756
|
-
/** Reasoning for the healing approach */
|
|
757
|
-
reasoning?: string;
|
|
758
|
-
};
|
|
759
|
-
/**
|
|
760
|
-
* Code-aware task that can self-heal using LLM context
|
|
761
|
-
*/
|
|
762
|
-
type CodeAwareTask<T extends Type> = {
|
|
763
|
-
/** Execute with code context and self-healing */
|
|
764
|
-
executeWithHealing: (codeContext: CodeContext, config: SelfHealingConfig, cancellationToken?: CancellationToken) => Promise<{
|
|
765
|
-
result: Option<unknown>;
|
|
766
|
-
fitness: FitnessResult;
|
|
767
|
-
healingAttempts: HealingAttempt[];
|
|
768
|
-
finalCode: string;
|
|
769
|
-
}>;
|
|
770
|
-
/** Evaluate fitness of code without execution */
|
|
771
|
-
evaluateFitness: (codeContext: CodeContext, result?: unknown, customFunctions?: Array<(context: CodeContext, result?: unknown) => Promise<PartialFitnessResult>>) => Promise<FitnessResult>;
|
|
772
|
-
/** Generate healing suggestions using LLM */
|
|
773
|
-
generateHealingSuggestions: (codeContext: CodeContext, error: string, config: SelfHealingConfig) => Promise<{
|
|
774
|
-
suggestions: string[];
|
|
775
|
-
healedCode?: string;
|
|
776
|
-
reasoning: string;
|
|
777
|
-
}>;
|
|
778
|
-
/** Validate healed code before execution */
|
|
779
|
-
validateHealedCode: (original: CodeContext, healed: string, config: SelfHealingConfig) => Promise<{
|
|
780
|
-
isValid: boolean;
|
|
781
|
-
issues: string[];
|
|
782
|
-
riskLevel: "low" | "medium" | "high";
|
|
783
|
-
}>;
|
|
784
|
-
};
|
|
785
|
-
/**
|
|
786
|
-
* Code-aware task that provides LLM context for self-healing and fitness evaluation
|
|
787
|
-
* @example
|
|
788
|
-
* // Basic usage with self-healing
|
|
789
|
-
* const codeTask = CodeAwareTask<string>({ name: "DataProcessor" })
|
|
790
|
-
* const context = CodeAwareTask.createCodeContext(
|
|
791
|
-
* "function processData(data) { return data.map(x => x.value) }",
|
|
792
|
-
* "Process array of objects to extract values"
|
|
793
|
-
* )
|
|
794
|
-
*
|
|
795
|
-
* const result = await codeTask.executeWithHealing(
|
|
796
|
-
* context,
|
|
797
|
-
* CodeAwareTask.defaultConfig()
|
|
798
|
-
* )
|
|
799
|
-
*
|
|
800
|
-
* @example
|
|
801
|
-
* // Custom fitness evaluation
|
|
802
|
-
* const customFitness = CodeAwareTask.createCustomFitnessFunction(
|
|
803
|
-
* "businessLogic",
|
|
804
|
-
* async (context, result) => ({
|
|
805
|
-
* score: 85,
|
|
806
|
-
* feedback: ["Follows business rules correctly"],
|
|
807
|
-
* suggestions: ["Consider adding validation"]
|
|
808
|
-
* })
|
|
809
|
-
* )
|
|
810
|
-
*
|
|
811
|
-
* const fitness = await codeTask.evaluateFitness(context, result, [customFitness])
|
|
812
|
-
*
|
|
813
|
-
* @example
|
|
814
|
-
* // High-fitness configuration
|
|
815
|
-
* const strictConfig = CodeAwareTask.fitnessConfig(90)
|
|
816
|
-
* const result = await codeTask.executeWithHealing(context, strictConfig)
|
|
817
|
-
*/
|
|
818
|
-
declare const CodeAwareTask: (<T extends Type>(params?: TaskParams) => CodeAwareTask<T>) & {
|
|
819
|
-
/**
|
|
820
|
-
* Create a default self-healing configuration
|
|
821
|
-
*/
|
|
822
|
-
defaultConfig: () => SelfHealingConfig;
|
|
823
|
-
/**
|
|
824
|
-
* Create a fitness-focused configuration
|
|
825
|
-
*/
|
|
826
|
-
fitnessConfig: (minScore: number) => SelfHealingConfig;
|
|
827
|
-
/**
|
|
828
|
-
* Create a custom fitness function for domain-specific evaluation
|
|
829
|
-
*/
|
|
830
|
-
createCustomFitnessFunction: (name: string, evaluator: (context: CodeContext, result?: unknown) => Promise<{
|
|
831
|
-
score: number;
|
|
832
|
-
feedback: string[];
|
|
833
|
-
suggestions?: string[];
|
|
834
|
-
}>) => (context: CodeContext, result?: unknown) => Promise<PartialFitnessResult>;
|
|
835
|
-
/**
|
|
836
|
-
* Utility to create code context from function
|
|
837
|
-
*/
|
|
838
|
-
createCodeContext: (source: string, intent: string, options?: {
|
|
839
|
-
filePath?: string;
|
|
840
|
-
functionName?: string;
|
|
841
|
-
expectedOutput?: unknown;
|
|
842
|
-
constraints?: string[];
|
|
843
|
-
dependencies?: string[];
|
|
844
|
-
}) => CodeContext;
|
|
845
|
-
};
|
|
846
|
-
|
|
847
648
|
/**
|
|
848
649
|
* Type definition for task information that may be attached to errors
|
|
849
650
|
*/
|
|
@@ -1024,6 +825,254 @@ type Identity<T> = {
|
|
|
1024
825
|
};
|
|
1025
826
|
declare function Identity<T>(value: T): Identity<T>;
|
|
1026
827
|
|
|
828
|
+
/**
|
|
829
|
+
* Lazy type module
|
|
830
|
+
* @module Lazy
|
|
831
|
+
* @category Core
|
|
832
|
+
*/
|
|
833
|
+
/**
|
|
834
|
+
* The Lazy type represents a computation that is deferred until needed.
|
|
835
|
+
* It provides memoization and safe evaluation with integration to Option, Either, and Try.
|
|
836
|
+
* @typeParam T - The type of the value to be computed
|
|
837
|
+
*/
|
|
838
|
+
type Lazy<T extends Type> = {
|
|
839
|
+
/** Tag identifying this as a Lazy type */
|
|
840
|
+
readonly _tag: "Lazy";
|
|
841
|
+
/** Whether the computation has been evaluated */
|
|
842
|
+
readonly isEvaluated: boolean;
|
|
843
|
+
/**
|
|
844
|
+
* Forces evaluation of the lazy value and returns the result.
|
|
845
|
+
* The result is memoized after first evaluation.
|
|
846
|
+
* @returns The computed value
|
|
847
|
+
* @throws Any error thrown by the computation
|
|
848
|
+
*/
|
|
849
|
+
get(): T;
|
|
850
|
+
/**
|
|
851
|
+
* Returns the computed value or a default value if computation fails
|
|
852
|
+
* @param defaultValue - The value to return if computation fails
|
|
853
|
+
* @returns The computed value or defaultValue
|
|
854
|
+
*/
|
|
855
|
+
getOrElse(defaultValue: T): T;
|
|
856
|
+
/**
|
|
857
|
+
* Returns the computed value or null if computation fails
|
|
858
|
+
* @returns The computed value or null
|
|
859
|
+
*/
|
|
860
|
+
getOrNull(): T | null;
|
|
861
|
+
/**
|
|
862
|
+
* Returns the computed value or throws a specified error if computation fails
|
|
863
|
+
* @param error - The error to throw if computation fails
|
|
864
|
+
* @returns The computed value
|
|
865
|
+
* @throws The specified error if computation fails
|
|
866
|
+
*/
|
|
867
|
+
getOrThrow(error: Error): T;
|
|
868
|
+
/**
|
|
869
|
+
* Maps the value inside the Lazy using the provided function
|
|
870
|
+
* @param f - The mapping function
|
|
871
|
+
* @returns A new Lazy containing the mapped value
|
|
872
|
+
*/
|
|
873
|
+
map<U extends Type>(f: (value: T) => U): Lazy<U>;
|
|
874
|
+
/**
|
|
875
|
+
* Maps the value inside the Lazy using an async function
|
|
876
|
+
* @param f - The async mapping function
|
|
877
|
+
* @returns A Promise of a new Lazy containing the mapped value
|
|
878
|
+
*/
|
|
879
|
+
mapAsync<U extends Type>(f: (value: T) => Promise<U>): Promise<Lazy<U>>;
|
|
880
|
+
/**
|
|
881
|
+
* Maps the value using a function that returns a Lazy
|
|
882
|
+
* @param f - The mapping function returning a Lazy
|
|
883
|
+
* @returns A new Lazy containing the flattened result
|
|
884
|
+
*/
|
|
885
|
+
flatMap<U extends Type>(f: (value: T) => Lazy<U>): Lazy<U>;
|
|
886
|
+
/**
|
|
887
|
+
* Maps the value using an async function that returns a Lazy
|
|
888
|
+
* @param f - The async mapping function returning a Lazy
|
|
889
|
+
* @returns A Promise of a new Lazy containing the flattened result
|
|
890
|
+
*/
|
|
891
|
+
flatMapAsync<U extends Type>(f: (value: T) => Promise<Lazy<U>>): Promise<Lazy<U>>;
|
|
892
|
+
/**
|
|
893
|
+
* Returns a Lazy that filters the value based on a predicate
|
|
894
|
+
* @param predicate - The predicate function
|
|
895
|
+
* @returns A Lazy containing an Option of the value
|
|
896
|
+
*/
|
|
897
|
+
filter(predicate: (value: T) => boolean): Lazy<Option<T>>;
|
|
898
|
+
/**
|
|
899
|
+
* Recovers from a failed computation by providing an alternative value
|
|
900
|
+
* @param f - Function that takes the error and returns a recovery value
|
|
901
|
+
* @returns A new Lazy that will use the recovery function if computation fails
|
|
902
|
+
*/
|
|
903
|
+
recover(f: (error: unknown) => T): Lazy<T>;
|
|
904
|
+
/**
|
|
905
|
+
* Recovers from a failed computation by providing an alternative Lazy
|
|
906
|
+
* @param f - Function that takes the error and returns a recovery Lazy
|
|
907
|
+
* @returns A new Lazy that will use the recovery Lazy if computation fails
|
|
908
|
+
*/
|
|
909
|
+
recoverWith(f: (error: unknown) => Lazy<T>): Lazy<T>;
|
|
910
|
+
/**
|
|
911
|
+
* Evaluates the computation and returns it as an Option
|
|
912
|
+
* @returns Some containing the value if successful, None if computation fails
|
|
913
|
+
*/
|
|
914
|
+
toOption(): Option<T>;
|
|
915
|
+
/**
|
|
916
|
+
* Evaluates the computation and returns it as an Either
|
|
917
|
+
* @returns Right containing the value if successful, Left containing the error if computation fails
|
|
918
|
+
*/
|
|
919
|
+
toEither(): Either<unknown, T>;
|
|
920
|
+
/**
|
|
921
|
+
* Evaluates the computation and returns it as an Either with a mapped error
|
|
922
|
+
* @param mapError - Function to map the error
|
|
923
|
+
* @returns Right containing the value if successful, Left containing the mapped error if computation fails
|
|
924
|
+
*/
|
|
925
|
+
toEitherWith<E>(mapError: (error: unknown) => E): Either<E, T>;
|
|
926
|
+
/**
|
|
927
|
+
* Evaluates the computation and returns it as a Try
|
|
928
|
+
* @returns Try containing the result of the computation
|
|
929
|
+
*/
|
|
930
|
+
toTry(): Try<T>;
|
|
931
|
+
/**
|
|
932
|
+
* Applies an effect function to the value if computation succeeds
|
|
933
|
+
* @param f - The effect function
|
|
934
|
+
* @returns This Lazy for chaining
|
|
935
|
+
*/
|
|
936
|
+
tap(f: (value: T) => void): Lazy<T>;
|
|
937
|
+
/**
|
|
938
|
+
* Applies an effect function to the error if computation fails
|
|
939
|
+
* @param f - The effect function for errors
|
|
940
|
+
* @returns This Lazy for chaining
|
|
941
|
+
*/
|
|
942
|
+
tapError(f: (error: unknown) => void): Lazy<T>;
|
|
943
|
+
/**
|
|
944
|
+
* Pattern matching on the Lazy value
|
|
945
|
+
* @param f - Function to apply to the computed value
|
|
946
|
+
* @returns The result of applying f to the computed value
|
|
947
|
+
*/
|
|
948
|
+
fold<U>(f: (value: T) => U): U;
|
|
949
|
+
/**
|
|
950
|
+
* Pattern matching with success and failure handlers
|
|
951
|
+
* @param onFailure - Function to handle computation failure
|
|
952
|
+
* @param onSuccess - Function to handle successful computation
|
|
953
|
+
* @returns The result of the appropriate handler
|
|
954
|
+
*/
|
|
955
|
+
foldWith<U>(onFailure: (error: unknown) => U, onSuccess: (value: T) => U): U;
|
|
956
|
+
/**
|
|
957
|
+
* Left fold operation
|
|
958
|
+
* @param z - Initial value
|
|
959
|
+
* @returns Function that takes an operator and applies it
|
|
960
|
+
*/
|
|
961
|
+
foldLeft: <B>(z: B) => (op: (b: B, a: T) => B) => B;
|
|
962
|
+
/**
|
|
963
|
+
* Right fold operation
|
|
964
|
+
* @param z - Initial value
|
|
965
|
+
* @returns Function that takes an operator and applies it
|
|
966
|
+
*/
|
|
967
|
+
foldRight: <B>(z: B) => (op: (a: T, b: B) => B) => B;
|
|
968
|
+
/**
|
|
969
|
+
* Pattern matching for the Lazy type
|
|
970
|
+
* @param patterns - Object with handler for Lazy pattern
|
|
971
|
+
* @returns The result of the matched handler
|
|
972
|
+
*/
|
|
973
|
+
match<R>(patterns: {
|
|
974
|
+
Lazy: (value: T) => R;
|
|
975
|
+
}): R;
|
|
976
|
+
/**
|
|
977
|
+
* Creates a string representation of the Lazy
|
|
978
|
+
* @returns String representation showing evaluation status
|
|
979
|
+
*/
|
|
980
|
+
toString(): string;
|
|
981
|
+
/**
|
|
982
|
+
* Converts the Lazy to a value object
|
|
983
|
+
* @returns Object representation of the Lazy
|
|
984
|
+
*/
|
|
985
|
+
toValue(): {
|
|
986
|
+
_tag: "Lazy";
|
|
987
|
+
evaluated: boolean;
|
|
988
|
+
value?: T;
|
|
989
|
+
};
|
|
990
|
+
} & Functor<T> & AsyncFunctor<T> & Pipe<T> & Serializable<T> & Typeable<"Lazy"> & Foldable<T> & Matchable<T, "Lazy">;
|
|
991
|
+
/**
|
|
992
|
+
* Creates a Lazy computation that defers evaluation until needed.
|
|
993
|
+
* Results are memoized after first evaluation.
|
|
994
|
+
*
|
|
995
|
+
* @example
|
|
996
|
+
* // Basic lazy evaluation
|
|
997
|
+
* const expensive = Lazy(() => {
|
|
998
|
+
* console.log("Computing...")
|
|
999
|
+
* return 42
|
|
1000
|
+
* })
|
|
1001
|
+
* // Nothing printed yet
|
|
1002
|
+
* const result = expensive.get() // Prints "Computing..." and returns 42
|
|
1003
|
+
* const cached = expensive.get() // Returns 42 without printing
|
|
1004
|
+
*
|
|
1005
|
+
* @example
|
|
1006
|
+
* // Error handling
|
|
1007
|
+
* const risky = Lazy(() => {
|
|
1008
|
+
* if (Math.random() > 0.5) throw new Error("Failed")
|
|
1009
|
+
* return "Success"
|
|
1010
|
+
* })
|
|
1011
|
+
* const safe = risky.getOrElse("Default") // Returns "Success" or "Default"
|
|
1012
|
+
* const option = risky.toOption() // Some("Success") or None
|
|
1013
|
+
* const either = risky.toEither() // Right("Success") or Left(Error)
|
|
1014
|
+
*
|
|
1015
|
+
* @example
|
|
1016
|
+
* // Chaining computations
|
|
1017
|
+
* const result = Lazy(() => 10)
|
|
1018
|
+
* .map(x => x * 2)
|
|
1019
|
+
* .flatMap(x => Lazy(() => x + 5))
|
|
1020
|
+
* .recover(err => 0)
|
|
1021
|
+
* .get() // 25
|
|
1022
|
+
*
|
|
1023
|
+
* @example
|
|
1024
|
+
* // Integration with functype
|
|
1025
|
+
* const userOption = Option({ id: 1, name: "Alice" })
|
|
1026
|
+
* const userName = Lazy.fromOption(userOption, () => ({ id: 0, name: "Anonymous" }))
|
|
1027
|
+
* .map(user => user.name)
|
|
1028
|
+
* .get() // "Alice"
|
|
1029
|
+
*/
|
|
1030
|
+
declare const Lazy: (<T extends Type>(thunk: () => T) => Lazy<T>) & {
|
|
1031
|
+
/**
|
|
1032
|
+
* Creates a Lazy from a thunk (deferred computation)
|
|
1033
|
+
* @param thunk - Function that computes the value
|
|
1034
|
+
* @returns A new Lazy instance
|
|
1035
|
+
*/
|
|
1036
|
+
of: <T extends Type>(thunk: () => T) => Lazy<T>;
|
|
1037
|
+
/**
|
|
1038
|
+
* Creates a Lazy from an immediate value
|
|
1039
|
+
* @param value - The value to wrap
|
|
1040
|
+
* @returns A new Lazy instance that returns the value
|
|
1041
|
+
*/
|
|
1042
|
+
fromValue: <T extends Type>(value: T) => Lazy<T>;
|
|
1043
|
+
/**
|
|
1044
|
+
* Creates a Lazy from an Option
|
|
1045
|
+
* @param option - The Option to convert
|
|
1046
|
+
* @param defaultThunk - Thunk to compute default value if Option is None
|
|
1047
|
+
* @returns A new Lazy instance
|
|
1048
|
+
*/
|
|
1049
|
+
fromOption: <T extends Type>(option: Option<T>, defaultThunk: () => T) => Lazy<T>;
|
|
1050
|
+
/**
|
|
1051
|
+
* Creates a Lazy from a Try
|
|
1052
|
+
* @param tryValue - The Try to convert
|
|
1053
|
+
* @returns A new Lazy instance
|
|
1054
|
+
*/
|
|
1055
|
+
fromTry: <T extends Type>(tryValue: Try<T>) => Lazy<T>;
|
|
1056
|
+
/**
|
|
1057
|
+
* Creates a Lazy from an Either
|
|
1058
|
+
* @param either - The Either to convert
|
|
1059
|
+
* @returns A new Lazy instance
|
|
1060
|
+
*/
|
|
1061
|
+
fromEither: <E, T extends Type>(either: Either<E, T>) => Lazy<T>;
|
|
1062
|
+
/**
|
|
1063
|
+
* Creates a Lazy that will throw an error since promises need to be awaited first
|
|
1064
|
+
* @param promise - The Promise to convert
|
|
1065
|
+
* @returns A new Lazy instance that throws an error
|
|
1066
|
+
*/
|
|
1067
|
+
fromPromise: <T extends Type>(promise: Promise<T>) => Lazy<T>;
|
|
1068
|
+
/**
|
|
1069
|
+
* Creates a failed Lazy that will throw when evaluated
|
|
1070
|
+
* @param error - The error to throw
|
|
1071
|
+
* @returns A new Lazy instance that throws the error
|
|
1072
|
+
*/
|
|
1073
|
+
fail: <T extends Type>(error: unknown) => Lazy<T>;
|
|
1074
|
+
};
|
|
1075
|
+
|
|
1027
1076
|
/**
|
|
1028
1077
|
* LazyList provides lazy evaluation for list operations.
|
|
1029
1078
|
* Operations are deferred until the list is materialized.
|
|
@@ -1244,4 +1293,4 @@ declare const Stack: (<A extends Type>(values?: A[]) => Stack<A>) & {
|
|
|
1244
1293
|
fromBinary: <A>(binary: string) => Stack<A>;
|
|
1245
1294
|
};
|
|
1246
1295
|
|
|
1247
|
-
export { type Async, Base, BoundedNumber, BoundedString, Brand, type CancellationToken, type CancellationTokenSource,
|
|
1296
|
+
export { type Async, AsyncFunctor, Base, BoundedNumber, BoundedString, Brand, type CancellationToken, type CancellationTokenSource, Companion, Cond, Either, type EitherKind, EmailAddress, type ErrorChainElement, type ErrorFormatterOptions, type ErrorWithTaskInfo, FPromise, Foldable, FoldableUtils, Functor, HKT, ISO8601Date, Identity, IntegerNumber, type Kind, Lazy, LazyList, Lazy as LazyType, List, type ListKind, Match, Matchable, NAME, NonEmptyString, NonNegativeNumber, Option, type OptionKind, ParseError, PatternString, Pipe, PositiveInteger, PositiveNumber, Serializable, Stack, type Sync, type TaggedThrowable, Task, type TaskErrorInfo, TaskException, type TaskInfo, type TaskParams, TaskResult, Throwable, type ThrowableType, Traversable, Try, type TryKind, Type, Typeable, UUID, type UniversalContainer, UrlString, ValidatedBrand, Valuable, createCancellationTokenSource, createErrorSerializer, formatError, formatStackTrace, isTaggedThrowable, safeStringify };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{F as Base,A as BoundedNumber,B as BoundedString,
|
|
1
|
+
export{F as Base,A as BoundedNumber,B as BoundedString,a as Companion,D as Cond,_ as ESMap,p as Either,w as EmailAddress,J as FPromise,I as FPromiseCompanion,U as FoldableUtils,W as HKT,z as ISO8601Date,X as Identity,t as IntegerNumber,Y as Lazy,Z as LazyList,i as Left,g as List,$ as Map,E as Match,aa as MatchableUtils,G as NAME,v as NonEmptyString,s as NonNegativeNumber,c as None,e as Option,d as OptionConstructor,T as ParseError,C as PatternString,u as PositiveInteger,r as PositiveNumber,h as Right,f as Set,b as Some,ba as Stack,O as Task,L as TaskException,M as TaskResult,H as Throwable,V as Try,n as TypeCheckLeft,m as TypeCheckRight,y as UUID,x as UrlString,q as ValidatedBrand,N as createCancellationTokenSource,S as createErrorSerializer,R as formatError,Q as formatStackTrace,k as isLeft,j as isRight,K as isTaggedThrowable,P as safeStringify,l as tryCatch,o as tryCatchAsync}from'./chunk-JIVKCD74.mjs';export{d as Tuple,a as Typeable,c as Valuable,b as isTypeable}from'./chunk-7PQA3W7W.mjs';export{a as Brand,g as BrandedBoolean,f as BrandedNumber,e as BrandedString,d as createBrander,c as hasBrand,b as unbrand}from'./chunk-TQJDL6YW.mjs';//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/list/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { L as List } from '../Either-
|
|
2
|
-
import '../Valuable-
|
|
1
|
+
export { L as List } from '../Either-CfG7OVB-.js';
|
|
2
|
+
import '../Valuable-BI2O7E9Q.js';
|
package/dist/list/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{g as List}from'../chunk-
|
|
1
|
+
export{g as List}from'../chunk-JIVKCD74.mjs';import'../chunk-7PQA3W7W.mjs';import'../chunk-TQJDL6YW.mjs';//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/map/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import '../Either-
|
|
2
|
-
import '../Valuable-
|
|
3
|
-
export { M as Map, S as SafeTraversable } from '../Map-
|
|
1
|
+
import '../Either-CfG7OVB-.js';
|
|
2
|
+
import '../Valuable-BI2O7E9Q.js';
|
|
3
|
+
export { M as Map, S as SafeTraversable } from '../Map-wkGSJvYa.js';
|
|
4
4
|
import '../tuple/index.js';
|
package/dist/map/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{$ as Map}from'../chunk-
|
|
1
|
+
export{$ as Map}from'../chunk-JIVKCD74.mjs';import'../chunk-7PQA3W7W.mjs';import'../chunk-TQJDL6YW.mjs';//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/option/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { N as None, O as Option, k as OptionConstructor, j as Some } from '../Either-
|
|
2
|
-
import '../Valuable-
|
|
1
|
+
export { N as None, O as Option, k as OptionConstructor, j as Some } from '../Either-CfG7OVB-.js';
|
|
2
|
+
import '../Valuable-BI2O7E9Q.js';
|
package/dist/option/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{c as None,e as Option,d as OptionConstructor,b as Some}from'../chunk-
|
|
1
|
+
export{c as None,e as Option,d as OptionConstructor,b as Some}from'../chunk-JIVKCD74.mjs';import'../chunk-7PQA3W7W.mjs';import'../chunk-TQJDL6YW.mjs';//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/set/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { m as Set } from '../Either-
|
|
2
|
-
import '../Valuable-
|
|
1
|
+
export { m as Set } from '../Either-CfG7OVB-.js';
|
|
2
|
+
import '../Valuable-BI2O7E9Q.js';
|
package/dist/set/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{f as Set}from'../chunk-
|
|
1
|
+
export{f as Set}from'../chunk-JIVKCD74.mjs';import'../chunk-7PQA3W7W.mjs';import'../chunk-TQJDL6YW.mjs';//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/try/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as Either, S as Serializable, P as Pipe, F as Foldable, M as Matchable } from '../Either-
|
|
2
|
-
import { T as Type, a as Typeable, V as Valuable } from '../Valuable-
|
|
1
|
+
import { E as Either, S as Serializable, P as Pipe, F as Foldable, M as Matchable } from '../Either-CfG7OVB-.js';
|
|
2
|
+
import { T as Type, a as Typeable, V as Valuable } from '../Valuable-BI2O7E9Q.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Possible types of Try instances
|
package/dist/try/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{V as Try}from'../chunk-JIVKCD74.mjs';import'../chunk-7PQA3W7W.mjs';import'../chunk-TQJDL6YW.mjs';//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/tuple/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as Type, c as ArrayFunctor, a as Typeable, V as Valuable } from '../Valuable-
|
|
1
|
+
import { T as Type, c as ArrayFunctor, a as Typeable, V as Valuable } from '../Valuable-BI2O7E9Q.js';
|
|
2
2
|
|
|
3
3
|
type Tuple<T extends Type[]> = {
|
|
4
4
|
get<K extends number>(index: K): T[K];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functype",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.80",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A smallish functional library for TypeScript",
|
|
6
6
|
"author": "jordan.burke@gmail.com",
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"homepage": "https://github.com/jordanburke/functype#readme",
|
|
13
13
|
"url": "https://github.com/jordanburke/functype",
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@eslint/compat": "^1.3.
|
|
15
|
+
"@eslint/compat": "^1.3.1",
|
|
16
16
|
"@eslint/eslintrc": "^3.3.1",
|
|
17
17
|
"@eslint/js": "^9.29.0",
|
|
18
|
-
"@types/node": "^22.15.
|
|
19
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
20
|
-
"@typescript-eslint/parser": "^8.
|
|
18
|
+
"@types/node": "^22.15.33",
|
|
19
|
+
"@typescript-eslint/eslint-plugin": "^8.35.0",
|
|
20
|
+
"@typescript-eslint/parser": "^8.35.0",
|
|
21
21
|
"@vitest/coverage-v8": "^3.2.4",
|
|
22
22
|
"@vitest/ui": "^3.2.4",
|
|
23
23
|
"cross-env": "^7.0.3",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"eslint-config-prettier": "^10.1.5",
|
|
26
26
|
"eslint-plugin-functional": "^9.0.2",
|
|
27
27
|
"eslint-plugin-import": "^2.32.0",
|
|
28
|
-
"eslint-plugin-prettier": "^5.5.
|
|
28
|
+
"eslint-plugin-prettier": "^5.5.1",
|
|
29
29
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
30
30
|
"fast-check": "^4.1.1",
|
|
31
31
|
"globals": "^16.2.0",
|
|
32
|
-
"prettier": "^3.
|
|
32
|
+
"prettier": "^3.6.1",
|
|
33
33
|
"rimraf": "^6.0.1",
|
|
34
34
|
"ts-node": "^10.9.2",
|
|
35
35
|
"tsup": "^8.5.0",
|
|
@@ -76,6 +76,12 @@
|
|
|
76
76
|
"default": "./dist/conditional/index.mjs"
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
|
+
"./lazy": {
|
|
80
|
+
"import": {
|
|
81
|
+
"types": "./dist/lazy/index.d.ts",
|
|
82
|
+
"default": "./dist/lazy/index.mjs"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
79
85
|
"./task": {
|
|
80
86
|
"import": {
|
|
81
87
|
"types": "./dist/core/task/index.d.ts",
|
|
@@ -88,6 +94,18 @@
|
|
|
88
94
|
"default": "./dist/fpromise/index.mjs"
|
|
89
95
|
}
|
|
90
96
|
},
|
|
97
|
+
"./functype": {
|
|
98
|
+
"import": {
|
|
99
|
+
"types": "./dist/functype/index.d.ts",
|
|
100
|
+
"default": "./dist/functype/index.mjs"
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"./typeclass": {
|
|
104
|
+
"import": {
|
|
105
|
+
"types": "./dist/typeclass/index.d.ts",
|
|
106
|
+
"default": "./dist/typeclass/index.mjs"
|
|
107
|
+
}
|
|
108
|
+
},
|
|
91
109
|
"./map": {
|
|
92
110
|
"import": {
|
|
93
111
|
"types": "./dist/map/index.d.ts",
|