0

I can't figure out a transform for f(x)(g(x)) using the functions available in Ramda. I'm hoping for something like R.something(f, g)(x) ideally - just so long as x only appears once and is the final argument.

f is a function taking x that returns a function

g is a function taking x that returns a value

I've tried pipe,compose,chain, but tbh I'm guessing pretty hard and no one of them work. I recently asked a similar question and I'd love to know a resource with loads of useful identities if one exists so I don't need to keep asking on SO :)

RichK
  • 11,318
  • 6
  • 35
  • 49
  • 1
    Btw, if you consider `constant = x => y => x` this is an applicative functor. –  Oct 05 '17 at 06:11

1 Answers1

2

chain was close: it does chain(f, g)(x) == f(g(x))(x) on functions. So you just need to flip f before passing it into chain:

R.chain(R.flip(f), g)(x)

or

const something = R.compose(R.chain, R.flip)
something(f, g)(x)
Bergi
  • 630,263
  • 148
  • 957
  • 1,375