problem about predicate-Collection of common programming errors


  • MPelletier
    vb.net linq predicate
    I need to build a dynamic linq query with or operators. I have seen PredicateBuilder but that is in C# and my project is in VB. Basically I need to build a WHERE clause similar to this:Where((this = 1 AND that = 2) OR (this = 1 AND that = 4) OR (this = 2 AND that = 4))but the problem is the number will have to be determined dynamically at runtime, and added using a loop, likefor each item in myItemsquery = query.OR (this = item.a AND this = item.b) nextHow could I go about doing that?

  • Maxim Gershkovich
    c# .net vb.net predicate
    When are predicates appropriate and what is the best pattern for usage? What are the advantages of predicates? It seems to me like most cases where a predicate can be employed a tight loop would accomplish the same functionality?I don’t see a reusability argument given you will probably only implement a predicate in one method right?They look and feel nice but besides that they seem like you would only employ them when you need a quick hack on the collection classes? UPDATEBut why would you be r

  • Dan Atkinson
    c# lambda antlr dsl predicate
    This is a simplified version of the original problem.I have a class called Person:public class Person {public string Name { get; set; }public int Age { get; set; }public int Weight { get; set; }public DateTime FavouriteDay { get; set; } }…and lets say an instance:var bob = new Person {Name = “Bob”,Age = 30,Weight = 213,FavouriteDay = ‘1/1/2000’ }I would like to write the following as a string in my favourite text editor….(Person.Age > 3 AND Person.Weight > 50) OR Person.Age < 3I wou

  • Andy G
    c# generics datagrid filter predicate
    Im trying to apply a filter to a DataGrid in WPF and the filter property needs a Predicate ex:dataGrid1.Filter = p => p.A_Field_Table1.Contains(textBox.Text);But my datagrid is being filled with reflection, so I only know the type of objects inside the datagrid at runtime.Then I created a method that dynamically generates the Predicate< T > :public static Predicate< T > GetPredicate< T >(string column, string valueP, T objSource, string table){Type itemType = typeof(T);Paramete

  • TheKido
    c# linq lambda expression predicate
    I have class that receives Type and an Expression (without TDeligate). I know the Expression is based on: Expression<Func<T, bool>> but I don’t have the T. Instead I have the Type. What I need is to execute the expression against a list and return the sub-list of results. Something like list.Where(Expression). Here is the method:public IEnumerable Query(Type type, Expression exp) {var list = GetListByType(type);return list.Where(exp); // << How do I make this happen? }Edit #1I

  • MikMik
    c++ stl set predicate
    I was refactoring some code and found there are two places that can be written with the same code except the comparator of a set is less<double> in one place and greater<double> in the other. Something like:double MyClass::Function1(double val) {std::set<double, less<double> > s;// Do something with s }double MyClass::Function2(double val) {std::set<double, greater<double> > s;// Do the same thing with s as in Function1 }So I thought of doing:double MyClass::G

  • atreat
    ios core-data nspredicate predicate
    I’m trying to create the following predicate[NSPredicate predicateWithFormat:@”name != %@ AND date %@ %@”, varName, operator, varDate]Where varName and varDate are NSString and NSDate objects respectively. The operator variable is declared like so:NSString *operator = (direction == kPageDirectionForward) ? @”>” : @”<“;Basically I want to save a couple lines when creating the predicate. I know I can create different predicates based on the value of direction, but this use case has me thinki

  • Piwacket
    xcode predicate sigabrt
    I’m a noob and trying to convert an example from a book into an app I can use. The sample app is a modified version of the contacts application and it works.I’ve done some further modification, and the search no longer works. It sigabrts on the following lineself.filteredAnswercards = [flattenedArrayfilteredArrayUsingPredicate:predicate];I’m stumped. my head is bloody from beating it against my keyboard. ANY help is massively appreciated.Thanks.

  • Dov
    objective-c ios core-data subquery predicate
    I am working on an app, which makes use of a Core Data Model and I am encountering a problem while using an NSPredicate.My data model looks like this:Asset 1 to 1 relationship with SearchAsset many to many relationship with SearchTermsAsset has several fields like unique_ID, URL, etc.. while SearchTerms has only one field called terms. SearchAsset has no fields, it only points to an Asset.When I want to do a search I call the following code:-(void)searchBar:(UISearchBar *)searchBar textDidChange

  • amitsbajaj
    ios uitableview core-data predicate searchbar
    I have a simple TableViewController which has an add button which goes over to a ModalViewController; the user adds in text into a text field, presses save and that dismisses and the entry is added to the Entities and Attributes in Core Data and displayed in the TableViewController. It works well. I firstly started off with another button that pulled up a UISearchBar in a Table View and I could search for results and pull that back; that worked. I then added a new tab to the bottom of the TableV

  • TechZen
    iphone ios core-data nspredicate predicate
    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 Predica

  • Schoob
    ios exception core-data predicate nsmanagedobjectcontext
    I’d like to execute a fetch request:NSFetchRequest *fetchRequest = [NSFetchRequest new]; [fetchRequest setIncludesPendingChanges:YES]; NSSet *set = [NSSet setWithObjects:@”TESTNAME”,@”TEST”, nil]; [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@”NONE name IN %@”, set]];when executing the request on an unsaved NSManagedObjectContext the app is terminated with exception:* Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘The left hand

  • lps
    iphone core-data count one-to-many predicate
    I have an entity matches which has a related to-many entity sets. I want to get a count of how many sets have the attribute ‘set_finished’ set to YES for a particular match. I’m trying to do this with:NSPredicate *predicate = [NSPredicate predicateWithFormat:@”ANY set_finished == YES”];NSUInteger numberOfFinishedSets = [[[match valueForKeyPath:@”sets”] filteredArrayUsingPredicate:predicate ] count];The second line crashes with this error, which I don’t understand. Can anyone shed some light on t

  • user1121366
    prolog swi-prolog predicate gnu-prolog
    I wrote the following simple code, and I expect that when I write ‘male.’, this code ask me once “is it male?” and if i input ‘No’ it write on screen “she is female”. male :- ( print(‘is it male ? ‘),read(yes)) -> true; asserta( not(male)),female. female:- not(male),print(‘she is female’). not(P) :- (call(P) -> fail ; true) .but this code has following error:uncaught exception: error(permission_error(modify,static_procedure,not/1),asserta/1);the error in swi-prolog is :ERROR: asserta/1: No

  • mbratch
    prolog predicate discrete-mathematics
    I am just starting to learn prolog. I am learning it for my CS 2300 class. I am trying to learn the basics right now. How do I add a predicate to my .pl file? I am just trying to add a predicate to my .pl file. I am doing this:married(X,Y) :- married(Y,X).And I get the errors:ERROR: Undefined procedure: (:-)/2 ERROR: Rules must be loaded from a file ERROR: See FAQ at http://www.swi-prolog.org/FAQ/ToplevelMode.txAm I supposed to enable this somehow?This is the given .pl file:% File FAMILY.PL

  • Lightness Races in Orbit
    c++ stl predicate
    I’m trying to write predicate function for use with STL algorithms. I see that they are two ways to define a predicate: (1) Use a simple function as below: bool isEven(unsigned int i) { return (i%2 == 0); }std::find_if(itBegin, itEnd, isEven); (2) Use the operator() function as below: class checker { public: bool operator()(unsigned int i) { return (i%2 == 0); } }; std::find_if(itBegin, itEnd, checker); I have more use for the second type as I usually would like to create a predicate

  • drby
    c++ stl functional-programming predicate
    Is there any way that you can combine predicates? Lets say I have something like this:class MatchBeginning : public binary_function<CStdString, CStdString, bool> { public:bool operator()(const CStdString &inputOne, const CStdString &inputTwo) const{ return inputOne.substr(0, inputTwo.length()).compare(inputTwo) == 0; } };int main(int argc, char* argv[]) {CStdString myString(“foo -b ar -t az”); vector<CStdString> tokens;// splits the string every time it encounters a “-“spli

  • deworde
    c++ vector sorting predicate user-defined
    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 {virtual bool operator()(const Loan& lhs, const Loan& rhs) const = 0; };struct strategyA : public Strategy {bool operator()(const Loan& lhs, const Loan& rhs) con

  • ChristianLinnell
    c# list delegates predicate
    It’s my understanding that if I want to get the ID of an item in a list, I can do this:private static void a() {List<string> list = new List<string> {“Box”, “Gate”, “Car”};Predicate<string> predicate = new Predicate<string>(getBoxId);int boxId = list.FindIndex(predicate); }private static bool getBoxId(string item) {return (item == “box”); }But what if I want to make the comparison dynamic? So instead of checking if item==”box”, I want to pass in a user-entered string to t

  • jjung
    android jython predicate monkeyrunner
    I want to use MonkeyRunner to generate MotionEvent (from screen touch). I have read the info on http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html.The problem is that for this jython program:from com.android.monkeyrunner import MonkeyRunnerif __name__ == ‘__main__’:# Connects to the current device, returning a MonkeyDevice objectdevice = MonkeyRunner.waitForConnection()I get the following error when executed:Traceback (most recent call last):File “C:\Documents and Se

  • lnafziger
    iphone objective-c core-data predicate nsfetchrequest
    I have a core data database and I am trying to create a fetch request using a block predicate, but I get an Unknown Predicate error:NOTE: employeeToHouse is a property of type House that was created for me when I subclassed NSManagedObjectNSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@”Place”]; request.predicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {Place *sortPlace = (Place *)evaluatedObject;CLLocation *place

Web site is in building