predicate

What Javascript library can evaluate MongoDB-like query predicates against an object?

烂漫一生 提交于 2019-11-27 21:17:58
问题 Is there a javascript library that will allow me to express object predicates in a DSL similar to MongoDB's query language? For the sake of clarity in a large program, I'd like to be able to say: var obj = { a: 1, b: 'abcdefg' }, qry = { a: { $gt: 0 }, b: /^abc/ }; if(query(qry).matches(obj)) { // do something appropriate since } instead of: var obj = { a: 1, b: 'abcdefg' }; if(obj.a>0 && qry.b.test(obj.b)) { // do something appropriate } I'm using Node.js, so anything on NPM would be great.

Howto use predicates in LINQ to Entities for Entity Framework objects

醉酒当歌 提交于 2019-11-27 21:12:32
I'm using LINQ to Entities for Entity Framework objects in my Data Access Layer. My goal is to filter as much as I can from the database, without applying filtering logic to in-memory results. For that purpose Business Logic Layer passes a predicate to Data Access Layer. I mean Func<MyEntity, bool> So, if I use this predicate directly, like public IQueryable<MyEntity> GetAllMatchedEntities(Func<MyEntity, Boolean> isMatched) { return qry = _Context.MyEntities.Where(x => isMatched(x)); } I'm getting the exception [System.NotSupportedException] --- {"The LINQ expression node type 'Invoke' is not

C++ remove_if on a vector of objects

半世苍凉 提交于 2019-11-27 20:26:35
I have a vector (order is important) of objects (lets call them myobj class) where I'm trying to delete multiple objects at a time. class vectorList { vector<*myobj> myList; }; class myobj { char* myName; int index; bool m_bMarkedDelete; } I was thinking that the best way to do this would be to mark specific myobj objects for deletion and then call myList.remove_if() on the vector. However, I'm not exactly sure how to use predicates and such for this. Should I create a member variable in the object which allows me to say that I want to delete the myobj and then create a predicate which checks

Built-in Java 8 predicate that always returns true?

别来无恙 提交于 2019-11-27 19:56:42
Google Guava has a predicate that always returns true . Does Java 8 have something similar for its Predicate ? I know I could use (foo)->{return true;} , but I want something pre-made, analogous to Collections.emptySet() . There are no built-in always-true and always-false predicates in Java 8. The most concise way to write these is x -> true and x -> false Compare these to Predicates.alwaysTrue() // Guava and finally to an anonymous inner class: new Predicate<Object>() { public boolean test(Object x) { return true; } } Probably the reason that Guava has these built-in predicates is that there

How to write a BOOL predicate in Core Data?

我怕爱的太早我们不能终老 提交于 2019-11-27 18:04:20
I have an attribute of type BOOL and I want to perform a search for all managed objects where this attribute is YES . For string attributes it is straightforward. I create a predicate like this: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"userName = %@", userName]; But how do I do this, if I have a bool attribute called selected and I want to make a predicate for this? Could I just do something like this? NSPredicate *predicate = [NSPredicate predicateWithFormat:@"selected = %@", yesNumber]; Or do I need other format specifiers and just pass YES ? From Predicate Programming

XPath/XSLT nested predicates: how to get the context of outer predicate?

陌路散爱 提交于 2019-11-27 15:05:28
It seems that this question was not discussed on stackoverflow before, save for Working With Nested XPath Predicates ... Refined where the solution not involving nested predicates was offered. So I tried to write the oversimplified sample of what I'd like to get: Input: <root> <shortOfSupply> <food animal="doggie"/> <food animal="horse"/> </shortOfSupply> <animalsDictionary> <cage name="A" animal="kittie"/> <cage name="B" animal="dog"/> <cage name="C" animal="cow"/> <cage name="D" animal="zebra"/> </animals> </root> Output: <root> <hungryAnimals> <cage name="B"/> <cage name="D"/> <

How to apply multiple predicates to a java.util.Stream?

假装没事ソ 提交于 2019-11-27 10:51:51
How can I apply multiple predicates to a java.util.Stream's filter() method? This is what I do now, but I don't really like it. I have a Collection of things and I need to reduce the number of things based on the Collection of filters (predicates): Collection<Thing> things = someGenerator.someMethod(); List<Thing> filtered = things.parallelStream().filter(p -> { for (Filter f : filtersCollection) { if (f.test(p)) return true; } return false; }).collect(Collectors.toList()); I know that if I knew number of filters up-front, I could do something like this: List<Thing> filtered = things

Core Data Predicate Date Comparison

感情迁移 提交于 2019-11-27 07:08:19
Im trying to fetch all the objects in an entity matching a user selectedDate (it's an NSDate). The Core Data code is fine but my predicate keeps returning 0 results, the dates are the same in the database as the user is selecting. How should the selectedDate be compared with a date from an entity using a predicate? NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(eDate = %@)", selectedDate]; Your predicate looks to be fine. The reason you're finding zero result are returned however may be that the dates aren't entirely the same. For example: 05/04/2012 13:37:00 will not match with

Combine Multiple Predicates

一曲冷凌霜 提交于 2019-11-27 07:05:47
Is there any way in c# .NET 2.0! to combine multiple Predicates? Let's say I have the following code. List<string> names = new List<string>(); names.Add("Jacob"); names.Add("Emma"); names.Add("Michael"); names.Add("Isabella"); names.Add("Ethan"); names.Add("Emily"); List<string> filteredNames = names.FindAll(StartsWithE); static bool StartsWithE(string s) { if (s.StartsWith("E")) { return true; } else { return false; } } This gives me: Emma Ethan Emily So this is pretty cool stuff, but I know want to be able to filter using multiple predicates. So I want to be able to say something like this:

Crash using Aggregate Operation: “ALL” in a Core Data iOS Application

荒凉一梦 提交于 2019-11-27 06:11:28
问题 I'm working on an iphone application and I have a simple many-to-many relationship set up with Group and Contact objects. A group can have many contacts and contacts can belong to multiple groups. I'm trying to select all groups that a particular contact does NOT already belong to using the following predicate. (Note: the uid field is a string field that I used to uniquely identify contact entities) [NSPredicate predicateWithFormat:@"ALL contacts.uid != %@", contactUId] According to Apple's