ramda.js - Transform objects pointfree style with Ramda -


given function below, how convert point-free style? nice use ramda's prop , path , skip data argument, can't figure out proper syntax.

const maptootherformat = (data) => (     {         'name': data.name         'email': data.user.email,         'foo': data.foo[0].bar     }); 

one option make use of r.applyspec, creates new function builds objects applying functions @ each key of supplied "spec" against given arguments of resulting function.

const maptootherformat = r.applyspec({    name: r.prop('name'),    email: r.path(['user', 'email']),    foo: r.path(['foo', 0, 'bar'])  })    const result = maptootherformat({    name: 'bob',    user: { email: 'bob@example.com' },    foo: [{ bar: 'moo' }, { bar: 'baa' }]  })    console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.22.1/ramda.min.js"></script>


Comments