fp-pack 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +135 -47
- package/dist/fp-pack.umd.js +1 -1
- package/dist/fp-pack.umd.js.map +1 -1
- package/dist/implement/async/pipeAsync.d.ts +3 -0
- package/dist/implement/async/pipeAsync.d.ts.map +1 -1
- package/dist/implement/async/pipeAsync.mjs.map +1 -1
- package/dist/implement/async/pipeAsyncSideEffect.d.ts +3 -0
- package/dist/implement/async/pipeAsyncSideEffect.d.ts.map +1 -1
- package/dist/implement/async/pipeAsyncSideEffect.mjs.map +1 -1
- package/dist/implement/async/pipeAsyncSideEffectStrict.d.ts +6 -0
- package/dist/implement/async/pipeAsyncSideEffectStrict.d.ts.map +1 -1
- package/dist/implement/async/pipeAsyncSideEffectStrict.mjs.map +1 -1
- package/dist/implement/composition/curry.d.ts +5 -5
- package/dist/implement/composition/curry.d.ts.map +1 -1
- package/dist/implement/composition/curry.mjs.map +1 -1
- package/dist/implement/composition/from.d.ts +5 -1
- package/dist/implement/composition/from.d.ts.map +1 -1
- package/dist/implement/composition/from.mjs +4 -3
- package/dist/implement/composition/from.mjs.map +1 -1
- package/dist/implement/composition/index.d.ts +3 -0
- package/dist/implement/composition/index.d.ts.map +1 -1
- package/dist/implement/composition/pipe.d.ts +3 -0
- package/dist/implement/composition/pipe.d.ts.map +1 -1
- package/dist/implement/composition/pipe.mjs.map +1 -1
- package/dist/implement/composition/pipe.type-test.d.ts +38 -8
- package/dist/implement/composition/pipe.type-test.d.ts.map +1 -1
- package/dist/implement/composition/pipeSideEffect.d.ts +3 -0
- package/dist/implement/composition/pipeSideEffect.d.ts.map +1 -1
- package/dist/implement/composition/pipeSideEffect.mjs.map +1 -1
- package/dist/implement/composition/pipeSideEffectStrict.d.ts +6 -0
- package/dist/implement/composition/pipeSideEffectStrict.d.ts.map +1 -1
- package/dist/implement/composition/pipeSideEffectStrict.mjs.map +1 -1
- package/dist/implement/composition/sideEffect.d.ts +1 -1
- package/dist/implement/composition/sideEffect.d.ts.map +1 -1
- package/dist/implement/composition/sideEffect.mjs.map +1 -1
- package/dist/implement/object/assocPath.d.ts +2 -1
- package/dist/implement/object/assocPath.d.ts.map +1 -1
- package/dist/implement/object/assocPath.mjs.map +1 -1
- package/dist/implement/object/dissocPath.d.ts +2 -1
- package/dist/implement/object/dissocPath.d.ts.map +1 -1
- package/dist/implement/object/dissocPath.mjs.map +1 -1
- package/dist/implement/object/index.d.ts +1 -0
- package/dist/implement/object/index.d.ts.map +1 -1
- package/dist/implement/object/path.d.ts +4 -2
- package/dist/implement/object/path.d.ts.map +1 -1
- package/dist/implement/object/path.mjs.map +1 -1
- package/dist/implement/object/pathKey.d.ts +2 -0
- package/dist/implement/object/pathKey.d.ts.map +1 -0
- package/dist/implement/object/pathOr.d.ts +5 -3
- package/dist/implement/object/pathOr.d.ts.map +1 -1
- package/dist/implement/object/pathOr.mjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/skills/fp-pack/SKILL.md +30 -20
- package/dist/skills/fp-pack.md +30 -20
- package/dist/stream/index.d.ts +1 -0
- package/dist/stream/index.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/implement/async/pipeAsync.ts +6 -0
- package/src/implement/async/pipeAsyncSideEffect.ts +7 -0
- package/src/implement/async/pipeAsyncSideEffectStrict.ts +10 -0
- package/src/implement/composition/curry.ts +5 -5
- package/src/implement/composition/from.ts +9 -2
- package/src/implement/composition/index.ts +3 -0
- package/src/implement/composition/pipe.ts +4 -0
- package/src/implement/composition/pipe.type-test.ts +67 -1
- package/src/implement/composition/pipeSideEffect.ts +5 -0
- package/src/implement/composition/pipeSideEffectStrict.ts +10 -0
- package/src/implement/composition/sideEffect.ts +1 -1
- package/src/implement/object/assocPath.ts +2 -2
- package/src/implement/object/dissocPath.ts +2 -2
- package/src/implement/object/index.ts +1 -0
- package/src/implement/object/path.ts +5 -3
- package/src/implement/object/pathKey.ts +1 -0
- package/src/implement/object/pathOr.ts +6 -4
- package/src/index.ts +3 -0
- package/src/stream/index.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dissocPath.mjs","sources":["../../../src/implement/object/dissocPath.ts"],"sourcesContent":["import curry from '../composition/curry';\
|
|
1
|
+
{"version":3,"file":"dissocPath.mjs","sources":["../../../src/implement/object/dissocPath.ts"],"sourcesContent":["import curry from '../composition/curry';\nimport type { PathKey } from './pathKey';\n\nconst isIndexKey = (key: PathKey): key is number | `${number}` => {\n if (typeof key === 'number') {\n return Number.isInteger(key);\n }\n if (typeof key === 'string') {\n return /^-?\\d+$/.test(key);\n }\n return false;\n};\n\nconst normalizeIndex = (key: number | `${number}`, length: number) => {\n const raw = typeof key === 'number' ? key : Number(key);\n if (Number.isNaN(raw)) {\n return -1;\n }\n if (raw < 0) {\n return length + raw;\n }\n return raw;\n};\n\nconst isObjectLike = (value: unknown): value is Record<PropertyKey, unknown> =>\n value !== null && typeof value === 'object';\n\ntype DissocPath = {\n <T = unknown>(...args: [pathArray: PathKey[]]): (obj: T) => T;\n <T = unknown>(...args: [pathArray: PathKey[], obj: T]): T;\n};\n\n/**\n * dissocPath - 경로 기반 값 제거 (불변)\n */\nfunction dissocPath<T = unknown>(pathArray: PathKey[], obj: T): T {\n if (pathArray.length === 0) {\n return obj;\n }\n\n if (!isObjectLike(obj)) {\n return obj;\n }\n\n const [key, ...rest] = pathArray;\n\n if (Array.isArray(obj) && isIndexKey(key)) {\n const index = normalizeIndex(key, obj.length);\n if (index < 0 || index >= obj.length) {\n return obj;\n }\n\n const result = obj.slice();\n if (rest.length === 0) {\n result.splice(index, 1);\n return result as unknown as T;\n }\n\n const nextValue = dissocPath(rest, result[index]);\n result[index] = nextValue;\n return result as unknown as T;\n }\n\n if (!Object.prototype.hasOwnProperty.call(obj, key)) {\n return obj;\n }\n\n if (rest.length === 0) {\n const { [key]: _removed, ...restObj } = obj as Record<PropertyKey, unknown>;\n return restObj as T;\n }\n\n const result = { ...(obj as object) } as Record<PropertyKey, unknown>;\n result[key] = dissocPath(rest, result[key]);\n return result as T;\n}\n\nconst curriedDissocPath = curry(dissocPath) as DissocPath;\nexport default curriedDissocPath;\nexport type { PathKey };\n"],"names":["isIndexKey","key","normalizeIndex","length","raw","isObjectLike","value","dissocPath","pathArray","obj","rest","index","result","nextValue","_removed","restObj","curriedDissocPath","curry"],"mappings":";AAGA,MAAMA,IAAa,CAACC,MACd,OAAOA,KAAQ,WACV,OAAO,UAAUA,CAAG,IAEzB,OAAOA,KAAQ,WACV,UAAU,KAAKA,CAAG,IAEpB,IAGHC,IAAiB,CAACD,GAA2BE,MAAmB;AACpE,QAAMC,IAAM,OAAOH,KAAQ,WAAWA,IAAM,OAAOA,CAAG;AACtD,SAAI,OAAO,MAAMG,CAAG,IACX,KAELA,IAAM,IACDD,IAASC,IAEXA;AACT,GAEMC,IAAe,CAACC,MACpBA,MAAU,QAAQ,OAAOA,KAAU;AAUrC,SAASC,EAAwBC,GAAsBC,GAAW;AAKhE,MAJID,EAAU,WAAW,KAIrB,CAACH,EAAaI,CAAG;AACnB,WAAOA;AAGT,QAAM,CAACR,GAAK,GAAGS,CAAI,IAAIF;AAEvB,MAAI,MAAM,QAAQC,CAAG,KAAKT,EAAWC,CAAG,GAAG;AACzC,UAAMU,IAAQT,EAAeD,GAAKQ,EAAI,MAAM;AAC5C,QAAIE,IAAQ,KAAKA,KAASF,EAAI;AAC5B,aAAOA;AAGT,UAAMG,IAASH,EAAI,MAAA;AACnB,QAAIC,EAAK,WAAW;AAClBE,aAAAA,EAAO,OAAOD,GAAO,CAAC,GACfC;AAGT,UAAMC,IAAYN,EAAWG,GAAME,EAAOD,CAAK,CAAC;AAChDC,WAAAA,EAAOD,CAAK,IAAIE,GACTD;AAAAA,EACT;AAEA,MAAI,CAAC,OAAO,UAAU,eAAe,KAAKH,GAAKR,CAAG;AAChD,WAAOQ;AAGT,MAAIC,EAAK,WAAW,GAAG;AACrB,UAAM,EAAE,CAACT,CAAG,GAAGa,GAAU,GAAGC,MAAYN;AACxC,WAAOM;AAAA,EACT;AAEA,QAAMH,IAAS,EAAE,GAAIH,EAAA;AACrB,SAAAG,EAAOX,CAAG,IAAIM,EAAWG,GAAME,EAAOX,CAAG,CAAC,GACnCW;AACT;AAEA,MAAMI,IAAoBC,EAAMV,CAAU;"}
|
|
@@ -19,4 +19,5 @@ export { default as mapValues } from './mapValues';
|
|
|
19
19
|
export { default as evolve } from './evolve';
|
|
20
20
|
export { default as has } from './has';
|
|
21
21
|
export { default as hasPath } from './hasPath';
|
|
22
|
+
export type { PathKey } from './pathKey';
|
|
22
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/implement/object/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAA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AACnD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { PathKey } from './pathKey';
|
|
1
2
|
type Path = {
|
|
2
|
-
(pathArray:
|
|
3
|
-
<T>(...args: [pathArray:
|
|
3
|
+
(pathArray: PathKey[]): <T>(obj: any) => T | undefined;
|
|
4
|
+
<T>(...args: [pathArray: PathKey[], obj: any]): T | undefined;
|
|
4
5
|
};
|
|
5
6
|
declare const curriedPath: Path;
|
|
6
7
|
export default curriedPath;
|
|
8
|
+
export type { PathKey };
|
|
7
9
|
//# sourceMappingURL=path.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../../src/implement/object/path.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../../src/implement/object/path.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,KAAK,IAAI,GAAG;IACV,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,SAAS,CAAC;IACvD,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;CAC/D,CAAC;AASF,QAAA,MAAM,WAAW,EAAkB,IAAI,CAAC;AACxC,eAAe,WAAW,CAAC;AAC3B,YAAY,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.mjs","sources":["../../../src/implement/object/path.ts"],"sourcesContent":["import curry from '../composition/curry';\n\ntype Path = {\n (pathArray:
|
|
1
|
+
{"version":3,"file":"path.mjs","sources":["../../../src/implement/object/path.ts"],"sourcesContent":["import curry from '../composition/curry';\nimport type { PathKey } from './pathKey';\n\ntype Path = {\n (pathArray: PathKey[]): <T>(obj: any) => T | undefined;\n <T>(...args: [pathArray: PathKey[], obj: any]): T | undefined;\n};\n\n/**\n * path - 안전한 깊은 프로퍼티 접근\n */\nfunction path<T>(pathArray: PathKey[], obj: any): T | undefined {\n return pathArray.reduce((current, key) => (current == null ? undefined : current[key]), obj) as T | undefined;\n}\n\nconst curriedPath = curry(path) as Path;\nexport default curriedPath;\nexport type { PathKey };\n"],"names":["path","pathArray","obj","current","key","curriedPath","curry"],"mappings":";AAWA,SAASA,EAAQC,GAAsBC,GAAyB;AAC9D,SAAOD,EAAU,OAAO,CAACE,GAASC,MAAuCD,IAAQC,CAAG,GAAIF,CAAG;AAC7F;AAEA,MAAMG,IAAcC,EAAMN,CAAI;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pathKey.d.ts","sourceRoot":"","sources":["../../../src/implement/object/pathKey.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { PathKey } from './pathKey';
|
|
1
2
|
type PathOr = {
|
|
2
|
-
<D>(...args: [defaultValue: D]): <T>(pathArray:
|
|
3
|
-
<D>(...args: [defaultValue: D, pathArray:
|
|
4
|
-
<T, D>(...args: [defaultValue: D, pathArray:
|
|
3
|
+
<D>(...args: [defaultValue: D]): <T>(pathArray: PathKey[]) => (obj: any) => T | D;
|
|
4
|
+
<D>(...args: [defaultValue: D, pathArray: PathKey[]]): <T>(obj: any) => T | D;
|
|
5
|
+
<T, D>(...args: [defaultValue: D, pathArray: PathKey[], obj: any]): T | D;
|
|
5
6
|
};
|
|
6
7
|
declare const curriedPathOr: PathOr;
|
|
7
8
|
export default curriedPathOr;
|
|
9
|
+
export type { PathKey };
|
|
8
10
|
//# sourceMappingURL=pathOr.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathOr.d.ts","sourceRoot":"","sources":["../../../src/implement/object/pathOr.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pathOr.d.ts","sourceRoot":"","sources":["../../../src/implement/object/pathOr.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,KAAK,MAAM,GAAG;IACZ,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IAClF,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,YAAY,EAAE,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9E,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,YAAY,EAAE,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CAC3E,CAAC;AAUF,QAAA,MAAM,aAAa,EAAoB,MAAM,CAAC;AAC9C,eAAe,aAAa,CAAC;AAC7B,YAAY,EAAE,OAAO,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathOr.mjs","sources":["../../../src/implement/object/pathOr.ts"],"sourcesContent":["import curry from '../composition/curry';\n\ntype PathOr = {\n <D>(...args: [defaultValue: D]): <T>(pathArray:
|
|
1
|
+
{"version":3,"file":"pathOr.mjs","sources":["../../../src/implement/object/pathOr.ts"],"sourcesContent":["import curry from '../composition/curry';\nimport type { PathKey } from './pathKey';\n\ntype PathOr = {\n <D>(...args: [defaultValue: D]): <T>(pathArray: PathKey[]) => (obj: any) => T | D;\n <D>(...args: [defaultValue: D, pathArray: PathKey[]]): <T>(obj: any) => T | D;\n <T, D>(...args: [defaultValue: D, pathArray: PathKey[], obj: any]): T | D;\n};\n\n/**\n * pathOr - 기본값이 있는 깊은 프로퍼티 접근\n */\nfunction pathOr<T, D>(defaultValue: D, pathArray: PathKey[], obj: any): T | D {\n const value = pathArray.reduce((current, key) => (current == null ? undefined : current[key]), obj) as T | undefined;\n return value == null ? defaultValue : value;\n}\n\nconst curriedPathOr = curry(pathOr) as PathOr;\nexport default curriedPathOr;\nexport type { PathKey };\n"],"names":["pathOr","defaultValue","pathArray","obj","value","current","key","curriedPathOr","curry"],"mappings":";AAYA,SAASA,EAAaC,GAAiBC,GAAsBC,GAAiB;AAC5E,QAAMC,IAAQF,EAAU,OAAO,CAACG,GAASC,MAAuCD,IAAQC,CAAG,GAAIH,CAAG;AAClG,SAAOC,KAAgBH;AACzB;AAEA,MAAMM,IAAgBC,EAAMR,CAAM;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,4 +8,5 @@ export * from './implement/string';
|
|
|
8
8
|
export * from './implement/async';
|
|
9
9
|
export * from './implement/nullable';
|
|
10
10
|
export * from './implement/debug';
|
|
11
|
+
export type { AnyIterable, AnyIterableInput, PromiseLikeValue } from './stream/utils';
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,gBAAgB,CAAC;AAGxB,cAAc,yBAAyB,CAAC;AAGxC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,gBAAgB,CAAC;AAGxB,cAAc,yBAAyB,CAAC;AAGxC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,mBAAmB,CAAC;AAGlC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,mBAAmB,CAAC;AAGlC,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -7,7 +7,7 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# fp-pack AI Agent Skills
|
|
9
9
|
|
|
10
|
-
Document Version: 0.
|
|
10
|
+
Document Version: 0.6.0
|
|
11
11
|
|
|
12
12
|
This document provides guidelines for AI coding assistants when working in projects that use fp-pack. Follow these instructions to write clean, declarative, functional code using fp-pack's utilities.
|
|
13
13
|
|
|
@@ -129,7 +129,7 @@ const finalValue = runPipeResult(processDataPipeline(input));
|
|
|
129
129
|
**Key SideEffect functions:**
|
|
130
130
|
- `SideEffect.of(fn, label?)` - Create a side effect container
|
|
131
131
|
- `isSideEffect(value)` - Type guard for **runtime checking** whether a value is a SideEffect
|
|
132
|
-
- `runPipeResult<T, R>(result)` - Execute SideEffect or return value (call **OUTSIDE** pipelines
|
|
132
|
+
- `runPipeResult<T, R>(result)` - Execute SideEffect or return value (call **OUTSIDE** pipelines). If the input type is precise, inference is preserved. If the input is widened to `SideEffect<any>` or `any`, the result becomes `any` unless you provide generics.
|
|
133
133
|
- `matchSideEffect(result, { value, effect })` - Pattern match on result
|
|
134
134
|
|
|
135
135
|
**Type-safe result handling:**
|
|
@@ -147,32 +147,34 @@ const processNumbers = pipeSideEffect(
|
|
|
147
147
|
|
|
148
148
|
const result = processNumbers([1, 2, 3, 4, 5]);
|
|
149
149
|
|
|
150
|
-
// ✅ CORRECT: Use isSideEffect for runtime checking
|
|
150
|
+
// ✅ CORRECT: Use isSideEffect for runtime checking
|
|
151
151
|
if (!isSideEffect(result)) {
|
|
152
152
|
// TypeScript knows: result is number[]
|
|
153
153
|
const sum: number = result.reduce((a, b) => a + b, 0);
|
|
154
154
|
} else {
|
|
155
155
|
// TypeScript knows: result is SideEffect<string>
|
|
156
|
-
//
|
|
157
|
-
const error = runPipeResult
|
|
156
|
+
// runPipeResult returns number[] | string (not fully narrowed)
|
|
157
|
+
const error = runPipeResult(result); // number[] | string
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
//
|
|
161
|
-
const
|
|
160
|
+
// ⚠️ If the result type is widened to SideEffect<any>, inference is lost
|
|
161
|
+
const widened: number[] | SideEffect<any> = result;
|
|
162
|
+
const unsafeValue = runPipeResult(widened); // number[] | any
|
|
162
163
|
|
|
163
|
-
// ✅ CORRECT: Provide generics to
|
|
164
|
-
const
|
|
164
|
+
// ✅ CORRECT: Provide generics to recover a safe union
|
|
165
|
+
const safeValue = runPipeResult<number[], string>(result); // result: number[] | string (union type - safe but not narrowed)
|
|
165
166
|
```
|
|
166
167
|
|
|
167
168
|
**⚠️ CRITICAL: runPipeResult Type Safety**
|
|
168
169
|
|
|
169
170
|
`runPipeResult<T, R=any>` has a default type parameter `R=any`. This means:
|
|
170
171
|
|
|
171
|
-
-
|
|
172
|
-
-
|
|
173
|
-
- ✅ **With
|
|
172
|
+
- ✅ **Precise input types**: `T | SideEffect<'E'>` preserves `T | 'E'` without extra annotations.
|
|
173
|
+
- ⚠️ **Widened inputs**: `T | SideEffect<any>` (or `any`) collapses to `any`.
|
|
174
|
+
- ✅ **With generics**: `runPipeResult<SuccessType, ErrorType>(result)` restores a safe union when inference is lost.
|
|
175
|
+
- ✅ **With isSideEffect**: Prefer for runtime narrowing when you need branch-specific types.
|
|
174
176
|
|
|
175
|
-
|
|
177
|
+
Provide generics when inference is lost; prefer `isSideEffect` for precise narrowing.
|
|
176
178
|
|
|
177
179
|
## Stream Functions - Lazy Iterable Processing
|
|
178
180
|
|
|
@@ -526,13 +528,13 @@ const gradeToLetter = cond([
|
|
|
526
528
|
### 6.1 Type-Safety Tips (prop/ifElse/cond)
|
|
527
529
|
|
|
528
530
|
- `prop` returns `T[K] | undefined`. Use `propOr` (or guard) before array operations.
|
|
529
|
-
- `ifElse` expects **functions** for both branches. If you already have a value, wrap it: `() => value
|
|
530
|
-
- Use `from(value)` when you need a unary function that ignores input (handy for `ifElse` branches).
|
|
531
|
+
- `ifElse` expects **functions** for both branches. If you already have a value, wrap it: `() => value` or use `from(value)` for cleaner constant branches.
|
|
532
|
+
- Use `from(value)` when you need a unary function that ignores input (handy for `ifElse`/`cond` branches and data-first patterns). Pipelines that start with `from(...)` can be called without an initial input value.
|
|
531
533
|
- `cond` returns `R | undefined`. Add a default branch and coalesce when you need a strict result.
|
|
532
534
|
- In `pipeSideEffect`, keep step return types aligned to avoid wide unions.
|
|
533
535
|
|
|
534
536
|
```typescript
|
|
535
|
-
import { pipe, propOr, append, assoc, ifElse, cond, from } from 'fp-pack';
|
|
537
|
+
import { pipe, propOr, append, assoc, ifElse, cond, from, filter, map } from 'fp-pack';
|
|
536
538
|
|
|
537
539
|
// propOr keeps the type strict for array ops
|
|
538
540
|
const addTodo = (text: string, state: AppState) =>
|
|
@@ -549,13 +551,21 @@ const toggleTodo = (id: string) => ifElse(
|
|
|
549
551
|
(todo) => todo
|
|
550
552
|
);
|
|
551
553
|
|
|
552
|
-
// from is useful for constant branches
|
|
554
|
+
// from is useful for constant branches - cleaner than () => value
|
|
553
555
|
const statusLabel = ifElse(
|
|
554
556
|
(score: number) => score >= 60,
|
|
555
|
-
from('pass'),
|
|
557
|
+
from('pass'), // Constant value
|
|
556
558
|
from('fail')
|
|
557
559
|
);
|
|
558
560
|
|
|
561
|
+
// Data-first pattern with from: inject data into pipeline
|
|
562
|
+
const processData = pipe(
|
|
563
|
+
from([1, 2, 3, 4, 5]),
|
|
564
|
+
filter((n: number) => n % 2 === 0),
|
|
565
|
+
map(n => n * 2)
|
|
566
|
+
);
|
|
567
|
+
const result = processData(); // [4, 8]
|
|
568
|
+
|
|
559
569
|
// cond still returns R | undefined, so coalesce if needed
|
|
560
570
|
const grade = (score: number) =>
|
|
561
571
|
cond([
|
|
@@ -672,8 +682,8 @@ const updateUser = assoc('lastLogin', new Date());
|
|
|
672
682
|
- **Pure async operations**: `pipeAsync`
|
|
673
683
|
- **Error handling with SideEffect**: `pipeSideEffect` (sync) / `pipeAsyncSideEffect` (async)
|
|
674
684
|
- **Strict SideEffect unions**: `pipeSideEffectStrict` (sync) / `pipeAsyncSideEffectStrict` (async)
|
|
675
|
-
- **Type-safe result handling**: `isSideEffect` for precise type narrowing (
|
|
676
|
-
- **Execute SideEffect**: `runPipeResult` (call OUTSIDE pipelines).
|
|
685
|
+
- **Type-safe result handling**: `isSideEffect` for precise type narrowing (prefer this when you need branch-specific types)
|
|
686
|
+
- **Execute SideEffect**: `runPipeResult` (call OUTSIDE pipelines). If the input is widened to `SideEffect<any>`/`any`, the result becomes `any`; provide generics to recover
|
|
677
687
|
- **Large datasets**: `stream/*` functions
|
|
678
688
|
- **Conditionals**: `ifElse`, `when`, `unless`, `cond`
|
|
679
689
|
- **Object access**: `prop`, `propStrict`, `path`, `pick`, `omit`
|
package/dist/skills/fp-pack.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# fp-pack AI Agent Skills
|
|
2
2
|
|
|
3
|
-
Document Version: 0.
|
|
3
|
+
Document Version: 0.6.0
|
|
4
4
|
|
|
5
5
|
This document provides guidelines for AI coding assistants when working in projects that use fp-pack. Follow these instructions to write clean, declarative, functional code using fp-pack's utilities.
|
|
6
6
|
|
|
@@ -122,7 +122,7 @@ const finalValue = runPipeResult(processDataPipeline(input));
|
|
|
122
122
|
**Key SideEffect functions:**
|
|
123
123
|
- `SideEffect.of(fn, label?)` - Create a side effect container
|
|
124
124
|
- `isSideEffect(value)` - Type guard for **runtime checking** whether a value is a SideEffect
|
|
125
|
-
- `runPipeResult<T, R>(result)` - Execute SideEffect or return value (call **OUTSIDE** pipelines
|
|
125
|
+
- `runPipeResult<T, R>(result)` - Execute SideEffect or return value (call **OUTSIDE** pipelines). If the input type is precise, inference is preserved. If the input is widened to `SideEffect<any>` or `any`, the result becomes `any` unless you provide generics.
|
|
126
126
|
- `matchSideEffect(result, { value, effect })` - Pattern match on result
|
|
127
127
|
|
|
128
128
|
**Type-safe result handling:**
|
|
@@ -140,32 +140,34 @@ const processNumbers = pipeSideEffect(
|
|
|
140
140
|
|
|
141
141
|
const result = processNumbers([1, 2, 3, 4, 5]);
|
|
142
142
|
|
|
143
|
-
// ✅ CORRECT: Use isSideEffect for runtime checking
|
|
143
|
+
// ✅ CORRECT: Use isSideEffect for runtime checking
|
|
144
144
|
if (!isSideEffect(result)) {
|
|
145
145
|
// TypeScript knows: result is number[]
|
|
146
146
|
const sum: number = result.reduce((a, b) => a + b, 0);
|
|
147
147
|
} else {
|
|
148
148
|
// TypeScript knows: result is SideEffect<string>
|
|
149
|
-
//
|
|
150
|
-
const error = runPipeResult
|
|
149
|
+
// runPipeResult returns number[] | string (not fully narrowed)
|
|
150
|
+
const error = runPipeResult(result); // number[] | string
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
//
|
|
154
|
-
const
|
|
153
|
+
// ⚠️ If the result type is widened to SideEffect<any>, inference is lost
|
|
154
|
+
const widened: number[] | SideEffect<any> = result;
|
|
155
|
+
const unsafeValue = runPipeResult(widened); // number[] | any
|
|
155
156
|
|
|
156
|
-
// ✅ CORRECT: Provide generics to
|
|
157
|
-
const
|
|
157
|
+
// ✅ CORRECT: Provide generics to recover a safe union
|
|
158
|
+
const safeValue = runPipeResult<number[], string>(result); // result: number[] | string (union type - safe but not narrowed)
|
|
158
159
|
```
|
|
159
160
|
|
|
160
161
|
**⚠️ CRITICAL: runPipeResult Type Safety**
|
|
161
162
|
|
|
162
163
|
`runPipeResult<T, R=any>` has a default type parameter `R=any`. This means:
|
|
163
164
|
|
|
164
|
-
-
|
|
165
|
-
-
|
|
166
|
-
- ✅ **With
|
|
165
|
+
- ✅ **Precise input types**: `T | SideEffect<'E'>` preserves `T | 'E'` without extra annotations.
|
|
166
|
+
- ⚠️ **Widened inputs**: `T | SideEffect<any>` (or `any`) collapses to `any`.
|
|
167
|
+
- ✅ **With generics**: `runPipeResult<SuccessType, ErrorType>(result)` restores a safe union when inference is lost.
|
|
168
|
+
- ✅ **With isSideEffect**: Prefer for runtime narrowing when you need branch-specific types.
|
|
167
169
|
|
|
168
|
-
|
|
170
|
+
Provide generics when inference is lost; prefer `isSideEffect` for precise narrowing.
|
|
169
171
|
|
|
170
172
|
## Stream Functions - Lazy Iterable Processing
|
|
171
173
|
|
|
@@ -519,13 +521,13 @@ const gradeToLetter = cond([
|
|
|
519
521
|
### 6.1 Type-Safety Tips (prop/ifElse/cond)
|
|
520
522
|
|
|
521
523
|
- `prop` returns `T[K] | undefined`. Use `propOr` (or guard) before array operations.
|
|
522
|
-
- `ifElse` expects **functions** for both branches. If you already have a value, wrap it: `() => value
|
|
523
|
-
- Use `from(value)` when you need a unary function that ignores input (handy for `ifElse` branches).
|
|
524
|
+
- `ifElse` expects **functions** for both branches. If you already have a value, wrap it: `() => value` or use `from(value)` for cleaner constant branches.
|
|
525
|
+
- Use `from(value)` when you need a unary function that ignores input (handy for `ifElse`/`cond` branches and data-first patterns). Pipelines that start with `from(...)` can be called without an initial input value.
|
|
524
526
|
- `cond` returns `R | undefined`. Add a default branch and coalesce when you need a strict result.
|
|
525
527
|
- In `pipeSideEffect`, keep step return types aligned to avoid wide unions.
|
|
526
528
|
|
|
527
529
|
```typescript
|
|
528
|
-
import { pipe, propOr, append, assoc, ifElse, cond, from } from 'fp-pack';
|
|
530
|
+
import { pipe, propOr, append, assoc, ifElse, cond, from, filter, map } from 'fp-pack';
|
|
529
531
|
|
|
530
532
|
// propOr keeps the type strict for array ops
|
|
531
533
|
const addTodo = (text: string, state: AppState) =>
|
|
@@ -542,13 +544,21 @@ const toggleTodo = (id: string) => ifElse(
|
|
|
542
544
|
(todo) => todo
|
|
543
545
|
);
|
|
544
546
|
|
|
545
|
-
// from is useful for constant branches
|
|
547
|
+
// from is useful for constant branches - cleaner than () => value
|
|
546
548
|
const statusLabel = ifElse(
|
|
547
549
|
(score: number) => score >= 60,
|
|
548
|
-
from('pass'),
|
|
550
|
+
from('pass'), // Constant value
|
|
549
551
|
from('fail')
|
|
550
552
|
);
|
|
551
553
|
|
|
554
|
+
// Data-first pattern with from: inject data into pipeline
|
|
555
|
+
const processData = pipe(
|
|
556
|
+
from([1, 2, 3, 4, 5]),
|
|
557
|
+
filter((n: number) => n % 2 === 0),
|
|
558
|
+
map(n => n * 2)
|
|
559
|
+
);
|
|
560
|
+
const result = processData(); // [4, 8]
|
|
561
|
+
|
|
552
562
|
// cond still returns R | undefined, so coalesce if needed
|
|
553
563
|
const grade = (score: number) =>
|
|
554
564
|
cond([
|
|
@@ -665,8 +675,8 @@ const updateUser = assoc('lastLogin', new Date());
|
|
|
665
675
|
- **Pure async operations**: `pipeAsync`
|
|
666
676
|
- **Error handling with SideEffect**: `pipeSideEffect` (sync) / `pipeAsyncSideEffect` (async)
|
|
667
677
|
- **Strict SideEffect unions**: `pipeSideEffectStrict` (sync) / `pipeAsyncSideEffectStrict` (async)
|
|
668
|
-
- **Type-safe result handling**: `isSideEffect` for precise type narrowing (
|
|
669
|
-
- **Execute SideEffect**: `runPipeResult` (call OUTSIDE pipelines).
|
|
678
|
+
- **Type-safe result handling**: `isSideEffect` for precise type narrowing (prefer this when you need branch-specific types)
|
|
679
|
+
- **Execute SideEffect**: `runPipeResult` (call OUTSIDE pipelines). If the input is widened to `SideEffect<any>`/`any`, the result becomes `any`; provide generics to recover
|
|
670
680
|
- **Large datasets**: `stream/*` functions
|
|
671
681
|
- **Conditionals**: `ifElse`, `when`, `unless`, `cond`
|
|
672
682
|
- **Object access**: `prop`, `propStrict`, `path`, `pick`, `omit`
|
package/dist/stream/index.d.ts
CHANGED
|
@@ -21,4 +21,5 @@ export { default as toArray } from './toArray';
|
|
|
21
21
|
export { default as toAsync } from './toAsync';
|
|
22
22
|
export { default as zip } from './zip';
|
|
23
23
|
export { default as zipWith } from './zipWith';
|
|
24
|
+
export type { AnyIterable, AnyIterableInput, PromiseLikeValue } from './utils';
|
|
24
25
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stream/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE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AAO,IAAI,IAAI,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fp-pack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Functional programming utilities library for TypeScript",
|
|
6
6
|
"keywords": [
|
|
@@ -73,7 +73,8 @@
|
|
|
73
73
|
"preview": "vite preview",
|
|
74
74
|
"test": "vitest",
|
|
75
75
|
"test:ui": "vitest --ui",
|
|
76
|
-
"test:run": "vitest run",
|
|
76
|
+
"test:run": "pnpm test:types && vitest run",
|
|
77
|
+
"test:types": "tsc --noEmit",
|
|
77
78
|
"clean": "pnpm clean:dist && pnpm clean:module",
|
|
78
79
|
"clean:dist": "rm -rf dist docs/dist",
|
|
79
80
|
"clean:module": "rm -rf dist docs/dist node_modules",
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { FromFn } from '../composition/from';
|
|
2
|
+
|
|
1
3
|
/** pipeAsync - 비동기 함수 합성 */
|
|
2
4
|
type AsyncOrSync<A, R> = (a: A) => R | Promise<R>;
|
|
3
5
|
type PipeInput<Fns extends AsyncOrSync<any, any>[]> = Fns extends [AsyncOrSync<infer A, any>, ...AsyncOrSync<any, any>[]]
|
|
@@ -11,7 +13,11 @@ type PipeOutput<Fns extends AsyncOrSync<any, any>[]> = Fns extends [AsyncOrSync<
|
|
|
11
13
|
: never
|
|
12
14
|
: never;
|
|
13
15
|
type PipeAsync<Fns extends AsyncOrSync<any, any>[]> = (input: PipeInput<Fns>) => Promise<PipeOutput<Fns>>;
|
|
16
|
+
type PipeAsyncFrom<Fns extends [FromFn<any>, ...AsyncOrSync<any, any>[]]> = (
|
|
17
|
+
input?: PipeInput<Fns>
|
|
18
|
+
) => Promise<PipeOutput<Fns>>;
|
|
14
19
|
|
|
20
|
+
function pipeAsync<Fns extends [FromFn<any>, ...AsyncOrSync<any, any>[]]>(...funcs: Fns): PipeAsyncFrom<Fns>;
|
|
15
21
|
function pipeAsync<A, R>(ab: AsyncOrSync<A, R>): (a: A) => Promise<Awaited<R>>;
|
|
16
22
|
function pipeAsync<A, B, R>(ab: AsyncOrSync<A, B>, bc: AsyncOrSync<Awaited<B>, R>): (a: A) => Promise<Awaited<R>>;
|
|
17
23
|
function pipeAsync<A, B, C, R>(
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FromFn } from '../composition/from';
|
|
1
2
|
import SideEffect, { isSideEffect } from '../composition/sideEffect';
|
|
2
3
|
|
|
3
4
|
/** pipeAsyncSideEffect - SideEffect를 허용하는 비동기 함수 합성 */
|
|
@@ -21,7 +22,13 @@ type Resolve<T> = T extends infer R ? R : never;
|
|
|
21
22
|
type PipeAsyncSideEffect<Fns extends AsyncOrSync<any, any>[]> = (
|
|
22
23
|
input: PipeInput<Fns> | SideEffect<any>
|
|
23
24
|
) => Promise<Resolve<PipeOutput<Fns>>>;
|
|
25
|
+
type PipeAsyncSideEffectFrom<Fns extends [FromFn<any>, ...AsyncOrSync<any, any>[]]> = (
|
|
26
|
+
input?: PipeInput<Fns> | SideEffect<any>
|
|
27
|
+
) => Promise<Resolve<PipeOutput<Fns>>>;
|
|
24
28
|
|
|
29
|
+
function pipeAsyncSideEffect<Fns extends [FromFn<any>, ...AsyncOrSync<any, any>[]]>(
|
|
30
|
+
...funcs: Fns
|
|
31
|
+
): PipeAsyncSideEffectFrom<Fns>;
|
|
25
32
|
function pipeAsyncSideEffect<A, R>(
|
|
26
33
|
ab: AsyncOrSync<A, R>
|
|
27
34
|
): (a: A | SideEffect<any>) => Promise<MaybeSideEffect<Awaited<R>>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FromFn } from '../composition/from';
|
|
1
2
|
import SideEffect, { isSideEffect } from '../composition/sideEffect';
|
|
2
3
|
|
|
3
4
|
type AnyFn = (...args: any[]) => any;
|
|
@@ -43,6 +44,12 @@ type PipeAsyncSideEffectStrictUnary<Fns extends [AnyFn, ...AnyFn[]]> = {
|
|
|
43
44
|
input: PipeInputStrict<Fns> | SideEffect<EIn>
|
|
44
45
|
): Promise<Resolve<MaybeSideEffect<PipeValueOutputStrict<Fns>, EffectsOf<Fns> | EIn>>>;
|
|
45
46
|
};
|
|
47
|
+
type PipeAsyncSideEffectStrictUnaryOptional<Fns extends [AnyFn, ...AnyFn[]]> = {
|
|
48
|
+
(input?: PipeInputStrict<Fns>): Promise<Resolve<MaybeSideEffect<PipeValueOutputStrict<Fns>, EffectsOf<Fns>>>>;
|
|
49
|
+
<EIn>(
|
|
50
|
+
input?: PipeInputStrict<Fns> | SideEffect<EIn>
|
|
51
|
+
): Promise<Resolve<MaybeSideEffect<PipeValueOutputStrict<Fns>, EffectsOf<Fns> | EIn>>>;
|
|
52
|
+
};
|
|
46
53
|
|
|
47
54
|
type PipeAsyncSideEffectStrict<Fns extends [AnyFn, ...AnyFn[]]> = Fns extends [ZeroFn<any>, ...AnyFn[]]
|
|
48
55
|
? () => Promise<Resolve<MaybeSideEffect<PipeValueOutputStrict<Fns>, EffectsOf<Fns>>>>
|
|
@@ -177,6 +184,9 @@ function pipeAsyncSideEffectStrict<B, C, D, E, F, G, H, I, J, R>(
|
|
|
177
184
|
AsyncOrSync<NonSideEffect<Awaited<I>>, J>,
|
|
178
185
|
AsyncOrSync<NonSideEffect<Awaited<J>>, R>
|
|
179
186
|
]>;
|
|
187
|
+
function pipeAsyncSideEffectStrict<Fns extends [FromFn<any>, ...AnyFn[]]>(
|
|
188
|
+
...funcs: Fns
|
|
189
|
+
): PipeAsyncSideEffectStrictUnaryOptional<Fns>;
|
|
180
190
|
function pipeAsyncSideEffectStrict<A, R>(
|
|
181
191
|
ab: AsyncOrSync<A, R>
|
|
182
192
|
): PipeAsyncSideEffectStrict<[AsyncOrSync<A, R>]>;
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
* Supports functions with 2-5 parameters and keeps data-last call order.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
type Curry2<Fn> = Fn extends (a: infer A, b: infer B) => infer R
|
|
6
|
+
export type Curry2<Fn> = Fn extends (a: infer A, b: infer B) => infer R
|
|
7
7
|
? {
|
|
8
8
|
(...args: [A]): (b: B) => R;
|
|
9
9
|
(...args: [A, B]): R;
|
|
10
10
|
}
|
|
11
11
|
: never;
|
|
12
12
|
|
|
13
|
-
type Curry3<Fn> = Fn extends (a: infer A, b: infer B, c: infer C) => infer R
|
|
13
|
+
export type Curry3<Fn> = Fn extends (a: infer A, b: infer B, c: infer C) => infer R
|
|
14
14
|
? {
|
|
15
15
|
(...args: [A]): (b: B) => (c: C) => R;
|
|
16
16
|
(...args: [A, B]): (c: C) => R;
|
|
@@ -18,7 +18,7 @@ type Curry3<Fn> = Fn extends (a: infer A, b: infer B, c: infer C) => infer R
|
|
|
18
18
|
}
|
|
19
19
|
: never;
|
|
20
20
|
|
|
21
|
-
type Curry4<Fn> = Fn extends (a: infer A, b: infer B, c: infer C, d: infer D) => infer R
|
|
21
|
+
export type Curry4<Fn> = Fn extends (a: infer A, b: infer B, c: infer C, d: infer D) => infer R
|
|
22
22
|
? {
|
|
23
23
|
(...args: [A]): (b: B) => (c: C) => (d: D) => R;
|
|
24
24
|
(...args: [A, B]): (c: C) => (d: D) => R;
|
|
@@ -27,7 +27,7 @@ type Curry4<Fn> = Fn extends (a: infer A, b: infer B, c: infer C, d: infer D) =>
|
|
|
27
27
|
}
|
|
28
28
|
: never;
|
|
29
29
|
|
|
30
|
-
type Curry5<Fn> = Fn extends (a: infer A, b: infer B, c: infer C, d: infer D, e: infer E) => infer R
|
|
30
|
+
export type Curry5<Fn> = Fn extends (a: infer A, b: infer B, c: infer C, d: infer D, e: infer E) => infer R
|
|
31
31
|
? {
|
|
32
32
|
(...args: [A]): (b: B) => (c: C) => (d: D) => (e: E) => R;
|
|
33
33
|
(...args: [A, B]): (c: C) => (d: D) => (e: E) => R;
|
|
@@ -53,7 +53,7 @@ type CurryByArity<Fn extends (...args: any[]) => any> = Parameters<Fn>['length']
|
|
|
53
53
|
? Curry5<Fn>
|
|
54
54
|
: CurryVariadic<Fn>;
|
|
55
55
|
|
|
56
|
-
type Curried<Fn extends (...args: any[]) => any> = CurryByArity<Fn>;
|
|
56
|
+
export type Curried<Fn extends (...args: any[]) => any> = CurryByArity<Fn>;
|
|
57
57
|
|
|
58
58
|
function curry<Fn extends (...args: any[]) => any>(fn: Fn): Curried<Fn>;
|
|
59
59
|
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* from - 입력을 무시하고 고정 값을 반환
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
export type FromFn<T> = {
|
|
5
|
+
<I>(_input: I): T;
|
|
6
|
+
readonly __from: true;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
function from<T>(value: T): FromFn<T> {
|
|
10
|
+
const fn = (_input: unknown) => value;
|
|
11
|
+
Object.defineProperty(fn, '__from', { value: true });
|
|
12
|
+
return fn as FromFn<T>;
|
|
6
13
|
}
|
|
7
14
|
|
|
8
15
|
export default from;
|
|
@@ -3,15 +3,18 @@ export { default as pipeSideEffect } from './pipeSideEffect';
|
|
|
3
3
|
export { default as pipeSideEffectStrict } from './pipeSideEffectStrict';
|
|
4
4
|
export { default as compose } from './compose';
|
|
5
5
|
export { default as curry } from './curry';
|
|
6
|
+
export type { Curried, Curry2, Curry3, Curry4, Curry5 } from './curry';
|
|
6
7
|
export { default as partial } from './partial';
|
|
7
8
|
export { default as flip } from './flip';
|
|
8
9
|
export { default as complement } from './complement';
|
|
9
10
|
export { default as identity } from './identity';
|
|
10
11
|
export { default as constant } from './constant';
|
|
11
12
|
export { default as from } from './from';
|
|
13
|
+
export type { FromFn } from './from';
|
|
12
14
|
export { default as tap } from './tap';
|
|
13
15
|
export { default as once } from './once';
|
|
14
16
|
export { default as memoize } from './memoize';
|
|
15
17
|
export { default as SideEffect } from './sideEffect';
|
|
16
18
|
export { SideEffect as SideEffectClass } from './sideEffect';
|
|
17
19
|
export { isSideEffect, matchSideEffect, runPipeResult } from './sideEffect';
|
|
20
|
+
export type { MatchHandlers } from './sideEffect';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { FromFn } from './from';
|
|
2
|
+
|
|
1
3
|
type UnaryFn<A, R> = (a: A) => R;
|
|
2
4
|
type ZeroFn<R> = () => R;
|
|
3
5
|
type PipeInput<Fns extends UnaryFn<any, any>[]> = Fns extends [UnaryFn<infer A, any>, ...UnaryFn<any, any>[]]
|
|
@@ -11,6 +13,7 @@ type PipeOutput<Fns extends UnaryFn<any, any>[]> = Fns extends [UnaryFn<any, inf
|
|
|
11
13
|
: never
|
|
12
14
|
: never;
|
|
13
15
|
type Pipe<Fns extends UnaryFn<any, any>[]> = (input: PipeInput<Fns>) => PipeOutput<Fns>;
|
|
16
|
+
type PipeFrom<Fns extends [FromFn<any>, ...UnaryFn<any, any>[]]> = (input?: PipeInput<Fns>) => PipeOutput<Fns>;
|
|
14
17
|
|
|
15
18
|
function pipe<R>(ab: ZeroFn<R>): () => R;
|
|
16
19
|
function pipe<B, R>(ab: ZeroFn<B>, bc: UnaryFn<B, R>): () => R;
|
|
@@ -73,6 +76,7 @@ function pipe<B, C, D, E, F, G, H, I, J, R>(
|
|
|
73
76
|
ij: UnaryFn<I, J>,
|
|
74
77
|
jk: UnaryFn<J, R>
|
|
75
78
|
): () => R;
|
|
79
|
+
function pipe<Fns extends [FromFn<any>, ...UnaryFn<any, any>[]]>(...funcs: Fns): PipeFrom<Fns>;
|
|
76
80
|
function pipe<A, R>(ab: UnaryFn<A, R>): (a: A) => R;
|
|
77
81
|
function pipe<A, B, R>(ab: UnaryFn<A, B>, bc: UnaryFn<B, R>): (a: A) => R;
|
|
78
82
|
function pipe<A, B, C, R>(ab: UnaryFn<A, B>, bc: UnaryFn<B, C>, cd: UnaryFn<C, R>): (a: A) => R;
|