FAQ Database Discussion Community


operators in predicate as argument in lambda expression

java,lambda,type-conversion,java-8,predicate
I need to use Predicate as argument in lambda expression. I tried an example code but seeing compiler error. I see that the compiler is treating the same Predicate differently for different arguments. So Predicate arguments n -> true and n -> false works but n -> n%4 == 0...

Lambda expression alternative to several if statements

c#,lambda,expression,predicate
I'm trying to accomplish an expression function alternative private static Expression<Func<UserProfile, bool>> CompareFilter(FilterViewModel f) { ... } on this one: private static bool CompareFilter(UserProfile profile, FilterViewModel filter) { if (filter.FirstName != null) { if (profile.FirstName != null) { if (profile.FirstName.CompareTo(filter.FirstName) != 0) { return false; } } else { return...

Method reference and chained predicate

java,java-8,predicate,java-stream,method-reference
I'm trying to compactify my code with method references. Here is a line that I'm trying to improve: assertThat("only true & false strings allowed", records.stream().map(Record::getType) .allMatch(s -> "true".equals(s) || "false".equals(s))); With method reference it could be much nicer: assertThat("only true & false strings allowed", records.stream().map(Record::getType).allMatch("true"::equals)); But can I anyhow add...

Two parameters in a predicate function

python-3.x,predicate
Is there a way that I can write a predicate function that will compare two strings and see which one is greater? Right now I have def helper1(x, y): return x > y However, I'm trying to use the function in this way, new_tuple = divide((helper1(some_value, l[0]),l[1:]) Please note that...

What's the module name of built-in predicate 'term_string/3' in SWI-Prolog 7.1.3?

module,prolog,predicate,swi-prolog,built-in
I am using a framework that has globally overridden the built-in predicate term_string/3 with different behaviour. Now i would like to use the built-in one, but what is its module name? I would like to call <ItsModuleName>:term_string(..) I know that list operations have a separate module :- use_module(library(lists)) that can...

Using predicate to find if string value exists

ios,objective-c,xcode,predicate
I have a NSMutableArray of objects with tag attributes assigned to them. I am trying to find if any of these objects have a tag assigned to them of the string value "a". my code so far: for (Object *object in self.array) { NSDictionary *attrs = [object propertyValue:@"attrs"]; NSString *tag...

How can I negate a lambda Predicate?

java,lambda,predicate
Lets say I have a Stream of Strings. final Stream<String> stream = ...; I want to filter out each empty string after trimmed. stream .filter(Objects::nonNull) .map(String::trim) .filter(v -> !v.isEmpty()); Is there any way to apply Predicate#negate() for replacing v -> !v.isEmpty() part? .filter(((Predicate) String::isEmpty).negate()) // not compile ...

Linq predicate query results is not working for further Linq Join

c#,linq,dynamics-crm-2011,predicate,linqkit
I am using results from Predicate query to write join in Linq query. Bit it is throwing following error. However when I run similar query in SQL, it return expected results. var predicate = PredicateBuilder.False<Product>(); foreach (var productId in productIds) { var tempGuid = productId; predicate = predicate.Or(p => p.ProductId==...

Complex query prolog

prolog,predicate,complextype
Yeah, I just was wondering if it is possible to make complex queries in Prolog. I have a database of tablets with many attributes. tablet(Id, Name). tablet_operating_system(Id, Operating_system). tablet_release_year(Id,Release_Year). tablet_screen_diagonal(Id, Diagonal). and so on... Well, I need to create a list that matches different conditions: Select all tablets that have...

How to define a predicate in SMT-LIB

predicate,smt
How would I define a predicate such as even: Int -> Bool, which takes an integer and outputs whether it is even or not? I tried something like (set-logic AUFNIRA) (declare-fun even (Int) Bool) I want to know how to declare, for example, that even(2) is true. ...

selenium filter with Predicate

java,selenium,lambda,java-8,predicate
I am looking to use and learn about the Predicate and Lambda expression. In particular using it with selenium. Imagine you have a large selection(List) of WebElements and you want to apply a predicate filter to it so that the list is smaller . Am I on the right track...

NSPredicate - EXC_BAD_INSTRUCTION (code= EXC_I386_INVOP, subcode=0x0)

ios,swift,core-data,predicate
I'm trying to read a data from CoreData with multiple NSPredicates, but I'm getting EXC_BAD_INSTRUCTION (code= EXC_I386_INVOP, subcode=0x0). Here is the code where I try to read the data: public class func fetchSetting(key: NSString, countryId: Int) -> Setting { let fetchRequest = NSFetchRequest(entityName: "Setting") var existingSetting: Setting? let keyPredicate =...

Get a sub-list of string matching a list of word

c#,linq,predicate
List<string> myList = new List<string>() { "This is a first matching exemple", "This is second matching exemple", "this one don't match", "Here, the last item" }; List<string> words = new List<string>() { "This", "is" }; How can i get a list matching all the words List<string> result = myList.Contains(AllWords???); Edit...

How to use predicates with LINQ to query CRM 2011

linq,linq-to-entities,dynamics-crm-2011,predicate,linqkit
I am trying to use linqkit to Predicate. Getting following code when I am trying to compile. public void TestPredicate(Guid[] productIds) { var predicate = PredicateBuilder.False<Product>(); foreach (var productId in productIds) { var tempGuid = productId; predicate = predicate.Or(p => p.ProductId== tempGuid); } } var query = from p in...

breeze: how to filter collection in count condition

collections,breeze,predicate
I have a class named A, it has a property B who is a collection of class C, and I want to filter some records of A by A.B.count > 0, below is my tried queries: breeze.Predicate.create("B().length", ">", 0); breeze.Predicate.create("B()[0]", "!=", null); breeze.Predicate.create("B()","all","length", ">", 0); I got the error:TypeError: this._fnNode1...

Specialize a function template in c++?

c++,function,sorting,templates,predicate
I have to create a generic function to sort strings in C++, and I have to test it with my own string class (which I have implemented as SuchString). I have a template like this: template<typename T, class Sel> void stringSort(T& lel); the Sel class contains a predicate function to...

Uniqueness and other restrictions for Arbitrary in QuickCheck

haskell,unique,predicate,quickcheck
I'm trying to write a modified Arbitrary instance for my data type, where (in my case) a subcomponent has a type [String]. I would ideally like to bring uniqueness in the instance itself, that way I don't need ==> headers / prerequisites for every test I write. Here's my data...

Passing a predicate that was passed in as a parameter

c#,linq,parameters,predicate
I'm having trouble with passing in a predicate to another function. This predicate would have been passed in as a parameter that is trying to call the second function. Below is a code snippet. public IEnumerable<ViewModel> BuildModel<TPart, TRecord>(Expression<Func<TRecord, bool>> predicate) where TPart : ContentPart<TRecord> where TRecord : ContentPartRecord { IEnumerable<ReportPart>...

returning entries based on a is contained predicate with sql [duplicate]

sql,postgresql,recursion,predicate
This question already has an answer here: how to make a sql loop? 3 answers I stumbled upon a very hideous problem, here is my table filesystem (id, name, parentid); and some entries for the example (1, 'root', null) (2, 'folder1', 1) (3, 'subfolder1.1', 2) (4, 'subfolder1.2', 2) (5,...

Is there a way to find the first element to match a Predicate? [duplicate]

java,performance,filtering,predicate,java-stream
This question already has an answer here: Java 8 find first element by predicate 2 answers With Java 8+, you can easily find all elements of a collection that match a Predicate. someCollection.stream().filter(somePredicate) You could then find the first element: someCollection.stream().filter(somePredicate).findFirst() The problem with this, though, is that it...

CoreData Many-to-Many Find Duplicates

ios,core-data,join,nspredicate,predicate
I am working on a predicate to search for users with the same preferences as any other user Users <<->> Preferences Given the following state; I wish to check for a new registering user (Sam, nickname: "foo", language: "english") to see if any existing users have the same preferences. There...

Adding two int variables from a KB [Prolog]

prolog,predicate
am a Prolog newbie and am currently learning logic in computing simultaneously so please excuse my lack of coherence on this topic. I am trying to provide a conditional that allows the user to add any two of 1, 2 and 3 to find its sum. I want to make...

SQL: from predicate logic to SQL SELECT

sql,predicate
I am trying to understand how to effectively translate predicate logic to SQL Queries. I am stuck at: For all P(x), (for all P(y), (Knows(x,y) -> Likes(x,y))) which I further translated to: -exists P(x), (exists P(y), (Knows(x,y) /\ -Likes(x,y))) Using as 'formulas': for all x, (A -> B) <=> -exists...

R check if a list of TRUE/FASLE values evaluate to TRUE

r,list,vector,predicate
I am relatively new to R so sorry if this is basics. I have this loop that have a condition inside that compares between 2 lists and return a vector of TRUE/FALSE values. What I really need to check is if this vector includes ONLY TRUE values (meaning the 2...

C# predicate list passed to linq Where clause

c#,linq,where,predicate
I have a long linq .where clause that I would like to populate with a predicate list. List<Expression<Func<Note, bool>>> filters = new List<Expression<Func<Note, bool>>>(); filters.Add(p => p.Title != null && p.Title.ToLower().Contains(searchString)); filters.Add(p => p.Notes != null && p.Notes.ToLower().Contains(searchString)); filters.Add(GlobalSearchUser((List < User > users = new List<User>() { p.user1, p.user2, p.user3,...

Wait the end of a predicate Prolog

prolog,wait,predicate
I have a predicate list_moves(Move), that gives all the possible moves for a game. Then I have the following predicates : find_best_move:- nb_setval(best,0), list_moves(NewMove), nb_getval(best,OldMove), better(OldMove,NewMove). better(OldMove, NewMove):- NewMove > OldMove, nb_setval(best,NewMove), !. better(_,_). get_best_move(Move):- find_best_move, nb_getval(max,Move). I want to get only one move when I call get_best_move(Move) : the...

How to make an array of all elements following X?

prolog,predicate
I need to write a predicate next(X, List1, List2), which returns List2, an array of elements which directly follow X. For example, next(v1,[v1,v2,v3,v1,v2,v1,v5],L) returns L=[v2,v2,v5] next(b,[b,k,m,b,j],L) returns L=[k,j] next(s,[s,b,c,d,e,f,s,c,s,g],L) returns L=[b,c,g] .... I know that recursion and tail must be used. I think I know the logic and how the...