I like the implementation to be as generic and functional (as in functional programming) as possible, but generally speaking, i'm expecting a json objected with the following structure:
[
{
id: number,
prop1: string,
prop2: number,
prop3: string,
...,
propN: string
},
...
]
(basically, an array of object that contain N properties, some mapped to strings and others to numbers)
I am trying to implement a generic set of functions so that i'll be able to achieve something to this end:
var filteredResult = filter(by(property, value, lt\gt\eq\contains), collection);
basically, I'd like to return an array with the same object structure, filtered by a property string that I pass into by(), along with the value (either a string or a number) and the type of comparison i'd like to perform.
generally speaking, for numbers I'd like to be able to filter results where property values are greater/lessthan/in range of the value I pass, with with strings, or arrays of strings, I'd like to find out if the property value contains the value I pass into by().
Since I'm new to FP, i'm struggling with formatting my code to take advantage of the auto-currying Ramda provides and I'm having trouble composing the different functions while passing the arguments I want.
For example, I've written this function:
var byProperty = function(p) {return R.useWith(R.filter, R.propEq(p), R.identity)};
but when I try to use it like so:
var property = 'prop1', value = 15;
console.log( byProperty( property, value, collection ) );
I get a function instead of the filtered array.
I know I'm missing something trivial here, but it's been kind of hard for me to wrap my head around the way values and functions are passed around in Ramda.