Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(transducers): extract internal helpers, update rfns & xforms
Impacted reducers: - add/mul/sub - groupByMap/Obj Xforms: - movingMedian - partitionSort / streamSort - takeLast
- Loading branch information
1 parent
820e7c7
commit 7772f9b
Showing
15 changed files
with
100 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Fn } from "@thi.ng/api"; | ||
import { ReductionFn } from "../api"; | ||
import { isReduced } from "../reduced"; | ||
|
||
/** | ||
* Helper HOF yielding a buffer drain completion function for some | ||
* transducers. | ||
* | ||
* @param buf | ||
* @param complete | ||
* @param reduce | ||
*/ | ||
export const __drain = <T>( | ||
buf: T[], | ||
complete: Fn<any, any>, | ||
reduce: ReductionFn<any, T> | ||
) => (acc: T[]) => { | ||
while (buf.length && !isReduced(acc)) { | ||
acc = reduce(acc, buf.shift()!); | ||
} | ||
return complete(acc); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { identity } from "@thi.ng/compose"; | ||
import { GroupByOpts } from "../api"; | ||
import { push } from "../rfn/push"; | ||
|
||
/** | ||
* Shared helper function for groupBy* reducers | ||
* | ||
* @param opts | ||
*/ | ||
export const __groupByOpts = <SRC, KEY, GROUP>( | ||
opts?: Partial<GroupByOpts<SRC, PropertyKey, GROUP>> | ||
) => | ||
<GroupByOpts<SRC, KEY, GROUP>>{ | ||
key: identity, | ||
group: push(), | ||
...opts | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { compare } from "@thi.ng/compare"; | ||
import { identity } from "@thi.ng/compose"; | ||
import { SortOpts } from "../api"; | ||
|
||
export const __sortOpts = <A, B>(opts?: Partial<SortOpts<A, B>>) => | ||
<SortOpts<A, B>>{ | ||
key: identity, | ||
compare, | ||
...opts | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters