Am I using the copy_if wrong?

The copy_if algorithm looks something like this(taken from MSVC2010): template<class InIt, class OutIt, class Pr> inline OutIt copy_if(InIt First, InIt Last, OutIt Dest, Pr Pred) { for (; First != _Last; ++First) if (Pred(*_First)) *Dest++ = *First; return (Dest); } And as you can see the copy_if does not do a push_back, it just copy … Read more

Why doesn’t Java 8’s Predicate extend Function

The method in Predicate<T> returns boolean. The method in Function<T, Boolean> returns Boolean. They are not the same. Although there is autoboxing, Java methods don’t use wrapper classes when primitives would do. Also, there are differences like Boolean can be null while boolean can’t. It’s even more different in the case of Consumer<T>. The method … Read more

Combine Multiple Predicates

How about: public static Predicate<T> Or<T>(params Predicate<T>[] predicates) { return delegate (T item) { foreach (Predicate<T> predicate in predicates) { if (predicate(item)) { return true; } } return false; }; } And for completeness: public static Predicate<T> And<T>(params Predicate<T>[] predicates) { return delegate (T item) { foreach (Predicate<T> predicate in predicates) { if (!predicate(item)) { … Read more

Core Data: Query objectIDs in a predicate?

A predicate like NSPredicate *predicate = [NSPredicate predicateWithFormat:@”NOT (self IN %@)”, arrayOfExcludedObjects]; where the entity of the fetch request is the entity of objects in the array, should do what you want. This can, of course be combined with other clauses in a single predicate for a fetch request. In general, object comparisons (e.g self … Read more

OData $filter with multiple predicates

You can definitely combine predicates in the $filter. For example: /People?$filter=endswith(LastName,’Smith’) and startswith(FirstName,’Mary’) For details around supported operators and such please see this page: http://www.odata.org/documentation/odata-version-2-0/uri-conventions#FilterSystemQueryOption Currently OData doesn’t have a way to express the question “People which have at least one address”. Depending on your data it might be feasible to download all People fulfilling … Read more

Xpath expression with multiple predicates

The following should do what you’re after: /root/user[login=’user1′ and name=”User 1″ and profile=”admin” and profile=”operator”] Having two tests for the profile value might seem odd, but as there are multiple profile nodes then the condition will be satisfied as long as at least one node matches the test. The reason you can compare profile directly … Read more