predicate

How do I write a predicate that checks if a value exists in an infinite seq?

I had an idea for a higher-order function today that I'm not sure how to write. I have several sparse, lazy infinite sequences, and I want to create an abstraction that lets me check to see if a given number is in any of these lazy sequences. To improve performance, I wanted to push the values of the sparse sequence into a hashmap (or se...

Why doesn't this NSPredicate work?

Hey, I have an Array of MKAnnotation objects called arrAnnotations. I want to pick out one of the annotations with the same coordinate as the one stored in a CLLocation object called "newLocation". I'm trying to use an NSPredicate, but it doesn't work. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SELF.coordinate == %f)...

how to bind one function to other

I have a function A that accepts a predicate function as its argument. I have another function B and it takes a char and returns an int, and a function C that accepts int and returns a bool. My question is how to bind B and C to pass it to function A. Something like: A(bindfunc(B,C)) I know boost::bind works but i am looking for ...

IEnumerable<T>.Contains with predicate

I need just to clarify that given collection contains an element. I can do that via collection.Count(foo => foo.Bar == "Bar") > 0) but it will do the unnecessary job - iterate the whole collection while I need to stop on the first occurrence. But I want to try to use Contains() with a predicate, e.g. foo => foo.Bar == "Bar". Currentl...

Creating a template predicate class requiring a pointer to method function, and ensuing compiler errors

I'm building a series of predicates that duplicate lots of code, and so are being changed into a single template function class based on the std::unary_function. The idea is that my class interface requires methods such as Element_t Element() and std::string Name() to be defined, so the predicate template arguments are the object type an...

DRY LINQ Predicate Filters for Multiple Tables

Suppose I have two tables, TableA and TableB. Each record in A has one or more related records in B. Say I want a reusable filter using predicates. I might do something like this (Linq-to-SQL by the way): private Expression<Func<ARecord, bool>> FilterPredicate() { return x => x.Name == "Test"; } private IQueryable<ARecord> GetRecor...

Core Data - Setting a Relationship

Hello, I have a problem with Core Data which has left me at the end of my tether. So I was wondering if any of you wonderful people could help. Basically, I have two entities in a Core Data project. These are: Author {authorName, dateOfBirth} Book {bookName, pages} There is a one-to-many relationship from author to books called 'auth...

Method with Predicate as Parameter

This is a general question, but here is the specific case I'm looking for a solution to: I have a Dictionary<int, List<string>> I want to apply various predicates to. I want one method that can take care of multiple LINQ queries such as these: from x in Dictionary where x.Value.Contains("Test") select x.Key from x in Dictionary where ...

Predicates and OrderBy , Func....

i understand that predicates are delegate to function which return bool and take generic param , i understand that when i say mycustomer => mycustomer.fullname == 1 it actually means: delegate (Customer mycustomer) { return mycustomer.fullName == "John"; } the paramter im passing in when i ...

Predicate and distinct objects

I have entity Unit and Tag, each with to-many relation to other. I am using NSFetchedResultsController to manage the data. What I need is to return distinct Unit object into NSFetchedResultsController for condition Tag.show == YES. I'm not sure how to feed all this to NSFetchedResultsController. Set entity to Unit or Tag, how to build ...

Searching NSArray for an object

I have NSArray consisting of NSDictionary objects. Need to find index in NSArray of object with matching key name in NSDictionary. Dictionary has only 1 element. What is the fastest way of doing that? Filter with predicate and then use indexOfObject? ...

Predicate's label in JSF on Nuxeo.

Hi everyone. I'am on a JSF problem using Nuxeo : I would like to get a predicate label (like "label.relation.predicate.inverse.Requires") out of this very predicate inside a JSF. I tried to do many things and all the objects I have are "statement" and "node". I tried to figure the label from the "#{statement.predicate.uri}" and wethe...

Func or Predicate to ExpressionTree

Lets say i have : Func<Customer,bool > a = (c) => c.fullName == "John"; now i want to convert to expressiontree any way to do that ? i know i can define it from the first place as expressiontree but the situation i have is different because i must concatenate some lambda expressions first then pass it to a method which take express...

Scheme and Clojure don't have the atom type predicate - is this by design?

Common LISP and Emacs LISP have the atom type predicate. Scheme and Clojure don't have it. http://hyperpolyglot.wikidot.com/lisp Is there a design reason for this - or is it just not an essential function to include in the API? ...

Can you implement any pure LISP function using the ten primitives? (ie no type predicates)

This site makes the following claim: http://hyperpolyglot.wikidot.com/lisp#ten-primitives McCarthy introduced the ten primitives of lisp in 1960. All other pure lisp functions (i.e. all functions which don't do I/O or interact with the environment) can be implemented with these primitives. Thus, when implementing or porting lisp, the...

Convert func to predicate using reflection in C#

I'm basically trying to do this, but I don't know what T will be, so I'm building things up using Reflection and Expression trees. // Input (I don't know about "Book") Type itemType = typeof(Book); // Actual Code // Build up func p => p.AuthorName == "Jon Skeet" ParameterExpression predParam = Expression.Parameter(itemType, "p"); Expre...

How can I change a ViewController list (by changing predicate) without popping and pushing?

I have a ViewController whose view results from data from a fetch request with Predicate 1. I'd like to repeat the fetch request with a more restrictive Predicate 2 that will give a SUBSET of the data using Predicate 1. Then I'd like to update (and possibly animate) that view on the iPhone screen by pressing a toggle button, so that ...

How do I use the translate function in a predicate of a XPath argument to XmlDocument.SelectNodes?

I'm using C# and .NET 2.0. Given the XML below, I'd like to get a XMLNodeList of <user> nodes where the <role> is "admin". <users> <user> <name>John Doe</name> <roles> <role>superadmin</role> <role>admin</role> </roles> </user> <user> <name>Jane Doe</name> <rol...

Yet another .NET XPath predicate question...

Given this XML, I want to retrieve a XmlNodeList of <member> nodes from <group> nodes whose <id> matches 'Tech'. The matching should be case-insensitive. <groups> <group> <id>Tech</id> <members> <member>johndoe</member> <member>janedoe</member> <member>ro...

How can I pass additional parameters to predicate functions?

Can I pass additional parameters to a predicate function? I need it in a sorting process actually. public void Sort( Comparison<T> comparison ) where I would like to use Comparison predicate in this form: public delegate int Comparison<T>( T x, T y, object extraParameter ) Is this possible? Thanks, ...