predicate

Help with Predicate<T> delegate

Hello, I am trying to create an overloaded Add method as an extension to the OrderedDictionary class and would like to add the key/value based on some curried predicate. The calling code would look like this: OrderedDictionary dict = new OrderedDictionary(); Predicate<int> lessThan5 = i=>; i < 5; Predicate<string> lenOf2 = s=> s.le...

Is there any way to negate a Predicate?

I want to do something like this: List<SomeClass> list1 = ... List<SomeClass> list2 = ... Predicate<SomeClass> condition = ... ... list2.RemoveAll (!condition); ... list2.AddRange (list1.FindAll (condition)); However, this results in a compiler error, as ! can't be applied to Predicate<SomeClass>. Is there any way to do this? ...

Finding elements in a scala list and also know which predicate has been satisfied

I have the following problem in scala. I have to find the first element in al list which satisfies a predicate function with two conditions in OR. The problem is that I would like to get the element but also know which of the two conditions has been satisfied. Here is a simple example: val l1 = List("A", "B", "AA", "BB") val l2 = List("...

XPath element which contains an attribute and whose parent's parent contains another attribute

Hey everyone, This is my first post here and since I've seen many great answers I thought I'd give it a try. I'm trying to use XPath to obtain a specific element in an HTML document. Here is an example based off of the Google web page: <html> <head> <title>XPath Test</title> </head> <body> <form name='f'> <table> ...

Transform items from iterable with a sequence of unary functions

I frequently find myself needing to apply a sequence of unary functions to a sequence of of the same length. My first thought is to go with map(), however this only takes a single function to be applied to all items in the sequence. In the following code for example, I wish to apply str.upper() to the first item, and int to the second i...

Predicate<Bool>, pointless or useful?

I'm trying to get my head around the Predicate<T> type and I can understand it when T is anything, except for bool. If you have Predicate<bool>, I don't see how that can be used. Can someone tell me if this is a silly thing to do or if it actually serves a purpose? Predicate<T> already returns a bool, so then testing a condition on a ...

lisp filter out results from list not matching predicate

hey I am trying to learn lisp, using emacs dialect and I have a question. let us say list has some members, for which predicate evaluates to false. how do I create a new list without those members? something like { A in L: p(A) is true }. in python there is filter function, is there something equivalent in lisp? if not, how do I do i...

How can I define a "Do-Nothing" sort?

Hi, I'm working on a system where I need to be able to sort a vector by a given predicate, which my classes shouldn't have control over. Basically, I pass them a derived class and they blindly sort on it. As one of the "delightful quirks", one of the sort patterns is order of entry. Here's what I've got so far. struct Strategy { vi...

What am I missing in this chain of predicates?

NOTE: Right before posting this question it occurred to me there's a better way of doing what I was trying to accomplish (and I feel pretty stupid about it): IEnumerable<string> checkedItems = ProductTypesList.CheckedItems.Cast<string>(); filter = p => checkedItems.Contains(p.ProductType); So OK, yes, I already realize this. However, ...

Collection was modified exception linq-to-objects

I got a strange exception when trying to find out if a property in a list of objects is equal for all objects. This is my code: bool lvNoGuests = pvBillData.Reservering.Dagen.All(x => { return x.AantalKinderen == pvBillData.Reservering.Dagen[0].AantalKinderen && x.AantalVolwassenen == pvBillData.Reservering.Dagen[0].Aan...

Predicates and Lists

Hello guys, I have a generic list. Some elements of this list belong to a parent element. I retrieved all these elements from a database and i want to recursively build a tree with them. So, here's what i'm thinking: Here is my predicate: public static bool FindChildren(Int32 parentId,CategoryMapping catMapping) { if (catMapping...

Predicate problem in ToSelectList

the ToSelectList method I have: public static IList<SelectListItem> ToSelectList<T>(this IEnumerable<T> itemsToMap, Func<T, string> textProperty, Func<T, string> valueProperty, Predicate<T> isSelected) { var result = new List<SelectListItem>(); foreach (var item in itemsToMap) { result.Add(new SelectListItem ...

How can I insert an additional argument after the last argument in a prolog procedure?

I am new to learning prolog, and I want to know, if we have some procedure like father("Nic","Adam"). and I want to write a function that it will add new value to this father("Nic","Adam","something"..) how can I do this? Using list? Or what? ...

Lisp: Determine if a list contains a predicate

As part of a homework assignment in Lisp, I am to use apply or funcall on any predicates I find. My question (uncovered in the coursework) is: how do I know when I've found a predicate in my list of arguments? I've done some basic google searching and come up with nothing so far. We're allowed to use Lisp references for the assignment...

XSLT: attribute value used as numeric predicate

Given <xsl:variable name="datePrecision" as="element()*"> <p>Year</p> <p>Month</p> <p>Day</p> <p>Time</p> <p>Timestamp</p> </xsl:variable> The expression $datePrecision[5] returns a nodeSet containing one text node with value "Timestamp", as expected. Later in a template, with a context element having an attribute @pr...

NSPredicate by NSManagedObject for many-to-one lookups

Hi guys, I've got the scenario with two NSManagedObjects, Arm and Person. Between them is a many-to-one relationship Person.arms and inverse Arm.owner. I'd like to write a simple NSPredicate where I've got the NSManagedObject *arm and I'd like to fetch the NSManagedObject *person that this arm belongs to. I could make a textual repres...

Objective-C: fetchManagedObjectsForEntity problem

Hi.I am trying to get value from CoreData entity name Person with predicate and then comparing with new data in dictionary.But it it returns every time 0 .And it creates about 5 person with same name. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"userName == %@",[flickr usernameForUserID:@"owner"]]; peopleList = (...

NSPredicate cause update editing to return NSFetchedResultsChangeDelete not NSFetchedResultsChangeUpdate

I have predicate inside of - (NSFetchedResultsController *)fetchedResultsController in a standard way starting from the CoreDataBook example. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"state=%@ && date >= %@ && date < %@", @"1",fromDate,toDate]; [fetchRequest setPredicate:predicate]; This works fine however when ...

How to use predicate builder with linq2sql and OR operator

I have two tables (TABLE1, TABLE2 - unique i know) that has a 1-to-many relationship respectively and a foreign key between ID columns of both tables. Using linq2sql I am trying to select all TABLE1 entries such that their corresponding TABLE2 values contains at least 1 item in the list I pass it. Here's some sample code I was using in...

Predicate for searching the first letter of each word in a string of words

I would like to create a predicate to search for a specific letter at the start of each word in a string of words e.g. all words starting with A in @"The man ate apples", would return ate and apples. Is it possible to create such a predicate? Thank you. ...