3 ms·
Consider this: http://ramdajs.com/docs/#sort http://ramdajs.com/docs/#sort Say I want to sort a list of objects/records that have a "name" field by name. I c
by Roboprog 10y ago
Consider this: http://ramdajs.com/docs/#sort http://ramdajs.com/docs/#sort
Say I want to sort a list of objects/records that have a "name" field by name. I can compose some functions to do this, and use the resulting function where needed (regardless of the input object list "type(s)", as long as it/they quacks back with a "name" property/field).
I'm going to assign some functions to intermediate symbols, but that's not strictly required, since functions are an expression/value like many other things.
var name_comp = function( l, r ) { return l < r }
var sort_by_name = R.sort( name_comp )
// alternatively: ... = R.sort( function ( l, r) { return l < r } )
...
var old_list = [
{ name: 'Middle', foo: 'bar' },
{ name: 'Zero', bluk: 'phooey' },
{ name: 'Alpha', answer: 42 }
]
...
var new_list = sort_by_name( old_list ) // ... Alpha ... Middle ... Zero ...
In general, the curried arguments can be primitives and objects, as well as functions.
The Ramda library is primarily geared around taking common "collections" types of operations and chaining them together. It has other FP "mathy" stuff that I still have not got my head around yet, as well.