question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ramda: Error in type definition for Pipe/Compose

See original GitHub issue

The definitions for Ramda for pipe and compose are incorrect.

The definitions specify that pipe takes a list of UnaryFns 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:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
keithamuscommented, Nov 7, 2016

FYI this is still very much on my radar, I’m filling out much of the TODOs as we speak. I hope to have a PR before the weekend.

1reaction
GAntoinecommented, Oct 10, 2017

Closing as it seems the changes were made at some point.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pipe typings not seeming to work.. · Issue #466 - GitHub
Why rambda cannot use types from ts-toolbelt as ramda does? Lots of types are broken or semi-broken - for example map when used...
Read more >
composeK - Ramda Documentation
Ramda defines the empty value of Array ( [] ), Object ( {} ), String ( '' ), and Arguments. Other types are...
Read more >
using ramda type definition, pipe function throws type error
I installed type definition file for Ramda (@types/ramda), when I write the following code, no complains: const gt5 = (x: number): boolean ...
Read more >
ramda/ramda - Gitter
The memoizeWith function takes a function of type (*, . ... '(fn: (x: number) => number, list: readonly number[]): number[]', gave the following...
Read more >
Creating a typed "compose" function in TypeScript
For this I had defined the interface for params, and wanted to be able to type the arguments. I wanted the signature of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found