Skip to content

Commit

Permalink
issue-#57 - Progress on idiomatic curry - converted methods up to, an…
Browse files Browse the repository at this point in the history
…d including, 'src/list/'.
  • Loading branch information
elycruz committed Aug 9, 2022
1 parent b40862a commit 962f55d
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 28 deletions.
4 changes: 2 additions & 2 deletions packages/fjl/src/list/sortBy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {curry} from "../function/curry";
import {genericAscOrdering} from "./utils";
import {sliceCopy} from "./utils/sliceCopy";

Expand All @@ -10,4 +9,5 @@ export const
sortBy = <T>(orderingFn, xs: T[]): T[] => (sliceCopy(xs) as T[])
.sort(orderingFn || genericAscOrdering),

$sortBy = curry(sortBy);
$sortBy = <T>(orderingFn) =>
(xs: T[]): T[] => sortBy(orderingFn, xs);
5 changes: 3 additions & 2 deletions packages/fjl/src/list/sortOn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {curry2, CurryOf2} from "../function/curry";
import {map} from "./map";
import {sortBy} from "./sortBy";
import {genericAscOrdering} from "./utils";
Expand Down Expand Up @@ -42,4 +41,6 @@ export const
export type SortOn = typeof sortOn;
export type SortOnParams = Parameters<SortOn>;

export const $sortOn = curry2(sortOn) as CurryOf2<SortOnParams[0], SortOnParams[1]>;
export const $sortOn = <T = any>(valueFn: Unary<T>) =>
(xs: T[]): T[] =>
sortOn(valueFn, xs);
4 changes: 2 additions & 2 deletions packages/fjl/src/list/span.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {curry} from "../function/curry";
import {negateF3} from "../function/negate";
import {findIndexWhere} from "./utils";
import {of} from "../object/of";
Expand All @@ -20,4 +19,5 @@ export const
splitAt(splitPoint, list);
},

$span = curry(span);
$span = <T>(pred: PredForSlice<T>) =>
(list: Slice<T>): [Slice<T>, Slice<T>] => span(pred, list);
5 changes: 3 additions & 2 deletions packages/fjl/src/list/splitAt.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {sliceFrom} from "./utils/sliceFrom";
import {sliceTo} from "./utils/sliceTo";
import {Slice} from "../types";
import {curry} from "../function";

export const

Expand All @@ -12,4 +11,6 @@ export const
splitAt = <T>(ind: number, list: Slice<T>): [Slice<T>, Slice<T>] =>
[sliceTo(ind, list), sliceFrom(ind, list)],

$splitAt = curry(splitAt);
$splitAt = <T>(ind: number) =>
(list: Slice<T>): [Slice<T>, Slice<T>] =>
splitAt(ind, list);
4 changes: 3 additions & 1 deletion packages/fjl/src/list/stripPrefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ export const
splitAt(length(prefix), list)[1] :
sliceCopy(list),

$stripPrefix = curry(stripPrefix);
$stripPrefix = <T>(prefix: Slice<T>) =>
(list: Slice<T>): Slice<T> =>
stripPrefix(prefix, list)
5 changes: 3 additions & 2 deletions packages/fjl/src/list/takeWhile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {curry, CurryOf2} from "../function/curry";
import {negateF3} from "../function/negate";
import {reduceUntil} from "./utils";
import {isString} from "../object/is";
Expand All @@ -21,4 +20,6 @@ export const
xs
),

$takeWhile = curry(takeWhile) as CurryOf2<PredForSlice<any>, Slice<any>, Slice<any>>;
$takeWhile = <T>(pred: PredForSlice<T>) =>
(xs: Slice<T>): Slice<T> =>
takeWhile(pred, xs);
5 changes: 4 additions & 1 deletion packages/fjl/src/list/unfoldr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ export const
return out;
},

$unfoldr = curry(unfoldr);
$unfoldr = <A, B>(op: ((b: B | undefined, i?: number, as?: A[]) => [A, B] | undefined)) =>
(bs: B): A[] =>
unfoldr(op, bs)
;
5 changes: 3 additions & 2 deletions packages/fjl/src/list/union.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {curry} from "../function/curry";
import {append} from "./append";
import {filter} from "./filter";
import {includes, } from "../platform/slice";
Expand All @@ -17,4 +16,6 @@ export const
filter(elm => !includes(arr1, elm), arr2) as Slice<T>
),

$union = curry(union);
$union = <T>(arr1: Slice<T>) =>
(arr2: Slice<T>): Slice<T> => union(arr1, arr2)
;
5 changes: 4 additions & 1 deletion packages/fjl/src/list/unionBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ export const
return foldl(foldOp, sliceCopy(xs1) as Slice<T>, xs2) as Slice<T>;
},

$unionBy = curry(unionBy);
$unionBy = <T>(pred: BinaryPred<T, T>) =>
(xs1: Slice<T>) =>
(xs2: Slice<T>): Slice<T> =>
unionBy(pred, xs1, xs2);
5 changes: 4 additions & 1 deletion packages/fjl/src/list/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ export const
[], a1);
},

$zip = curry(zip);
$zip = <T, T2>(arr1: T[]) =>
(arr2: T2[]): [T, T2][] => zip(arr1, arr2)

;
4 changes: 3 additions & 1 deletion packages/fjl/src/list/zip3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ export const
*/
zip3 = <T = any>(arr1: T[], arr2: T[], arr3: T[]): T[][] => zipN(arr1, arr2, arr3),

$zip3 = curry(zip3);
$zip3 = <T = any>(arr1: T[]) =>
(arr2: T[]) =>
(arr3: T[]): T[][] => zip3(arr1, arr2, arr3);
5 changes: 4 additions & 1 deletion packages/fjl/src/list/zip4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ export const /**
*/
zip4 = <T = any>(arr1: T[], arr2: T[], arr3: T[], arr4: T[]): T[][] => zipN(arr1, arr2, arr3, arr4),

$zip4 = curry(zip4);
$zip4 = <T = any>(arr1: T[]) =>
(arr2: T[]) =>
(arr3: T[]) =>
(arr4: T[]): T[][] => zip4(arr1, arr2, arr3, arr4);
7 changes: 5 additions & 2 deletions packages/fjl/src/list/zipN.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {curry2} from "../function/curry";
import {reduce} from "./utils/reduce";
import {toShortest} from "./utils/toShortest";
import {push} from "./push";
Expand All @@ -17,4 +16,8 @@ export const
[], trimmedLists[0]);
},

$zipN = curry2(zipN);
$zipN = <T = any>(arr1: T[]) =>
(...lists: T[][]): T[][] =>
zipN(arr1, ...lists)

;
6 changes: 4 additions & 2 deletions packages/fjl/src/list/zipWith.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {curry} from "../function/curry";
import {length} from "./length";
import {reduce, toShortest} from "./utils";
import {push} from "./push";
Expand Down Expand Up @@ -39,4 +38,7 @@ export const
[], a1);
},

$zipWith = curry(zipWith);
$zipWith = <T, T2>(op: Binary<T, T2, [T, T2]>) =>
(xs1: Slice<T>) =>
(xs2: Slice<T2>): [T, T2][] =>
zipWith(op, xs1, xs2);
6 changes: 4 additions & 2 deletions packages/fjl/src/list/zipWith3.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {curry} from "../function/curry";
import {zipWithN} from "./zipWithN";
import {Slice} from "../types";

Expand All @@ -19,4 +18,7 @@ export const
*/
zipWith3 = <T = any>(op: ZipWith3Op<T>, xs1: T[], xs2: T[], xs3: T[]): Slice<T>[] => zipWithN(op, xs1, xs2, xs3),

$zipWith3 = curry(zipWith3);
$zipWith3 = <T = any>(op: ZipWith3Op<T>) =>
(xs1: T[]) =>
(xs2: T[]) =>
(xs3: T[]): Slice<T>[] => zipWith3(op, xs1, xs2, xs3);
7 changes: 3 additions & 4 deletions packages/fjl/src/list/zipWithN.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {curry3} from "../function/curry";
import {length} from "./length";
import {toShortest} from "./utils";
import {map} from "./map";
import {sliceTo} from "./utils/sliceTo";
import {Slice} from "../types";

export const
Expand All @@ -27,5 +24,7 @@ export const
);
},

$zipWithN = curry3(zipWithN);
$zipWithN = <T = any>(op) =>
(...lists: T[][]): Slice<T>[] =>
zipWithN(op, ...lists);

0 comments on commit 962f55d

Please sign in to comment.