Ramda: Error in type definition for Pipe/Compose
See original GitHub issueThe definitions for Ramda for pipe
and compose
are incorrect.
The definitions specify that pipe takes a list of UnaryFn
s which pipe through to the next. The docs for ramda contradict this though:
The leftmost function may have any arity; the remaining functions must be unary.
Case in point, I have a function that looks like this: pipe(zip, map(sum))
. This is valid Ramda code and passes my tests, but Flow is not having it.
As the first function pipe accepts can be variadic, I propose adding a new type alongside the UnaryFn definitions for a Variadic Definition:
declare module ramda {
+ declare type VariadicFn<A,R> = (...rest: A[]) => R;
declare type UnaryFn<A,R> = (a: A) => R;
So Pipe (whose first function and returning function which can be Variadic) becomes:
declare type Pipe = (<A,B,C,D,E,F,G>(ab: UnaryFn<A,B>, bc: UnaryFn<B,C>, cd: UnaryFn<C,D>, de: UnaryFn<D,E>, ef: UnaryFn<E,F>, fg: UnaryFn<F,G>, ...rest: Array<void>) => UnaryFn<A,G>)
& (<A,B,C,D,E,F>(ab: UnaryFn<A,B>, bc: UnaryFn<B,C>, cd: UnaryFn<C,D>, de: UnaryFn<D,E>, ef: UnaryFn<E,F>, ...rest: Array<void>) => UnaryFn<A,F>)
& (<A,B,C,D,E>(ab: UnaryFn<A,B>, bc: UnaryFn<B,C>, cd: UnaryFn<C,D>, de: UnaryFn<D,E>, ...rest: Array<void>) => UnaryFn<A,E>)
& (<A,B,C,D>(ab: UnaryFn<A,B>, bc: UnaryFn<B,C>, cd: UnaryFn<C,D>, ...rest: Array<void>) => UnaryFn<A,D>)
& (<A,B,C>(ab: UnaryFn<A,B>, bc: UnaryFn<B,C>, ...rest: Array<void>) => UnaryFn<A,C>)
& (<A,B>(ab: UnaryFn<A,B>, ...rest: Array<void>) => UnaryFn<A,B>)
And compose becomes
declare type Compose = & (<A,B,C,D,E,F,G>(fg: UnaryFn<F,G>, ef: UnaryFn<E,F>, de: UnaryFn<D,E>, cd: UnaryFn<C,D>, bc: UnaryFn<B,C>, ab: VariadicFn<A,B>, ...rest: Array<void>) => VariadicFn<A,G>)
& (<A,B,C,D,E,F>(ef: UnaryFn<E,F>, de: UnaryFn<D,E>, cd: UnaryFn<C,D>, bc: UnaryFn<B,C>, ab: VariadicFn<A,B>, ...rest: Array<void>) => VariadicFn<A,F>)
& (<A,B,C,D,E>(de: UnaryFn<D,E>, cd: UnaryFn<C,D>, bc: UnaryFn<B,C>, ab: VariadicFn<A,B>, ...rest: Array<void>) => VariadicFn<A,E>)
& (<A,B,C,D>(cd: UnaryFn<C,D>, bc: UnaryFn<B,C>, ab: VariadicFn<A,B>, ...rest: Array<void>) => VariadicFn<A,D>)
& (<A,B,C>(bc: UnaryFn<B,C>, ab: VariadicFn<A,B>, ...rest: Array<void>) => VariadicFn<A,C>)
& (<A,B>(ab: UnaryFn<A,B>, ...rest: Array<void>) => VariadicFn<A,B>)
This isn’t a perfect proposal, as these accepted functions can be unary, but the VariadicFn definition suffices for both.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:6 (4 by maintainers)
Top GitHub Comments
FYI this is still very much on my radar, I’m filling out much of the
TODO
s as we speak. I hope to have a PR before the weekend.Closing as it seems the changes were made at some point.