-
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transducers): add IXform interface & TxLike type alias, update r…
…elated functions - update all fns expecting Transducer args - add internal ensureTransducer() helper
- Loading branch information
1 parent
3ede5af
commit 49c62b7
Showing
9 changed files
with
191 additions
and
133 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,101 +1,101 @@ | ||
import { comp as _comp } from "@thi.ng/compose"; | ||
import { Transducer } from "../api"; | ||
import { Transducer, TxLike } from "../api"; | ||
import { ensureTransducer } from "../internal/ensure"; | ||
|
||
/** | ||
* Transducer composition. Returns new transducer which applies given | ||
* transducers in left-to-right order. | ||
* | ||
* @remarks | ||
* Fast (loop-free) paths are provided for up to 10 args (transducers). | ||
* | ||
* @param a - | ||
*/ | ||
export function comp<A, B>(a: Transducer<A, B>): Transducer<A, B>; | ||
export function comp<A, B>(a: TxLike<A, B>): Transducer<A, B>; | ||
export function comp<A, B, C>( | ||
a: Transducer<A, B>, | ||
b: Transducer<B, C> | ||
a: TxLike<A, B>, | ||
b: TxLike<B, C> | ||
): Transducer<A, C>; | ||
export function comp<A, B, C, D>( | ||
a: Transducer<A, B>, | ||
b: Transducer<B, C>, | ||
c: Transducer<C, D> | ||
a: TxLike<A, B>, | ||
b: TxLike<B, C>, | ||
c: TxLike<C, D> | ||
): Transducer<A, D>; | ||
export function comp<A, B, C, D, E>( | ||
a: Transducer<A, B>, | ||
b: Transducer<B, C>, | ||
c: Transducer<C, D>, | ||
d: Transducer<D, E> | ||
a: TxLike<A, B>, | ||
b: TxLike<B, C>, | ||
c: TxLike<C, D>, | ||
d: TxLike<D, E> | ||
): Transducer<A, E>; | ||
export function comp<A, B, C, D, E, F>( | ||
a: Transducer<A, B>, | ||
b: Transducer<B, C>, | ||
c: Transducer<C, D>, | ||
d: Transducer<D, E>, | ||
e: Transducer<E, F> | ||
a: TxLike<A, B>, | ||
b: TxLike<B, C>, | ||
c: TxLike<C, D>, | ||
d: TxLike<D, E>, | ||
e: TxLike<E, F> | ||
): Transducer<A, F>; | ||
export function comp<A, B, C, D, E, F, G>( | ||
a: Transducer<A, B>, | ||
b: Transducer<B, C>, | ||
c: Transducer<C, D>, | ||
d: Transducer<D, E>, | ||
e: Transducer<E, F>, | ||
f: Transducer<F, G> | ||
a: TxLike<A, B>, | ||
b: TxLike<B, C>, | ||
c: TxLike<C, D>, | ||
d: TxLike<D, E>, | ||
e: TxLike<E, F>, | ||
f: TxLike<F, G> | ||
): Transducer<A, G>; | ||
export function comp<A, B, C, D, E, F, G, H>( | ||
a: Transducer<A, B>, | ||
b: Transducer<B, C>, | ||
c: Transducer<C, D>, | ||
d: Transducer<D, E>, | ||
e: Transducer<E, F>, | ||
f: Transducer<F, G>, | ||
g: Transducer<G, H> | ||
a: TxLike<A, B>, | ||
b: TxLike<B, C>, | ||
c: TxLike<C, D>, | ||
d: TxLike<D, E>, | ||
e: TxLike<E, F>, | ||
f: TxLike<F, G>, | ||
g: TxLike<G, H> | ||
): Transducer<A, H>; | ||
export function comp<A, B, C, D, E, F, G, H, I>( | ||
a: Transducer<A, B>, | ||
b: Transducer<B, C>, | ||
c: Transducer<C, D>, | ||
d: Transducer<D, E>, | ||
e: Transducer<E, F>, | ||
f: Transducer<F, G>, | ||
g: Transducer<G, H>, | ||
h: Transducer<H, I> | ||
a: TxLike<A, B>, | ||
b: TxLike<B, C>, | ||
c: TxLike<C, D>, | ||
d: TxLike<D, E>, | ||
e: TxLike<E, F>, | ||
f: TxLike<F, G>, | ||
g: TxLike<G, H>, | ||
h: TxLike<H, I> | ||
): Transducer<A, I>; | ||
export function comp<A, B, C, D, E, F, G, H, I, J>( | ||
a: Transducer<A, B>, | ||
b: Transducer<B, C>, | ||
c: Transducer<C, D>, | ||
d: Transducer<D, E>, | ||
e: Transducer<E, F>, | ||
f: Transducer<F, G>, | ||
g: Transducer<G, H>, | ||
h: Transducer<H, I>, | ||
i: Transducer<I, J> | ||
a: TxLike<A, B>, | ||
b: TxLike<B, C>, | ||
c: TxLike<C, D>, | ||
d: TxLike<D, E>, | ||
e: TxLike<E, F>, | ||
f: TxLike<F, G>, | ||
g: TxLike<G, H>, | ||
h: TxLike<H, I>, | ||
i: TxLike<I, J> | ||
): Transducer<A, J>; | ||
export function comp<A, B, C, D, E, F, G, H, I, J, K>( | ||
a: Transducer<A, B>, | ||
b: Transducer<B, C>, | ||
c: Transducer<C, D>, | ||
d: Transducer<D, E>, | ||
e: Transducer<E, F>, | ||
f: Transducer<F, G>, | ||
g: Transducer<G, H>, | ||
h: Transducer<H, I>, | ||
i: Transducer<I, J>, | ||
j: Transducer<J, K> | ||
a: TxLike<A, B>, | ||
b: TxLike<B, C>, | ||
c: TxLike<C, D>, | ||
d: TxLike<D, E>, | ||
e: TxLike<E, F>, | ||
f: TxLike<F, G>, | ||
g: TxLike<G, H>, | ||
h: TxLike<H, I>, | ||
i: TxLike<I, J>, | ||
j: TxLike<J, K> | ||
): Transducer<A, K>; | ||
export function comp<A, B, C, D, E, F, G, H, I, J, K>( | ||
a: Transducer<A, B>, | ||
b: Transducer<B, C>, | ||
c: Transducer<C, D>, | ||
d: Transducer<D, E>, | ||
e: Transducer<E, F>, | ||
f: Transducer<F, G>, | ||
g: Transducer<G, H>, | ||
h: Transducer<H, I>, | ||
i: Transducer<I, J>, | ||
j: Transducer<J, K>, | ||
...fns: Transducer<any, any>[] | ||
a: TxLike<A, B>, | ||
b: TxLike<B, C>, | ||
c: TxLike<C, D>, | ||
d: TxLike<D, E>, | ||
e: TxLike<E, F>, | ||
f: TxLike<F, G>, | ||
g: TxLike<G, H>, | ||
h: TxLike<H, I>, | ||
i: TxLike<I, J>, | ||
j: TxLike<J, K>, | ||
...fns: TxLike<any, any>[] | ||
): Transducer<A, any>; | ||
export function comp(...fns: any[]) { | ||
fns = fns.map(ensureTransducer); | ||
return _comp.apply(null, <any>fns); | ||
} |
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,7 @@ | ||
import { implementsFunction } from "@thi.ng/checks"; | ||
import { IXform, Transducer, TxLike } from "../api"; | ||
|
||
export const ensureTransducer = <A, B>(x: TxLike<A, B>) => | ||
implementsFunction(x, "xform") | ||
? (<IXform<A, B>>x).xform() | ||
: <Transducer<A, B>>x; |
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
Oops, something went wrong.