I implemented mixin to add an βorβ condition using _.where
var arr = [{a:1,b:4}, {a:5}, {a:6}, {a:11}];
_.mixin({
or: function(obj,arr,condition){
return _.chain(arr).where(condition).union(obj).value();
}
});
now i can use it like this and it works fine as sql query
_.chain(arr).where({a:1}).or(arr,{a:11,b:3}).or(arr,{a:2}).value();
_.chain(arr).where({a:1}).or(arr,{a:11}).or(arr,{a:2}).value();
_.chain(arr).where({a:1}).or(arr,{a:11}).or(arr,{b:4}).value();
but I want to find a better way to just call _.or ({a: 1}), right now I have to pass arr every time _.or (arr, {a: 1}), as the "or" chain gets the first object as a result previously performed functions.
Is there a way to get the whole array in a mixin function chain?
I want the same result returned below as my previous implementation. (like perfect sql query)
_.chain(arr).where({a:1}).or({a:11,b:3}).or({a:2}).value();
, , , , lodash - , . , , , . , . .
jsFiddle