functype 0.8.67 → 0.8.69
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 +136 -6
- package/dist/Either-BfXNbTHo.d.ts +533 -0
- package/dist/Map-vivbm5n0.d.ts +65 -0
- package/dist/{Tuple-DfdXAbL_.d.ts → Valuable-CtuVEKTZ.d.ts} +17 -10
- package/dist/chunk-5DWCHDSA.mjs +39 -0
- package/dist/chunk-5DWCHDSA.mjs.map +1 -0
- package/dist/chunk-7PQA3W7W.mjs +2 -0
- package/dist/chunk-7PQA3W7W.mjs.map +1 -0
- package/dist/either/index.d.ts +2 -3
- package/dist/either/index.mjs +1 -1
- package/dist/fpromise/index.d.ts +373 -3
- package/dist/fpromise/index.mjs +1 -1
- package/dist/index.d.ts +533 -2
- package/dist/index.mjs +1 -1
- package/dist/list/index.d.ts +2 -3
- package/dist/list/index.mjs +1 -1
- package/dist/map/index.d.ts +4 -3
- package/dist/map/index.mjs +1 -1
- package/dist/option/index.d.ts +2 -987
- package/dist/option/index.mjs +1 -1
- package/dist/set/index.d.ts +2 -3
- package/dist/set/index.mjs +1 -1
- package/dist/try/index.d.ts +59 -3
- package/dist/try/index.mjs +1 -1
- package/dist/tuple/index.d.ts +12 -1
- package/dist/tuple/index.mjs +1 -1
- package/package.json +17 -16
- package/readme/BUNDLE_OPTIMIZATION.md +74 -0
- package/readme/FPromise-Assessment.md +43 -0
- package/readme/HKT.md +110 -0
- package/readme/ROADMAP.md +113 -0
- package/readme/TASK-IMPLEMENTATION.md +290 -0
- package/readme/TASK-TODO.md +40 -0
- package/readme/TASK-UPDATES.md +64 -0
- package/readme/TUPLE-EXAMPLES.md +79 -0
- package/readme/TaskMigration.md +129 -0
- package/readme/ai-guide.md +406 -0
- package/readme/examples.md +2093 -0
- package/readme/quick-reference.md +514 -0
- package/readme/task-cancellation-progress.md +258 -0
- package/readme/task-error-handling.md +128 -0
- package/readme/task-quick-reference.md +157 -0
- package/readme/tasks.md +205 -0
- package/readme/type-index.md +238 -0
- package/dist/chunk-NTL4HYMA.mjs +0 -18
- package/dist/chunk-NTL4HYMA.mjs.map +0 -1
- package/dist/chunk-PXFJPCM7.mjs +0 -2
- package/dist/chunk-PXFJPCM7.mjs.map +0 -1
package/dist/option/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{c as None,e as Option,d as OptionConstructor,b as Some}from'../chunk-5DWCHDSA.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,3 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import '../
|
|
3
|
-
import '../branded/index.js';
|
|
1
|
+
export { m as Set } from '../Either-BfXNbTHo.js';
|
|
2
|
+
import '../Valuable-CtuVEKTZ.js';
|
package/dist/set/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{f as Set}from'../chunk-5DWCHDSA.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,3 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
import '../
|
|
3
|
-
|
|
1
|
+
import { E as Either, S as Serializable, P as Pipe, F as Foldable, M as Matchable } from '../Either-BfXNbTHo.js';
|
|
2
|
+
import { a as Type, T as Typeable, V as Valuable } from '../Valuable-CtuVEKTZ.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Possible types of Try instances
|
|
6
|
+
*/
|
|
7
|
+
type TypeNames = "Success" | "Failure";
|
|
8
|
+
type Try<T> = {
|
|
9
|
+
readonly _tag: TypeNames;
|
|
10
|
+
readonly error: Error | undefined;
|
|
11
|
+
isSuccess: () => boolean;
|
|
12
|
+
isFailure: () => boolean;
|
|
13
|
+
get: () => T;
|
|
14
|
+
getOrElse: (defaultValue: T) => T;
|
|
15
|
+
orElse: (alternative: Try<T>) => Try<T>;
|
|
16
|
+
orThrow: (error: Error) => T;
|
|
17
|
+
toEither: () => Either<Error, T>;
|
|
18
|
+
map: <U>(f: (value: T) => U) => Try<U>;
|
|
19
|
+
flatMap: <U>(f: (value: T) => Try<U>) => Try<U>;
|
|
20
|
+
/**
|
|
21
|
+
* Pattern matches over the Try, applying onFailure if Failure and onSuccess if Success
|
|
22
|
+
* @param onFailure - Function to apply if the Try is Failure
|
|
23
|
+
* @param onSuccess - Function to apply if the Try is Success
|
|
24
|
+
* @returns The result of applying the appropriate function
|
|
25
|
+
*/
|
|
26
|
+
fold: <U extends Type>(onFailure: (error: Error) => U, onSuccess: (value: T) => U) => U;
|
|
27
|
+
toString: () => string;
|
|
28
|
+
/**
|
|
29
|
+
* Pattern matches over the Try, applying a handler function based on the variant
|
|
30
|
+
* @param patterns - Object with handler functions for Success and Failure variants
|
|
31
|
+
* @returns The result of applying the matching handler function
|
|
32
|
+
*/
|
|
33
|
+
match<R>(patterns: {
|
|
34
|
+
Success: (value: T) => R;
|
|
35
|
+
Failure: (error: Error) => R;
|
|
36
|
+
}): R;
|
|
37
|
+
} & Typeable<TypeNames> & Valuable<TypeNames, T | Error> & Serializable<T> & Pipe<T> & Foldable<T> & Matchable<T | Error, "Success" | "Failure">;
|
|
38
|
+
declare const Try: (<T>(f: () => T) => Try<T>) & {
|
|
39
|
+
/**
|
|
40
|
+
* Creates a Try from JSON string
|
|
41
|
+
* @param json - The JSON string
|
|
42
|
+
* @returns Try instance
|
|
43
|
+
*/
|
|
44
|
+
fromJSON: <T>(json: string) => Try<T>;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a Try from YAML string
|
|
47
|
+
* @param yaml - The YAML string
|
|
48
|
+
* @returns Try instance
|
|
49
|
+
*/
|
|
50
|
+
fromYAML: <T>(yaml: string) => Try<T>;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a Try from binary string
|
|
53
|
+
* @param binary - The binary string
|
|
54
|
+
* @returns Try instance
|
|
55
|
+
*/
|
|
56
|
+
fromBinary: <T>(binary: string) => Try<T>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export { Try, type TypeNames };
|
package/dist/try/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{G as Try}from'../chunk-5DWCHDSA.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 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { a as Type, c as ArrayFunctor, T as Typeable, V as Valuable } from '../Valuable-CtuVEKTZ.js';
|
|
2
|
+
|
|
3
|
+
type Tuple<T extends Type[]> = {
|
|
4
|
+
get<K extends number>(index: K): T[K];
|
|
5
|
+
map<U extends Type[]>(f: (value: T) => U): Tuple<U>;
|
|
6
|
+
flatMap<U extends Type[]>(f: (value: T) => Tuple<U>): Tuple<U>;
|
|
7
|
+
toArray(): T;
|
|
8
|
+
[Symbol.iterator](): Iterator<T[number]>;
|
|
9
|
+
} & ArrayFunctor<T> & Typeable<"Tuple"> & Valuable<"Tuple", T>;
|
|
10
|
+
declare const Tuple: <T extends Type[]>(values: T) => Tuple<T>;
|
|
11
|
+
|
|
12
|
+
export { Tuple };
|
package/dist/tuple/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{d as Tuple}from'../chunk-7PQA3W7W.mjs';//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functype",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.69",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A smallish functional library for TypeScript",
|
|
6
6
|
"author": "jordan.burke@gmail.com",
|
|
@@ -12,29 +12,30 @@
|
|
|
12
12
|
"homepage": "https://github.com/jordanburke/functype#readme",
|
|
13
13
|
"url": "https://github.com/jordanburke/functype",
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@eslint/compat": "^1.2.
|
|
15
|
+
"@eslint/compat": "^1.2.9",
|
|
16
16
|
"@eslint/eslintrc": "^3.3.1",
|
|
17
|
-
"@eslint/js": "^9.
|
|
18
|
-
"@types/node": "^22.15.
|
|
19
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
20
|
-
"@typescript-eslint/parser": "^8.
|
|
21
|
-
"@vitest/coverage-v8": "^3.
|
|
22
|
-
"@vitest/ui": "^3.
|
|
17
|
+
"@eslint/js": "^9.28.0",
|
|
18
|
+
"@types/node": "^22.15.30",
|
|
19
|
+
"@typescript-eslint/eslint-plugin": "^8.33.1",
|
|
20
|
+
"@typescript-eslint/parser": "^8.33.1",
|
|
21
|
+
"@vitest/coverage-v8": "^3.2.2",
|
|
22
|
+
"@vitest/ui": "^3.2.2",
|
|
23
23
|
"cross-env": "^7.0.3",
|
|
24
|
-
"eslint": "^9.
|
|
25
|
-
"eslint-config-prettier": "^10.1.
|
|
24
|
+
"eslint": "^9.28.0",
|
|
25
|
+
"eslint-config-prettier": "^10.1.5",
|
|
26
|
+
"eslint-plugin-functional": "^9.0.2",
|
|
26
27
|
"eslint-plugin-import": "^2.31.0",
|
|
27
|
-
"eslint-plugin-prettier": "^5.
|
|
28
|
+
"eslint-plugin-prettier": "^5.4.1",
|
|
28
29
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
29
30
|
"fast-check": "^4.1.1",
|
|
30
|
-
"globals": "^16.
|
|
31
|
+
"globals": "^16.2.0",
|
|
31
32
|
"prettier": "^3.5.3",
|
|
32
33
|
"rimraf": "^6.0.1",
|
|
33
34
|
"ts-node": "^10.9.2",
|
|
34
|
-
"tsup": "^8.
|
|
35
|
-
"typedoc": "^0.28.
|
|
35
|
+
"tsup": "^8.5.0",
|
|
36
|
+
"typedoc": "^0.28.5",
|
|
36
37
|
"typescript": "5.8.3",
|
|
37
|
-
"vitest": "^3.
|
|
38
|
+
"vitest": "^3.2.2"
|
|
38
39
|
},
|
|
39
40
|
"types": "./dist/index.d.ts",
|
|
40
41
|
"module": "./dist/index.mjs",
|
|
@@ -129,7 +130,7 @@
|
|
|
129
130
|
"test:ui": "vitest --ui",
|
|
130
131
|
"docs": "typedoc",
|
|
131
132
|
"docs:watch": "typedoc --watch",
|
|
132
|
-
"postdocs": "node -e \"console.log('Documentation generated in ./
|
|
133
|
+
"postdocs": "node -e \"console.log('Documentation generated in ./typedocs')\"",
|
|
133
134
|
"analyze:size": "pnpm build:prod && node ./scripts/analyze-bundle-size.js"
|
|
134
135
|
}
|
|
135
136
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Bundle Size Optimization Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Functype is designed with tree-shaking in mind, allowing you to optimize your application's bundle size by only including the specific modules you need.
|
|
6
|
+
|
|
7
|
+
## Import Strategies
|
|
8
|
+
|
|
9
|
+
### Strategy 1: Selective Module Imports (Recommended)
|
|
10
|
+
|
|
11
|
+
Import only the specific modules you need to reduce bundle size significantly.
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Option } from "functype/option"
|
|
15
|
+
import { Either } from "functype/either"
|
|
16
|
+
|
|
17
|
+
// Usage
|
|
18
|
+
const option = Option.some(42)
|
|
19
|
+
const either = Either.right("value")
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Strategy 2: Direct Constructor Imports (Smallest Bundle)
|
|
23
|
+
|
|
24
|
+
For the most aggressive tree-shaking, import only the specific constructors and functions you need.
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { some, none } from "functype/option"
|
|
28
|
+
import { right } from "functype/either"
|
|
29
|
+
|
|
30
|
+
// Usage
|
|
31
|
+
const option = some(42)
|
|
32
|
+
const none_value = none()
|
|
33
|
+
const either = right("value")
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Bundle Size Comparison
|
|
37
|
+
|
|
38
|
+
| Import Strategy | Approximate Bundle Size | Best For |
|
|
39
|
+
| --------------- | ------------------------ | -------------------------- |
|
|
40
|
+
| Selective | 200-500 bytes per module | Most applications |
|
|
41
|
+
| Direct | <200 bytes per feature | Size-critical applications |
|
|
42
|
+
|
|
43
|
+
## Common Module Sizes
|
|
44
|
+
|
|
45
|
+
| Module | Approximate Size (minified) | Gzipped Size |
|
|
46
|
+
| -------- | --------------------------- | ------------ |
|
|
47
|
+
| Option | ~200 bytes | ~140 bytes |
|
|
48
|
+
| Either | ~290 bytes | ~190 bytes |
|
|
49
|
+
| List | ~170 bytes | ~125 bytes |
|
|
50
|
+
| Try | ~170 bytes | ~125 bytes |
|
|
51
|
+
| Tuple | ~120 bytes | ~100 bytes |
|
|
52
|
+
| FPromise | ~200 bytes | ~140 bytes |
|
|
53
|
+
|
|
54
|
+
## Additional Tips
|
|
55
|
+
|
|
56
|
+
1. **Import Analysis**: Use tools like [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) or [rollup-plugin-visualizer](https://github.com/btd/rollup-plugin-visualizer) to analyze your bundle and identify opportunities for optimization.
|
|
57
|
+
|
|
58
|
+
2. **Dynamic Imports**: Consider using dynamic imports for rarely used functionality:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
// Only load when needed
|
|
62
|
+
const useRareFeature = async () => {
|
|
63
|
+
const { someLargeUtility } = await import("functype/some-large-module")
|
|
64
|
+
return someLargeUtility()
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
3. **Development vs Production**: During development, you might prefer the convenience of importing everything. In production builds, switch to selective imports.
|
|
69
|
+
|
|
70
|
+
4. **Peer Dependencies**: Functype has minimal dependencies, and the only external dependency (`safe-stable-stringify`) is quite small.
|
|
71
|
+
|
|
72
|
+
## Need Help?
|
|
73
|
+
|
|
74
|
+
If you need assistance with optimizing your bundle size further, please open an issue on our GitHub repository.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# FPromise Implementation Assessment
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This document provides an assessment of whether the FPromise implementation is ready to replace the old main branch version, with particular focus on potential impacts to implementing libraries outside this one.
|
|
6
|
+
|
|
7
|
+
## Strengths of the FPromise Implementation
|
|
8
|
+
|
|
9
|
+
1. **Comprehensive Error Handling**: FPromise provides rich error handling capabilities including `mapError`, `tapError`, `recover`, `recoverWith`, `recoverWithF`, `filterError`, and `logError`.
|
|
10
|
+
|
|
11
|
+
2. **Either Integration**: FPromise has built-in conversion to/from Either with `toEither()` and `fromEither()`, which aligns well with the functional programming approach used in the Task implementation.
|
|
12
|
+
|
|
13
|
+
3. **Promise Compatibility**: FPromise implements the PromiseLike interface, ensuring compatibility with async/await and standard Promise chains.
|
|
14
|
+
|
|
15
|
+
4. **Extensive Test Coverage**: The test suite is comprehensive, covering basic functionality, error handling, recovery mechanisms, and real-world scenarios.
|
|
16
|
+
|
|
17
|
+
5. **Retry Mechanisms**: The implementation includes multiple retry strategies (basic retry, retry with backoff, and retry with options).
|
|
18
|
+
|
|
19
|
+
## Potential Compatibility Issues
|
|
20
|
+
|
|
21
|
+
1. **Import Path Differences**: The Task.ts file imports from `"'core/throwable/Throwable"'` and `"'either/Either"'` with unusual quotes, while the actual imports should use `@/` prefix. This might cause issues if external libraries rely on these specific import paths.
|
|
22
|
+
|
|
23
|
+
2. **Type Compatibility**: The Task implementation uses `Either<Throwable, T>` for error handling, while FPromise uses a more generic approach. Libraries expecting specific Either structures might need adjustments.
|
|
24
|
+
|
|
25
|
+
3. **API Surface Changes**: External libraries that directly interact with the Promise implementation might need to adapt to the new methods and patterns provided by FPromise.
|
|
26
|
+
|
|
27
|
+
## Recommendation
|
|
28
|
+
|
|
29
|
+
The FPromise implementation is technically sound and provides significant improvements, but to avoid breaking implementing libraries outside this one:
|
|
30
|
+
|
|
31
|
+
1. **Gradual Migration**: Consider a phased approach where both implementations coexist temporarily.
|
|
32
|
+
|
|
33
|
+
2. **Version Bumping**: This change warrants a major version bump to signal potential breaking changes.
|
|
34
|
+
|
|
35
|
+
3. **Documentation**: Provide clear migration guides for dependent libraries.
|
|
36
|
+
|
|
37
|
+
4. **Import Path Fixes**: Ensure import paths are consistent and follow the project's conventions.
|
|
38
|
+
|
|
39
|
+
5. **Compatibility Layer**: Consider providing a thin compatibility layer for libraries that can't immediately migrate to the new API.
|
|
40
|
+
|
|
41
|
+
## Conclusion
|
|
42
|
+
|
|
43
|
+
The FPromise implementation appears ready to replace the old main branch version from a technical perspective, but careful migration planning is necessary to minimize disruption to implementing libraries.
|
package/readme/HKT.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Higher-Kinded Types (HKT)
|
|
2
|
+
|
|
3
|
+
Higher-kinded types allow for writing generic code that works across different container types like `Option`, `List`, `Either`, and `Try`. This is a powerful abstraction that lets you create algorithms that work with any type that supports certain operations, without having to rewrite them for each specific type.
|
|
4
|
+
|
|
5
|
+
## Introduction
|
|
6
|
+
|
|
7
|
+
In functional programming, many operations like `map`, `flatMap`, or `sequence` follow similar patterns across different data structures. The HKT module provides a unified way to work with these operations for any supporting container type.
|
|
8
|
+
|
|
9
|
+
## Key Concepts
|
|
10
|
+
|
|
11
|
+
1. **Kind**: A type-level function representing a higher-kinded type relationship
|
|
12
|
+
2. **Container Types**: Data structures that contain values (Option, List, Either, etc.)
|
|
13
|
+
3. **Type Constructor**: A function that takes a type and returns a new type
|
|
14
|
+
|
|
15
|
+
## Basic Operations
|
|
16
|
+
|
|
17
|
+
### Map
|
|
18
|
+
|
|
19
|
+
Apply a function to a value inside a container:
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { Option, HKT } from "functype"
|
|
23
|
+
|
|
24
|
+
const option = Option(42)
|
|
25
|
+
const doubled = HKT.map(option, (x) => x * 2) // Option(84)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### FlatMap
|
|
29
|
+
|
|
30
|
+
Apply a function that returns a container to a value inside a container, then flatten the result:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
const option = Option(42)
|
|
34
|
+
const result = HKT.flatMap(option, (x) => Option(x * 2)) // Option(84)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Flatten
|
|
38
|
+
|
|
39
|
+
Flatten a nested container:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const nestedOption = Option(Option(42))
|
|
43
|
+
const flattened = HKT.flatten(nestedOption) // Option(42)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Advanced Operations
|
|
47
|
+
|
|
48
|
+
### Sequence
|
|
49
|
+
|
|
50
|
+
Transform a container of containers into a container of container (e.g., `Option<List<A>>` to `List<Option<A>>`):
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
const optionOfList = Option(List([1, 2, 3]))
|
|
54
|
+
const listOfOptions = HKT.sequence(optionOfList)
|
|
55
|
+
// List([Option(1), Option(2), Option(3)])
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Traverse
|
|
59
|
+
|
|
60
|
+
Transform each element in a container using a function that returns another container type, then sequence the results:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
const list = List([1, 2, 3])
|
|
64
|
+
const result = HKT.traverse(list, (x) => Option(x * 2))
|
|
65
|
+
// Option(List([2, 4, 6]))
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Applicative (ap)
|
|
69
|
+
|
|
70
|
+
Apply a function inside a container to a value inside another container:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const optionFn = Option((x: number) => x * 2)
|
|
74
|
+
const optionValue = Option(21)
|
|
75
|
+
const result = HKT.ap(optionFn, optionValue) // Option(42)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Supported Container Types
|
|
79
|
+
|
|
80
|
+
The HKT module currently supports the following container types:
|
|
81
|
+
|
|
82
|
+
- `Option<A>`
|
|
83
|
+
- `List<A>`
|
|
84
|
+
- `Either<E, A>`
|
|
85
|
+
- `Try<A>`
|
|
86
|
+
|
|
87
|
+
## Creating Generic Algorithms
|
|
88
|
+
|
|
89
|
+
The power of HKT is in creating algorithms that work with any container type:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
// A function that works with any container implementing map
|
|
93
|
+
function increment<F extends (a: number) => any>(container: Kind<F, number>): Kind<F, number> {
|
|
94
|
+
return HKT.map(container, (x) => x + 1)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Works with any container
|
|
98
|
+
increment(Option(41)) // Option(42)
|
|
99
|
+
increment(List([1, 2, 3])) // List([2, 3, 4])
|
|
100
|
+
increment(Right<string, number>(41)) // Right(42)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Implementing Your Own Container Types
|
|
104
|
+
|
|
105
|
+
To make your custom container types work with HKT, you need to:
|
|
106
|
+
|
|
107
|
+
1. Implement the appropriate methods (`map`, `flatMap`, etc.)
|
|
108
|
+
2. Add type checking in the HKT functions
|
|
109
|
+
|
|
110
|
+
This allows seamless integration with the rest of the functional programming ecosystem.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Functype Roadmap (2025-2026)
|
|
2
|
+
|
|
3
|
+
This roadmap outlines the planned development path for the Functype library, focusing on expanding functionality, improving performance, ensuring API consistency, and enhancing TypeScript integration.
|
|
4
|
+
|
|
5
|
+
## Q2 2025: Core Functional Data Types
|
|
6
|
+
|
|
7
|
+
### Lazy Evaluation
|
|
8
|
+
|
|
9
|
+
- [ ] Implement `LazyList` / `Stream` for efficient processing of potentially infinite sequences
|
|
10
|
+
- [ ] Add common operations: `map`, `filter`, `take`, `drop`, etc.
|
|
11
|
+
- [ ] Implement memoization for evaluated values
|
|
12
|
+
|
|
13
|
+
### Validation Type
|
|
14
|
+
|
|
15
|
+
- [ ] Create `Validation` data type for applicative validation
|
|
16
|
+
- [ ] Support collecting multiple errors (unlike Either which short-circuits)
|
|
17
|
+
- [ ] Add utilities for combining validation results
|
|
18
|
+
|
|
19
|
+
### Performance Foundation
|
|
20
|
+
|
|
21
|
+
- [ ] Add memoization utilities for expensive function calls
|
|
22
|
+
- [ ] Implement a basic benchmarking suite for measuring performance
|
|
23
|
+
- [ ] Standardize performance metrics across data structures
|
|
24
|
+
|
|
25
|
+
## Q3 2025: Advanced Functional Patterns & Optimizations
|
|
26
|
+
|
|
27
|
+
### Type Classes
|
|
28
|
+
|
|
29
|
+
- [x] Implement `Foldable` typeclass with fold, foldLeft, and foldRight methods
|
|
30
|
+
- [x] Implement `Matchable` typeclass for pattern matching
|
|
31
|
+
- [ ] Implement proper `Functor` and `Monad` typeclasses
|
|
32
|
+
- [ ] Add `Applicative` typeclass
|
|
33
|
+
- [ ] Support `Traversable` with comprehensive HKT
|
|
34
|
+
|
|
35
|
+
### Monad Implementations
|
|
36
|
+
|
|
37
|
+
- [ ] Implement `Reader` monad for dependency injection
|
|
38
|
+
- [ ] Add `State` monad for managing state transformations
|
|
39
|
+
- [ ] Create `IO` monad for pure handling of side effects
|
|
40
|
+
- [ ] Add comprehensive documentation and examples
|
|
41
|
+
|
|
42
|
+
### Performance Improvements
|
|
43
|
+
|
|
44
|
+
- [ ] Implement structural sharing for immutable collections
|
|
45
|
+
- [ ] Optimize recursive operations for large data structures
|
|
46
|
+
- [ ] Add performance comparison against other FP libraries
|
|
47
|
+
|
|
48
|
+
### Lenses & Optics
|
|
49
|
+
|
|
50
|
+
- [ ] Implement lens abstraction for immutable updates
|
|
51
|
+
- [ ] Add prism implementation for optional data
|
|
52
|
+
- [ ] Create utilities for composing lenses and prisms
|
|
53
|
+
|
|
54
|
+
## Q4 2025: TypeScript Enhancements & API Consistency
|
|
55
|
+
|
|
56
|
+
### TypeScript Integration
|
|
57
|
+
|
|
58
|
+
- [x] Add support for higher-kinded types
|
|
59
|
+
- [ ] Remove `any` from HKT
|
|
60
|
+
- [x] Implement branded/nominal types for stronger type safety
|
|
61
|
+
- [ ] Add type-level utilities using newer TypeScript features
|
|
62
|
+
- [ ] Leverage const type parameters and tuple manipulation
|
|
63
|
+
|
|
64
|
+
### API Normalization
|
|
65
|
+
|
|
66
|
+
- [ ] Review and standardize API across all modules
|
|
67
|
+
- [ ] Ensure consistent implementation of the Scala-inspired pattern
|
|
68
|
+
- [ ] Standardize import patterns (@imports throughout)
|
|
69
|
+
- [ ] Create migration guides for API changes
|
|
70
|
+
|
|
71
|
+
## Q1 2026: Testing, Documentation & Community Support
|
|
72
|
+
|
|
73
|
+
### Testing Expansion
|
|
74
|
+
|
|
75
|
+
- [ ] Add test coverage metrics and set coverage goals
|
|
76
|
+
- [ ] Expand property-based testing across all modules
|
|
77
|
+
- [ ] Create interoperability tests with popular libraries
|
|
78
|
+
- [ ] Add more specialized test cases for error handling
|
|
79
|
+
|
|
80
|
+
### Documentation & Examples
|
|
81
|
+
|
|
82
|
+
- [ ] Add comprehensive documentation for all modules
|
|
83
|
+
- [ ] Create step-by-step migration guides from imperative to functional
|
|
84
|
+
- [ ] Add real-world examples showcasing practical applications
|
|
85
|
+
- [ ] Create tutorial sections for beginners
|
|
86
|
+
|
|
87
|
+
### Community Engagement
|
|
88
|
+
|
|
89
|
+
- [ ] Create contribution guidelines and templates
|
|
90
|
+
- [ ] Set up automated issue/PR handling
|
|
91
|
+
- [ ] Establish regular release schedule
|
|
92
|
+
- [ ] Add community forum/discussion platform
|
|
93
|
+
|
|
94
|
+
## Ongoing Priorities
|
|
95
|
+
|
|
96
|
+
### Compatibility
|
|
97
|
+
|
|
98
|
+
- [ ] Ensure compatibility with Node.js LTS versions
|
|
99
|
+
- [ ] Maintain browser compatibility
|
|
100
|
+
- [ ] Support for Deno and other runtimes
|
|
101
|
+
- [ ] Test with various bundlers (webpack, esbuild, etc.)
|
|
102
|
+
|
|
103
|
+
### Bundle Size
|
|
104
|
+
|
|
105
|
+
- [x] Optimize tree-shaking
|
|
106
|
+
- [x] Provide guidance on importing only needed modules
|
|
107
|
+
- [x] Add bundle size monitoring to CI/CD
|
|
108
|
+
|
|
109
|
+
### Community Feedback
|
|
110
|
+
|
|
111
|
+
- [ ] Regular review of GitHub issues and feature requests
|
|
112
|
+
- [ ] Prioritization based on community needs
|
|
113
|
+
- [ ] Transparent development process
|