javascript - Using Ramda map helper in pointfree way -
how can change code:
map(user => assoc('isadult', isadult(user), user)
to function pointfree (using ramda). thinking how usewith, can't find working implementation.
any ideas?
import { pipe, prop, gte, __, map, assoc, sortwith, descend } 'ramda' const isadult = pipe( prop('age'), gte(__, 18) ) const func = pipe( map(user => assoc('isadult', isadult(user), user)), sortwith([ descend(prop('isadult')), descend(prop('age')), ]) ) export default func
edit (more info):
i want create function returns array of objects extended isadult
key. if user more 18 years old, set flag true
.
in addition, function should return users sorted flag isadult
, sorted key age
.
sample data:
const data1 = [ { name: 'cassidy david', email: 'sit@nullaeuneque.co.uk', id: 'fc92bf1e-a6fd-e5c1-88ab-183bd1bc59c5', position: 1, age: 53, created_at: '2017-04-07' }, { name: 'gwendolyn edwards', email: 'ut.mi.duis@elementumsemvitae.net', id: '00000001-ed9d-3a88-0d3c-07a148fd43ed', position: 2, age: 10, created_at: '2016-05-21' },
i think it's debatable whether trying make point-free useful.
this quite readable is:
map(user => assoc('isadult', isadult(user), user)),
point-free great technique can enhance readability. if doesn't, wouldn't bother it.
that said, if want try point-free, chain
helpful. note how chain works functions: chain(f, g)(x) //=> f(g(x), x)
.
so can write relevant part
map(chain(assoc('isadult'), isadult))
you can see in action on ramda repl.
Comments
Post a Comment