When I have a stream of objects, e.g.
values = Bacon.fromArray([ {'status':"active"}, {'status':"inactive"} ]);
I can apply a short form filter, like this:
activeStates = values.filter( ".status", "active" );
But when the original stream contains only primitives:
states = Bacon.fromArray( ["active", "inactive" ] );
Then I can no longer use that form, and I have to write a function literal. I have tried using "."
, ""
, null
, for the property name argument but that doesn't work.
I can define a function like this:
function equals( val ){
return function( obj ){
return obj === val;
}
}
And then write:
activeStates = values.filter( equals( "active" ) );
Is this the best I can do? Or is there either a Bacon function that I'm missing, or a common lodash function that saves me from writing my own equals
function?
You can use the Bacon.matchers library to implement such filters.
JsFiddle