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,4 +1,4 @@
|
|
|
1
|
-
import SideEffect from './sideEffect';
|
|
1
|
+
import SideEffect, { runPipeResult } from './sideEffect';
|
|
2
2
|
import from from './from';
|
|
3
3
|
import pipe from './pipe';
|
|
4
4
|
import pipeSideEffect from './pipeSideEffect';
|
|
@@ -71,6 +71,13 @@ export const pipeFromTenValue = pipeFromTen('input');
|
|
|
71
71
|
type PipeFromTenValueExpected = string;
|
|
72
72
|
export type PipeFromTenValueIsStrict = Expect<Equal<typeof pipeFromTenValue, PipeFromTenValueExpected>>;
|
|
73
73
|
|
|
74
|
+
export const pipeFromTenValueNoInput = pipeFromTen();
|
|
75
|
+
|
|
76
|
+
type PipeFromTenValueNoInputExpected = string;
|
|
77
|
+
export type PipeFromTenValueNoInputIsStrict = Expect<
|
|
78
|
+
Equal<typeof pipeFromTenValueNoInput, PipeFromTenValueNoInputExpected>
|
|
79
|
+
>;
|
|
80
|
+
|
|
74
81
|
export const pipeWithSideEffectInput = pipeSideEffect(
|
|
75
82
|
(value: number) => value + 1,
|
|
76
83
|
(value) => value * 2,
|
|
@@ -130,6 +137,13 @@ export type PipeSideEffectFromTenValueIsStrict = Expect<
|
|
|
130
137
|
Equal<typeof pipeSideEffectFromTenValue, PipeSideEffectFromTenValueExpected>
|
|
131
138
|
>;
|
|
132
139
|
|
|
140
|
+
export const pipeSideEffectFromTenValueNoInput = pipeSideEffectFromTen();
|
|
141
|
+
|
|
142
|
+
type PipeSideEffectFromTenValueNoInputExpected = string | SideEffect<any>;
|
|
143
|
+
export type PipeSideEffectFromTenValueNoInputIsStrict = Expect<
|
|
144
|
+
Equal<typeof pipeSideEffectFromTenValueNoInput, PipeSideEffectFromTenValueNoInputExpected>
|
|
145
|
+
>;
|
|
146
|
+
|
|
133
147
|
export const purePipeAsync = pipeAsync(
|
|
134
148
|
(value: number) => value + 1,
|
|
135
149
|
async (value) => value * 2,
|
|
@@ -187,6 +201,13 @@ export type PipeAsyncFromTenValueIsStrict = Expect<
|
|
|
187
201
|
Equal<typeof pipeAsyncFromTenValue, PipeAsyncFromTenValueExpected>
|
|
188
202
|
>;
|
|
189
203
|
|
|
204
|
+
export const pipeAsyncFromTenValueNoInput = pipeAsyncFromTen();
|
|
205
|
+
|
|
206
|
+
type PipeAsyncFromTenValueNoInputExpected = Promise<string>;
|
|
207
|
+
export type PipeAsyncFromTenValueNoInputIsStrict = Expect<
|
|
208
|
+
Equal<typeof pipeAsyncFromTenValueNoInput, PipeAsyncFromTenValueNoInputExpected>
|
|
209
|
+
>;
|
|
210
|
+
|
|
190
211
|
export const pipeAsyncWithSideEffectInput = pipeAsyncSideEffect(
|
|
191
212
|
(value: number) => value + 1,
|
|
192
213
|
async (value) => value * 2,
|
|
@@ -252,6 +273,13 @@ export type PipeAsyncSideEffectFromTenValueIsStrict = Expect<
|
|
|
252
273
|
Equal<typeof pipeAsyncSideEffectFromTenValue, PipeAsyncSideEffectFromTenValueExpected>
|
|
253
274
|
>;
|
|
254
275
|
|
|
276
|
+
export const pipeAsyncSideEffectFromTenValueNoInput = pipeAsyncSideEffectFromTen();
|
|
277
|
+
|
|
278
|
+
type PipeAsyncSideEffectFromTenValueNoInputExpected = Promise<string | SideEffect<any>>;
|
|
279
|
+
export type PipeAsyncSideEffectFromTenValueNoInputIsStrict = Expect<
|
|
280
|
+
Equal<typeof pipeAsyncSideEffectFromTenValueNoInput, PipeAsyncSideEffectFromTenValueNoInputExpected>
|
|
281
|
+
>;
|
|
282
|
+
|
|
255
283
|
export const strictPipeSideEffect = pipeSideEffectStrict(
|
|
256
284
|
(value: number) => value + 1,
|
|
257
285
|
(value) => (value > 1 ? value : SideEffect.of(() => 'LOW' as const)),
|
|
@@ -268,6 +296,15 @@ type StrictSideEffectValue = ValueUnion<typeof strictPipeSideEffectResult>;
|
|
|
268
296
|
type StrictSideEffectValueExpected = number;
|
|
269
297
|
export type PipeSideEffectStrictValue = Expect<Equal<StrictSideEffectValue, StrictSideEffectValueExpected>>;
|
|
270
298
|
|
|
299
|
+
export const strictPipeSideEffectRunResult = runPipeResult(strictPipeSideEffectResult);
|
|
300
|
+
|
|
301
|
+
type StrictPipeSideEffectRunExpected =
|
|
302
|
+
| ValueUnion<typeof strictPipeSideEffectResult>
|
|
303
|
+
| EffectUnion<typeof strictPipeSideEffectResult>;
|
|
304
|
+
export type PipeSideEffectStrictRunPipeResultIsStrict = Expect<
|
|
305
|
+
Equal<typeof strictPipeSideEffectRunResult, StrictPipeSideEffectRunExpected>
|
|
306
|
+
>;
|
|
307
|
+
|
|
271
308
|
export const strictPipeSideEffectInput = strictPipeSideEffect(SideEffect.of(() => 'INPUT' as const));
|
|
272
309
|
|
|
273
310
|
type StrictSideEffectInputEffects = EffectUnion<typeof strictPipeSideEffectInput>;
|
|
@@ -343,6 +380,20 @@ type StrictFromTenValue = ValueUnion<typeof strictPipeSideEffectFromTenResult>;
|
|
|
343
380
|
type StrictFromTenValueExpected = number;
|
|
344
381
|
export type PipeSideEffectStrictFromTenValue = Expect<Equal<StrictFromTenValue, StrictFromTenValueExpected>>;
|
|
345
382
|
|
|
383
|
+
export const strictPipeSideEffectFromTenResultNoInput = strictPipeSideEffectFromTen();
|
|
384
|
+
|
|
385
|
+
type StrictFromTenNoInputEffects = EffectUnion<typeof strictPipeSideEffectFromTenResultNoInput>;
|
|
386
|
+
type StrictFromTenNoInputEffectsExpected = 'LOW' | 'MID' | 0;
|
|
387
|
+
export type PipeSideEffectStrictFromTenNoInputEffects = Expect<
|
|
388
|
+
Equal<StrictFromTenNoInputEffects, StrictFromTenNoInputEffectsExpected>
|
|
389
|
+
>;
|
|
390
|
+
|
|
391
|
+
type StrictFromTenNoInputValue = ValueUnion<typeof strictPipeSideEffectFromTenResultNoInput>;
|
|
392
|
+
type StrictFromTenNoInputValueExpected = number;
|
|
393
|
+
export type PipeSideEffectStrictFromTenNoInputValue = Expect<
|
|
394
|
+
Equal<StrictFromTenNoInputValue, StrictFromTenNoInputValueExpected>
|
|
395
|
+
>;
|
|
396
|
+
|
|
346
397
|
export const strictPipeAsyncSideEffect = pipeAsyncSideEffectStrict(
|
|
347
398
|
(value: number) => value + 1,
|
|
348
399
|
async (value) => (value > 1 ? value : SideEffect.of(() => 'LOW' as const)),
|
|
@@ -443,3 +494,18 @@ type StrictAsyncFromTenValueExpected = number;
|
|
|
443
494
|
export type PipeAsyncSideEffectStrictFromTenValue = Expect<
|
|
444
495
|
Equal<StrictAsyncFromTenValue, StrictAsyncFromTenValueExpected>
|
|
445
496
|
>;
|
|
497
|
+
|
|
498
|
+
export const strictPipeAsyncSideEffectFromTenResultNoInput = strictPipeAsyncSideEffectFromTen();
|
|
499
|
+
|
|
500
|
+
type StrictAsyncFromTenNoInputResolved = Awaited<typeof strictPipeAsyncSideEffectFromTenResultNoInput>;
|
|
501
|
+
type StrictAsyncFromTenNoInputEffects = EffectUnion<StrictAsyncFromTenNoInputResolved>;
|
|
502
|
+
type StrictAsyncFromTenNoInputEffectsExpected = 'LOW' | 'MID' | 0;
|
|
503
|
+
export type PipeAsyncSideEffectStrictFromTenNoInputEffects = Expect<
|
|
504
|
+
Equal<StrictAsyncFromTenNoInputEffects, StrictAsyncFromTenNoInputEffectsExpected>
|
|
505
|
+
>;
|
|
506
|
+
|
|
507
|
+
type StrictAsyncFromTenNoInputValue = ValueUnion<StrictAsyncFromTenNoInputResolved>;
|
|
508
|
+
type StrictAsyncFromTenNoInputValueExpected = number;
|
|
509
|
+
export type PipeAsyncSideEffectStrictFromTenNoInputValue = Expect<
|
|
510
|
+
Equal<StrictAsyncFromTenNoInputValue, StrictAsyncFromTenNoInputValueExpected>
|
|
511
|
+
>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FromFn } from './from';
|
|
1
2
|
import SideEffect, { isSideEffect } from './sideEffect';
|
|
2
3
|
|
|
3
4
|
type MaybeSideEffect<T> = T | SideEffect<any>;
|
|
@@ -18,6 +19,9 @@ type Resolve<T> = T extends infer R ? R : never;
|
|
|
18
19
|
type PipeSideEffect<Fns extends UnaryFn<any, any>[]> = (
|
|
19
20
|
input: PipeInput<Fns> | SideEffect<any>
|
|
20
21
|
) => Resolve<PipeOutput<Fns>>;
|
|
22
|
+
type PipeSideEffectFrom<Fns extends [FromFn<any>, ...UnaryFn<any, any>[]]> = (
|
|
23
|
+
input?: PipeInput<Fns> | SideEffect<any>
|
|
24
|
+
) => Resolve<PipeOutput<Fns>>;
|
|
21
25
|
|
|
22
26
|
function pipeSideEffect<R>(ab: ZeroFn<R>): () => MaybeSideEffect<R>;
|
|
23
27
|
function pipeSideEffect<B, R>(ab: ZeroFn<B>, bc: UnaryFn<B, R>): () => MaybeSideEffect<R>;
|
|
@@ -85,6 +89,7 @@ function pipeSideEffect<B, C, D, E, F, G, H, I, J, R>(
|
|
|
85
89
|
ij: UnaryFn<I, J>,
|
|
86
90
|
jk: UnaryFn<J, R>
|
|
87
91
|
): () => MaybeSideEffect<R>;
|
|
92
|
+
function pipeSideEffect<Fns extends [FromFn<any>, ...UnaryFn<any, any>[]]>(...funcs: Fns): PipeSideEffectFrom<Fns>;
|
|
88
93
|
function pipeSideEffect<A, R>(ab: UnaryFn<A, R>): (a: A | SideEffect<any>) => MaybeSideEffect<R>;
|
|
89
94
|
function pipeSideEffect<A, B, R>(
|
|
90
95
|
ab: UnaryFn<A, B>,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FromFn } from './from';
|
|
1
2
|
import SideEffect, { isSideEffect } from './sideEffect';
|
|
2
3
|
|
|
3
4
|
type AnyFn = (...args: any[]) => any;
|
|
@@ -43,6 +44,12 @@ type PipeSideEffectStrictUnary<Fns extends [AnyFn, ...AnyFn[]]> = {
|
|
|
43
44
|
input: PipeInputStrict<Fns> | SideEffect<EIn>
|
|
44
45
|
): Resolve<MaybeSideEffect<PipeValueOutputStrict<Fns>, EffectsOf<Fns> | EIn>>;
|
|
45
46
|
};
|
|
47
|
+
type PipeSideEffectStrictUnaryOptional<Fns extends [AnyFn, ...AnyFn[]]> = {
|
|
48
|
+
(input?: PipeInputStrict<Fns>): Resolve<MaybeSideEffect<PipeValueOutputStrict<Fns>, EffectsOf<Fns>>>;
|
|
49
|
+
<EIn>(
|
|
50
|
+
input?: PipeInputStrict<Fns> | SideEffect<EIn>
|
|
51
|
+
): Resolve<MaybeSideEffect<PipeValueOutputStrict<Fns>, EffectsOf<Fns> | EIn>>;
|
|
52
|
+
};
|
|
46
53
|
|
|
47
54
|
type PipeSideEffectStrict<Fns extends [AnyFn, ...AnyFn[]]> = Fns extends [ZeroFn<any>, ...AnyFn[]]
|
|
48
55
|
? () => Resolve<MaybeSideEffect<PipeValueOutputStrict<Fns>, EffectsOf<Fns>>>
|
|
@@ -177,6 +184,9 @@ function pipeSideEffectStrict<B, C, D, E, F, G, H, I, J, R>(
|
|
|
177
184
|
UnaryFn<NonSideEffect<I>, J>,
|
|
178
185
|
UnaryFn<NonSideEffect<J>, R>
|
|
179
186
|
]>;
|
|
187
|
+
function pipeSideEffectStrict<Fns extends [FromFn<any>, ...AnyFn[]]>(
|
|
188
|
+
...funcs: Fns
|
|
189
|
+
): PipeSideEffectStrictUnaryOptional<Fns>;
|
|
180
190
|
function pipeSideEffectStrict<A, R>(ab: UnaryFn<A, R>): PipeSideEffectStrict<[UnaryFn<A, R>]>;
|
|
181
191
|
function pipeSideEffectStrict<A, B, R>(
|
|
182
192
|
ab: UnaryFn<A, B>,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import curry from '../composition/curry';
|
|
2
|
-
|
|
3
|
-
type PathKey = string | number | symbol;
|
|
2
|
+
import type { PathKey } from './pathKey';
|
|
4
3
|
|
|
5
4
|
const isIndexKey = (key: PathKey): key is number | `${number}` => {
|
|
6
5
|
if (typeof key === 'number') {
|
|
@@ -62,3 +61,4 @@ function assocPath<T = unknown>(pathArray: PathKey[], value: unknown, obj: unkno
|
|
|
62
61
|
|
|
63
62
|
const curriedAssocPath = curry(assocPath) as AssocPath;
|
|
64
63
|
export default curriedAssocPath;
|
|
64
|
+
export type { PathKey };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import curry from '../composition/curry';
|
|
2
|
-
|
|
3
|
-
type PathKey = string | number | symbol;
|
|
2
|
+
import type { PathKey } from './pathKey';
|
|
4
3
|
|
|
5
4
|
const isIndexKey = (key: PathKey): key is number | `${number}` => {
|
|
6
5
|
if (typeof key === 'number') {
|
|
@@ -78,3 +77,4 @@ function dissocPath<T = unknown>(pathArray: PathKey[], obj: T): T {
|
|
|
78
77
|
|
|
79
78
|
const curriedDissocPath = curry(dissocPath) as DissocPath;
|
|
80
79
|
export default curriedDissocPath;
|
|
80
|
+
export type { PathKey };
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import curry from '../composition/curry';
|
|
2
|
+
import type { PathKey } from './pathKey';
|
|
2
3
|
|
|
3
4
|
type Path = {
|
|
4
|
-
(pathArray:
|
|
5
|
-
<T>(...args: [pathArray:
|
|
5
|
+
(pathArray: PathKey[]): <T>(obj: any) => T | undefined;
|
|
6
|
+
<T>(...args: [pathArray: PathKey[], obj: any]): T | undefined;
|
|
6
7
|
};
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* path - 안전한 깊은 프로퍼티 접근
|
|
10
11
|
*/
|
|
11
|
-
function path<T>(pathArray:
|
|
12
|
+
function path<T>(pathArray: PathKey[], obj: any): T | undefined {
|
|
12
13
|
return pathArray.reduce((current, key) => (current == null ? undefined : current[key]), obj) as T | undefined;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
const curriedPath = curry(path) as Path;
|
|
16
17
|
export default curriedPath;
|
|
18
|
+
export type { PathKey };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type PathKey = string | number | symbol;
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import curry from '../composition/curry';
|
|
2
|
+
import type { PathKey } from './pathKey';
|
|
2
3
|
|
|
3
4
|
type PathOr = {
|
|
4
|
-
<D>(...args: [defaultValue: D]): <T>(pathArray:
|
|
5
|
-
<D>(...args: [defaultValue: D, pathArray:
|
|
6
|
-
<T, D>(...args: [defaultValue: D, pathArray:
|
|
5
|
+
<D>(...args: [defaultValue: D]): <T>(pathArray: PathKey[]) => (obj: any) => T | D;
|
|
6
|
+
<D>(...args: [defaultValue: D, pathArray: PathKey[]]): <T>(obj: any) => T | D;
|
|
7
|
+
<T, D>(...args: [defaultValue: D, pathArray: PathKey[], obj: any]): T | D;
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* pathOr - 기본값이 있는 깊은 프로퍼티 접근
|
|
11
12
|
*/
|
|
12
|
-
function pathOr<T, D>(defaultValue: D, pathArray:
|
|
13
|
+
function pathOr<T, D>(defaultValue: D, pathArray: PathKey[], obj: any): T | D {
|
|
13
14
|
const value = pathArray.reduce((current, key) => (current == null ? undefined : current[key]), obj) as T | undefined;
|
|
14
15
|
return value == null ? defaultValue : value;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
const curriedPathOr = curry(pathOr) as PathOr;
|
|
18
19
|
export default curriedPathOr;
|
|
20
|
+
export type { PathKey };
|
package/src/index.ts
CHANGED
package/src/stream/index.ts
CHANGED
|
@@ -21,3 +21,4 @@ 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';
|