Skip to content

Commit

Permalink
#57 - src/list/ - updated pseudo curried methods, upto 'cycle' method…
Browse files Browse the repository at this point in the history
…, to idiomatic curry syntax.
  • Loading branch information
elycruz committed Jul 30, 2022
1 parent 5b1a6d0 commit 6eeb2bc
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 26 deletions.
8 changes: 4 additions & 4 deletions packages/fjl/src/list/all.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {curry2, CurryOf2} from "../function";
import {length} from "./length";
import {PredForIndexable, Indexable} from "../types";
import {keys} from "../platform/object";

export type All<Pred, Functor> = CurryOf2<Pred, Functor, boolean>

/**
* Returns true if all items in container return `true` for predicate `p`.
*/
Expand All @@ -26,4 +23,7 @@ export const all = <T>(p: PredForIndexable<T>, xs: Indexable<T>): boolean => {
/**
* Curried version of `all`.
*/
export const $all = curry2(all) as All<PredForIndexable, Indexable>;
export const $all = <T>(p: PredForIndexable<T>) =>
(xs: Indexable<T>): boolean => all(p, xs)

;
7 changes: 5 additions & 2 deletions packages/fjl/src/list/any.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {curry, CurryOf2} from "../function/curry";
import {CurryOf2} from "../function/curry";
import {length} from "./length";
import {PredForIndexable, Indexable} from "../types";
import {keys} from "../platform/object";
Expand Down Expand Up @@ -28,4 +28,7 @@ export const
/**
* Curried version of `any`.
*/
$any = curry(any) as Any<PredForIndexable, Indexable>;
$any = <T>(p: PredForIndexable<T>) =>
(xs: Indexable<T>): boolean => any(p, xs)

;
6 changes: 2 additions & 4 deletions packages/fjl/src/list/breakOnList.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 {findIndexWhere} from "./utils/findexIndexWhere";
import {of} from "../object/of";
Expand All @@ -7,8 +6,6 @@ import {splitAt} from "./splitAt";
import {Slice, PredForSlice} from "../types";
import {sliceFrom} from "./utils/sliceFrom";

export type BreakOnList<Pred, Functor> = CurryOf2<Pred, Functor, [Functor, Functor]>;

export const

/**
Expand All @@ -29,5 +26,6 @@ export const
[of(list), sliceFrom(0, list)] : reverse(splitAt(splitPoint, list));
},

$breakOnList = curry(breakOnList) as BreakOnList<PredForSlice, Slice>
$breakOnList = <T>(pred: PredForSlice<T>) =>
(list: Slice<T>): [Slice<T>, Slice<T>] => breakOnList(pred, list)
;
11 changes: 2 additions & 9 deletions packages/fjl/src/list/complement.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import {curry2, CurryOf2} from '../function/curry';
import {reduce} from "./utils/reduce";
import {append} from "./append";
import {difference} from "./difference";
import {Slice} from '../types';

export type Complement<Functor> = CurryOf2<Functor, Functor, Functor>

export const

/**
Expand All @@ -20,12 +17,8 @@ export const

/**
* Returns the complement of list 0 and the reset of the passed in arrays.
* @function module:list.complement
* @param arr0 {Array}
* @param arrays {...Array}
* @returns {Array}
* @curried
*/
$complement = curry2(complement) as Complement<Slice<any>>
$complement = <T>(xs1: Slice<T>) =>
(xs2: Slice<T>, ...arrays: Slice<T>[]): Slice<T> => complement(xs1, xs2, ...arrays)

;
7 changes: 2 additions & 5 deletions packages/fjl/src/list/concatMap.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import {curry, CurryOf2} from "../function";
import {concat} from "./concat";
import {map} from "./map";
import {MapOp, Indexable} from "../types";

export type ConcatMap<T, RetT, Mapper, Functor, RetFunctor> =
CurryOf2<Mapper, Functor, RetT>

export const

/**
Expand All @@ -17,6 +13,7 @@ export const
): Indexable<T> =>
concat(map(fn, indexable)),

$concatMap = curry(concatMap) as ConcatMap<any, any, MapOp<any, number | string, Indexable, any>, Indexable, any>
$concatMap = <T, RetT>(fn: MapOp<T, number | string, Indexable<T>, RetT>) =>
(indexable: Indexable<T>): Indexable<T> => concatMap(fn, indexable)

;
4 changes: 2 additions & 2 deletions packages/fjl/src/list/cycle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {curry} from "../function";
import {concat} from "./concat";
import {replicate} from "./replicate";
import {Slice} from "../types";
Expand All @@ -13,7 +12,8 @@ export const
cycle = <T>(n: number, xs: Slice<T>): Slice<T[]> =>
concat(replicate(n, xs) as unknown as Slice<T[]>[]),

$cycle = curry(cycle),
$cycle = <T>(n: number) =>
(xs: Slice<T>): Slice<T[]> => cycle(n, xs),

/**
* Generates a generator which cycles list (concatenate) to end of last yielded result - On first call last yielded
Expand Down

0 comments on commit 6eeb2bc

Please sign in to comment.