-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(transducers): add generics for compR(), fix types in mapNth()
- Loading branch information
1 parent
4c014b1
commit 3b7c9d9
Showing
3 changed files
with
29 additions
and
7 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 |
---|---|---|
@@ -1,5 +1,27 @@ | ||
import { Reducer } from "../api"; | ||
import { Reduced } from "../reduced"; | ||
|
||
export function compR(rfn: Reducer<any, any>, fn: (acc: any, x: any) => any) { | ||
return <Reducer<any, any>>[rfn[0], rfn[1], fn]; | ||
/** | ||
* Reducer composition helper. Takes existing reducer `rfn` (a 3-tuple) | ||
* and a reducing function `fn`. Returns a new reducer tuple of this | ||
* form: | ||
* | ||
* ``` | ||
* [rfn[0], rfn[1], fn] | ||
* ``` | ||
* | ||
* `rfn[2]` reduces values of type `B` into an accumulator of type `A`. | ||
* `fn` accepts values of type `C` and produces interim results of type | ||
* `B`, which are then (possibly) passed to the "inner" `rfn[2]` | ||
* function. Therefore the resulting reducer takes inputs of `C` and an | ||
* accumulator of type `A`. | ||
* | ||
* It is assumed that `fn` internally calls `rfn[2]` to pass its own | ||
* results for further processing by the nested reducer `rfn`. | ||
* | ||
* @param rfn | ||
* @param fn | ||
*/ | ||
export function compR<A, B, C>(rfn: Reducer<A, B>, fn: (acc: A, x: C) => A | Reduced<A>) { | ||
return <Reducer<A, C>>[rfn[0], rfn[1], fn]; | ||
} |
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