ramda / ramda

:ram: Practical functional Javascript

Home Page:https://ramdajs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`groupBy` throws inscrutable errors when inferred to be a transducer

brekk opened this issue · comments

    return pipe(
      chain(
        pipe(
          groupBy(interpreter?.group ?? 'unknown'),
          // this reducer can replace the groupBy call:
          /*
          reduce((agg, g) => {
            const lookup = interpreter?.group ?? 'unknown'
            const prev = agg[g[lookup]] ?? []
            agg[g[lookup]] = [...prev, g]
            return agg
          }, {}),
          */
          writeCommentsToFiles({ interpreter, outputDir })
        )
      )
    )(listOfFutureWrappedComments)

I have some code like this, working with a list of Futures. When I try to use groupBy I get an inscrutable error that says keyFn is not a function. I figure that is related to this bit of code:

var key = keyFn(elt);
but I'm not certain. I have chosen to eschew the groupBy code in the interim, but I would really hope that ramda give me something more helpful to go on.

I can come up with a smaller / reproducible case if valuable, but since the error is nominally related to my code I wanted to raise this as is. I would love if ramda gave me some indication of what I did wrong in the groupBy call.

My assumption is that b/c Futures support transducing, and so this call is magically being delegated incorrectly. But I don't know b/c the error gives me nothing and doesn't even point at the code I wrote.

As I look at this actual function I see the problem 😅 Sorry for the trouble

groupBy(prop('x')) vs. groupBy('x') is the crux. But it'd be nice if ramda helped underline that for me

Sorry for the trouble

No trouble!

But it'd be nice if ramda helped underline that for me

If you aren't using them already, the types are getting better and better, they could have helped you here :)

😬 That might be trading one issue for another bigger one. I think TS is another problem space, well-defined. (ramda + generics involves so much annotation that I find it exhaustingly slow to develop against (at least last time I tried, 2ish years ago), but that's a subjective opinion. I think TS + curried functions is an exhausting endeavor currently) The monorepo I'm working in has plans to add more TS in the coming months, so I may end up eating my words.