From 5b1a6d0840a8dfe2661e5bf4c2ecb93c612155b2 Mon Sep 17 00:00:00 2001 From: Ely De La Cruz <603428+elycruz@users.noreply.github.com> Date: Sat, 30 Jul 2022 13:55:19 -0400 Subject: [PATCH] #57 - 'list/utils' module curried functions converted to idiomatic currying. --- packages/fjl/src/list/utils/reduce.ts | 6 ++++-- packages/fjl/src/list/utils/reduceRight.ts | 7 +++++-- packages/fjl/src/list/utils/reduceUntil.ts | 10 ++++------ packages/fjl/src/list/utils/reduceUntilRight.ts | 10 ++++++---- packages/fjl/src/list/utils/sliceFrom.ts | 4 ++-- packages/fjl/src/list/utils/sliceTo.ts | 4 ++-- packages/fjl/src/list/utils/swap.ts | 5 +++-- packages/fjl/src/list/utils/toShortest.ts | 6 +++--- 8 files changed, 29 insertions(+), 23 deletions(-) diff --git a/packages/fjl/src/list/utils/reduce.ts b/packages/fjl/src/list/utils/reduce.ts index 57b93505..6dee5727 100644 --- a/packages/fjl/src/list/utils/reduce.ts +++ b/packages/fjl/src/list/utils/reduce.ts @@ -1,4 +1,4 @@ -import {$reduceUntil, reduceUntil} from "./reduceUntil"; +import {reduceUntil} from "./reduceUntil"; import {alwaysFalse} from "../../boolean/alwaysFalse"; import {ReduceOp, Indexable} from "../../types"; @@ -17,6 +17,8 @@ export const /** * Curried `reduce` combinator. */ - $reduce = $reduceUntil(alwaysFalse) + $reduce = (op: ReduceOp, RetT>) => + (agg: RetT) => + (xs: Indexable): RetT => reduceUntil(alwaysFalse, op, agg, xs) ; diff --git a/packages/fjl/src/list/utils/reduceRight.ts b/packages/fjl/src/list/utils/reduceRight.ts index 7e34ff0e..31eb8290 100644 --- a/packages/fjl/src/list/utils/reduceRight.ts +++ b/packages/fjl/src/list/utils/reduceRight.ts @@ -1,4 +1,4 @@ -import {$reduceUntilRight, reduceUntilRight} from "./reduceUntilRight"; +import {reduceUntilRight} from "./reduceUntilRight"; import {alwaysFalse} from "../../boolean/alwaysFalse"; import {ReduceOp, Indexable} from "../../types"; @@ -12,6 +12,9 @@ export const agg: RetT, xs: Indexable): RetT => reduceUntilRight(alwaysFalse, op, agg, xs), - $reduceRight = $reduceUntilRight(alwaysFalse) + $reduceRight = (op: ReduceOp, RetT>) => + (agg: RetT) => + (xs: Indexable): RetT => + reduceUntilRight(alwaysFalse, op, agg, xs) ; diff --git a/packages/fjl/src/list/utils/reduceUntil.ts b/packages/fjl/src/list/utils/reduceUntil.ts index b86e4854..6ba5a419 100644 --- a/packages/fjl/src/list/utils/reduceUntil.ts +++ b/packages/fjl/src/list/utils/reduceUntil.ts @@ -1,11 +1,6 @@ -import {curry, CurryOf4} from "../../function/curry"; import {ReduceOp, PredForIndexable, Indexable, Lengthable} from "../../types"; import {length} from "../length"; -export type ReduceUntil = CurryOf4, - ReduceOp, RetT>, // @todo Refactor `ReduceOp` - RetT, Indexable, RetT>; - export const /** @@ -33,6 +28,9 @@ export const /** * Reduces a slice until predicate returns `true`. */ - $reduceUntil = curry(reduceUntil) as ReduceUntil + $reduceUntil = (pred: PredForIndexable) => + (op: ReduceOp, RetT>) => + (agg: RetT) => + (xs: Indexable): RetT => reduceUntil(pred, op, agg, xs) ; diff --git a/packages/fjl/src/list/utils/reduceUntilRight.ts b/packages/fjl/src/list/utils/reduceUntilRight.ts index 21a5b794..aa6fe01f 100644 --- a/packages/fjl/src/list/utils/reduceUntilRight.ts +++ b/packages/fjl/src/list/utils/reduceUntilRight.ts @@ -1,4 +1,3 @@ -import {curry, CurryOf4} from "../../function/curry"; import {length} from "../length"; import {Indexable, ReduceOp, PredForIndexable} from "../../types"; @@ -26,9 +25,12 @@ export const return result; }; -export type ReduceUntilRight = typeof reduceUntilRight; - /** * Curried version of `$reduceUntilRight`. */ -export const $reduceUntilRight = curry(reduceUntilRight) as CurryOf4; +export const $reduceUntilRight = (pred: PredForIndexable) => + (op: ReduceOp, RetT>) => + (agg: RetT) => + (arr: Indexable): RetT => + reduceUntilRight(pred, op, agg, arr) + ; diff --git a/packages/fjl/src/list/utils/sliceFrom.ts b/packages/fjl/src/list/utils/sliceFrom.ts index aaecbcda..782b8b2d 100644 --- a/packages/fjl/src/list/utils/sliceFrom.ts +++ b/packages/fjl/src/list/utils/sliceFrom.ts @@ -1,4 +1,3 @@ -import {curry, CurryOf2} from "../../function/curry"; import {slice} from "../../platform/slice"; import {Slice} from "../../types"; @@ -12,5 +11,6 @@ export const /** * Curried version of `sliceFrom`. */ - $sliceFrom = curry(sliceFrom) as CurryOf2 + $sliceFrom = = Slice>(startInd: number) => + (xs: T2): T2 => sliceFrom(startInd, xs) ; diff --git a/packages/fjl/src/list/utils/sliceTo.ts b/packages/fjl/src/list/utils/sliceTo.ts index 8e160231..8f26229c 100644 --- a/packages/fjl/src/list/utils/sliceTo.ts +++ b/packages/fjl/src/list/utils/sliceTo.ts @@ -1,4 +1,3 @@ -import {curry, CurryOf2} from "../../function/curry"; import {slice} from "../../platform/slice"; import {Slice} from "../../types"; @@ -12,6 +11,7 @@ export const /** * Curried version of `sliceTo`. */ - $sliceTo = curry(sliceTo) as CurryOf2 + $sliceTo = = Slice>(toInd: number) => + (xs: T2): T2 => sliceTo(toInd, xs) ; diff --git a/packages/fjl/src/list/utils/swap.ts b/packages/fjl/src/list/utils/swap.ts index 50205bee..c5056e0a 100644 --- a/packages/fjl/src/list/utils/swap.ts +++ b/packages/fjl/src/list/utils/swap.ts @@ -1,4 +1,3 @@ -import {curry, CurryOf3} from "../../function"; import {sliceCopy} from "./sliceCopy"; export const @@ -17,6 +16,8 @@ export const /** * Returns an array with the given indices swapped. */ - $swap = curry(swap) as CurryOf3 + $swap = (ind1: number) => + (ind2: number) => + (list: T[]): T[] => swap(ind1, ind2, list) ; diff --git a/packages/fjl/src/list/utils/toShortest.ts b/packages/fjl/src/list/utils/toShortest.ts index e8545a57..716b5238 100644 --- a/packages/fjl/src/list/utils/toShortest.ts +++ b/packages/fjl/src/list/utils/toShortest.ts @@ -1,4 +1,3 @@ -import {curry2, CurryOf2} from "../../function/curry"; import {lengths} from "./lengths"; import {map} from "../map"; import {sliceTo} from "./sliceTo"; @@ -21,8 +20,9 @@ export const * Returns a list of lists trimmed to the shortest length in given list of lists. * @background This method is used by the `zip*` functions to achieve their * 'slice to smallest' functionality. - * @curried At two or more. + * @curried Upto two. */ - $toShortest = curry2(toShortest) as CurryOf2 + $toShortest = = Slice>(list1: T2) => + (list2: T2, ...lists: T2[]): T2[] => toShortest(list1, list2, ...lists) ;