predicate

How to define a predicate as a function argument

I want to be able to write something as void Start(some condition that might evaluate to either true or false) { //function will only really start if the predicate evaluates to true } I'd guess it must be something of the form: void Start(Predicate predicate) { } How can I check inside my Start function whenever the predicate e...

Java: minimum number of operations for conjunctive inequalities?

I try to simplify conditionals in: for ( int t=0, size=fo.getPrintViewsPerFile().size(); t<size && t<countPerFile; t++) { // ... } , more precisely: t<s && t<c You need to compare two times, then calc the boolean value from them. Is there any simpler way to do it? If no, how can you prove it? I can simplify...

Predicate<int> match question

Hi, I do not understand how following code works. Specifically, I do not understand using of "return i<3". I would expect return i IF its < than 3. I always though that return just returns value. I could not even find what syntax is it. Second question, it seems to me like using anonymous method (delegate(int i)) but could be possible t...

Using Predicate of a class to Search Generic list - Faster than looping?

Lets say we have a generic list of Class1, typically having ~100 objects for a given session. I would like to see if the list has a particular object. ASP.NET 2.0 allows me to do this: Dim objResult as Class1 = objList.Find(objSearch) How does this approach rate when compared to a traditional For loop, looking at a performance perspe...

Proving Predicate Logic using Coq - Beginner Syntax

I'm trying to prove the following in Coq: Goal (forall x:X, P(x) /\ Q(x)) -> ((forall x:X, P (x)) /\ (forall x:X, Q (x))). Can someone please help? I'm not sure whether to split, make an assumption etc. My apologies for being a complete noob ...

Filtering subsets using Linq

Hi All, Imagine a have a very long enunumeration, too big to reasonably convert to a list. Imagine also that I want to remove duplicates from the list. Lastly imagine that I know that only a small subset of the initial enumeration could possibly contain duplicates. The last point makes the problem practical. Basically I want to filter ...

pointer delegate in STL set.

I'm kinda stuck with using a set with a pointer delegate. My code is as follows: void Graph::addNodes (NodeSet& nodes) { for (NodeSet::iterator pos = nodes.begin(); pos != nodes.end(); ++pos) { addNode(*pos); } } Here NodeSet is defined as: typedef std::set<Node_ptr, Node_ptr_Sorting_Predicate> NodeSet; The above piece...

Linq to Sql select from multiple table

Hello; I have a question about selecting from multiple tables in C# using Linq. Table structure is like this: TABLE A TableAID Column1 Column2 TABLE B TableBID TableAID Column3 Column4 So in code i have: List<string> myList = new List{"Test1","Test2"}; var myView = MYDC.TableA.AsQueryAble(); If I want to select records from tab...

iPhone: Get indexPath of Predicate Object

I am using a predicate to find an object in core data. I can successfully find the object that I want, but I need to also get the indexPath of that object, so that I can push a details view in for that object. Currently I have the following code for getting my object: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; ...

Predicate in Java

I am going through the code which uses Predicate in Java. I have never used predicate. Can someone guide me to any tutorial or conceptual explanation of predicate and their implementation in java ? Google didnt help much... ...

How do I create a set with std::pair thats sorted based on the ::second pair member using bind

I know I could use the following: template <typename Pair> struct ComparePairThroughSecond : public std::unary_function<Pair, bool> { bool operator ()(const Pair& p1, const Pair& p2) const { return p1.second < p2.second; } }; std::set<std::pair<int, long>, ComparePairThroughSecond> somevar; but wondered if i...

iPad: CoreData FetchedRequest Ignores Changes in Predicate

Hi there, While programming an iPad-app, I'm just running into trouble using a fetchedResultsController with a "dynamic" predicate. it seems the changes to the predicate get ignored. No matter how the predicate changes, I always get the result of the first fetch ... same code runs without no problems on iphone-env (3.1.x) !! sample : ...

How to write a custom predicate for multi_index_containder with composite_key?

I googled and searched in the boost's man, but didn't find any examples. May be it's a stupid question...anyway. So we have the famous phonebook from the man: typedef multi_index_container< phonebook_entry, indexed_by< ordered_non_unique< composite_key< phonebook_entry, member<phonebook_entry,std::string,&...

NSString *predicateFormat how to search two entities....

hello there and sorry for the stupid question but i think i might be missing something simple here and can t figure it out myself. i m trying to search a table view using the following code: - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { NSString...

Help creating a predicate for use with filteredArrayUsingPredicate

I am trying to learn how to use predicates and so am trying to replace the following working code with filteredArrayUsingPredicate... [filteredLocations removeAllObjects]; for (NSString *location in locations) { NSRange range = [location rangeOfString:query options:NSCaseInsensitiveSearch]; if (range.length > 0) { [filteredLocat...

List<object>.RemoveAll - How to create an appropriate Predicate

This is a bit of noob question - I'm still fairly new to C# and generics and completely new to predicates, delegates and lamda expressions... I have a class 'Enquiries' which contains a generic list of another class called 'Vehicles'. I'm building up the code to add/edit/delete Vehicles from the parent Enquiry. And at the moment, I'm sp...

Problem using templated predicate in STL algorithms

I have the following piece of code, that gives an error on the first usage form of pred2. I was hoping if someone could explain why this particular usage is incorrect, as I think pred3 usage is similar. #include <algorithm> bool pred1(const int&) { return true; } template<typename T> bool pred2(const T&) { return true; } struct pred3...

Why doesn't this NSPredicate work?

I have a very simple NSPredicate as such: NSPredicate *sPredicate = [NSPredicate predicateWithFormat:@"name beginswith '%@'", theString]; [matchingTags filterUsingPredicate:sPredicate]; This causes the array to have 0 results when theString == "p" However, when I do this: NSPredicate *sPredicate = [NSPredicate predicateWithFormat:@"...

Trying to get VB anonymous methods working. querying lists

I am trying to get my code working as per the instruction on http://www.paulstovell.com/vb-anonymous-methods So far I have the wrapper: Public Delegate Function PredicateWrapperDelegate(Of T, A)(ByVal item As T, ByVal argument As A) As Boolean Public Class PredicateWrapper(Of T, A) Private _argument As A Private _wrapperDelegat...

ruby idiom: predicates and the conditional operator

I like judicious use of the ternary, conditional operator. To my mind it's quite succinct. However, in ruby, I find I'm often testing predicate methods, which already have their own question marks: some_method( x.predicate? ? foo : bar ) I'm jarred by those two question marks so close to each other. Is there an equivalently compact...