predicate

Create custom Predicate with Set<String> and String as parameter

房东的猫 提交于 2019-12-05 02:11:12
I have a String as "ishant" and a Set<String> as ["Ishant", "Gaurav", "sdnj"] . I need to write the Predicate for this. I have tried as below code, but it is not working Predicate<Set<String>,String> checkIfCurrencyPresent = (currencyList,currency) -> currencyList.contains(currency); How can I create a Predicate which will take Set<String> and String as a parameter and can give the result? A Predicate<T> which you're currently using represents a predicate (boolean-valued function) of one argument . You're looking for a BiPredicate<T,U> which essentially represents a predicate (boolean-valued

NSPredicate cause update editing to return NSFetchedResultsChangeDelete not NSFetchedResultsChangeUpdate

扶醉桌前 提交于 2019-12-05 01:15:24
问题 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 editing an item, it returns with NSFetchedResultsChangeDelete not Update. When the main view returns, it is missing the item. If I restart the simulator the delete

Convert func to predicate using reflection in C#

耗尽温柔 提交于 2019-12-05 00:02:17
问题 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"); Expression left = Expression.Field(predParam, itemType.GetField("AuthorName")); Expression right = Expression.Constant("Jon Skeet", typeof(string)); Expression

EntityFramework Casting issues

*爱你&永不变心* 提交于 2019-12-04 17:24:16
I am building my query using PredicateBuilder from LinqKit. it is great and does exactly what i am looking for. To make my code more reusable (tables and views) i created a generic predicate builder class: public class LocalPredicateBuilder<T> where T : IResort ... var predicate = PredicateBuilder.True<T>( which exposes BuildPredicate method. I can use it like this: var predicate = new LocalPredicateBuilder<Resort>().BuildPredicate(); var resorts = _entities.Resorts.Where(predicate).ToList(); however when i try to do this, i get this runtime error (btw entity objects implement IResort): Unable

Prolog — symetrical predicates

半腔热情 提交于 2019-12-04 14:46:37
I have to simulate family tree in prolog. And i have problem of symetrical predicates. Facts: parent(x,y). male(x). female(y). age(x, number). Rules: blood_relation is giving me headache. this is what i have done: blood_relation(X,Y):-ancestor(X,Y). blood_relation(X,Y):-uncle(X,Y);brother(X,Y);sister(X,Y);(mother(Z,Y),sister(X,Z));(father(Z,Y),sister(X,Z));(father(Z,Y),brother(X,Z)). blood_relation(X,Y):-uncle(X,Z),blood_relation(Z,Y). and I am getting i think satisfactory results(i have double prints - can i fix this), problem is that i want that this relation be symmetrical. It is not now.

Why do C++ classes without member variables occupy space?

限于喜欢 提交于 2019-12-04 10:09:33
问题 I found that both MSVC and GCC compilers allocate at least one byte per each class instance even if the class is a predicate with no member variables (or with just static member variables). The following code illustrates the point. #include <iostream> class A { public: bool operator()(int x) const { return x>0; } }; class B { public: static int v; static bool check(int x) { return x>0; } }; int B::v = 0; void test() { A a; B b; std::cout << "sizeof(A)=" << sizeof(A) << "\n" << "sizeof(a)=" <<

Convert Predicate<T> to Expression<Func<T, bool>>

浪尽此生 提交于 2019-12-04 05:49:04
Is possible to convert a Predicate<T> to Expression<Func<T, bool>> in some way? I would like to use the next IQueryable function using the filters of the my ICollectionView: public static System.Linq.IQueryable<TSource> Where<TSource>(this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<System.Func<TSource, bool>> predicate) Thanks In theory it is possible to convert a delegate 'back' to an expression, because you can request the emitted IL of a delegate, which gives you the information you need to transform it back. However, it's for a reason that neither LINQ to

recursive Prolog predicate?

本小妞迷上赌 提交于 2019-12-04 04:37:16
问题 i am currently working on a project and i want to implement helper predicate in Prolog break_down(N, L) which works as follows ?- break_down(1,L). L = [1] ; false. ?- break_down(4,L). L = [1, 1, 1, 1] ; L = [1, 1, 2] ; L = [1, 3] ; L = [2, 2] ; L = [4] ; false. and so on for any positive integer N . i have tried and implemented a code which generates only the first result and i cannot get the rest of the results , and this is my code break_down(1,[1]). break_down(N,L):- N>0, N1 is N-1, break

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

≯℡__Kan透↙ 提交于 2019-12-04 03:23:02
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("AA", "BB", "A", "B") def c1(s: String) = s.startsWith("B") def c2(s: String) = s.length == 2 println(l1.find(s => c1(s) || c2(s))) println(l2.find(s => c1(s) || c2(s))) result is: Some(B) Some(AA) For the l1 case I would like to have some return value (a String

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

我的梦境 提交于 2019-12-04 02:06:14
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, these are the only functions which need to be implemented in a lower language. The way the non-primitives of lisp can be constructed from primitives is analogous to the way theorems can be proven from axioms in mathematics. The primitives are: atom, quote, eq, car,