Search code examples
javascriptfunctional-programmingramda.jspointfree

Function composition using Ramda


I have a 2 functions and 1 variable which when combined take the form

const value = f(g(x))(x)

That is, f(g(x)) returns a function taking x again. I don't like this redundancy and it's preventing me from declaring my function pointfree.

What Ramda function do I need to transform this into R.something(f, g)(x)?

Here's a working example, testable in http://ramdajs.com/repl/?v=0.24.1,

const triple = x => x * 3
const conc = x => y => x + " & " + y

const x = 10

conc(triple(x))(x)

// I'm looking for R.something(conc, triple)(x)

Solution

  • You can use R.chain

    const something = chain(conc, triple)
    

    You can see this in action on the Ramda repl.