Questions tagged [predicate]

A Predicate is a method which represents a set of criteria and decides for a given object if these criteria are fulfilled or not. In computer languages a Predicate is expressed as a function which takes a single object as input parameter and returns a boolean value.

A Predicate is a method which represents a set of criteria and decides for a given object if these criteria are fulfilled or not. In computer languages a Predicate is expressed as a function which takes a single object as input parameter and returns a boolean value.

Example of a Predicate in .NET Framework / C#

In the .NET Framework the most general form of a Predicate is represented by a generic delegate:

public delegate bool Predicate<in T>(T obj)

An often used alternative representation is:

public delegate TResult Func<in T, out TResult>(T arg)

where TResult is of type bool.

An example of a concrete instance of such a delegate is a method which decides for a given Product by a special citerion if it is expensive or not:

public bool IsExpensive(Product product)
{
    return product.UnitPrice > 1000;
}

Predicates are often used for defining criteria to filter a subset of data out of a larger set and are often expressed as anonymous methods or by lambda expressions:

IEnumerable<Product> expensiveProducts =
    allProducts.Where(p => p.UnitPrice > 1000);
1908 questions
0
votes
1 answer

Need a expression to find comma separated string in a List

i am creating a generic method which generates predicate to filter data. this is my contains method Expression.Call(Member, typeof(string).GetMethod("Contains"), constant) like wise i need a expression to find comma separated string in a list of…
summ
  • 1
  • 1
0
votes
0 answers

string compare greater than expression predicate

i am creating a method that generates predicate to filter out items from list. MemberExpression member = Expression.Property(param, filter.ColumnName); ConstantExpression constant = Expression.Constant(filter.Text); for contains …
Sumit Sharma
  • 126
  • 2
  • 11
0
votes
1 answer

cast left side of expression predicate into string

i am having a generic method which return an expression predicate to filter data from list. MemberExpression member = Expression.Property(param, filter.ColumnName); ConstantExpression constant =…
Sumit Sharma
  • 126
  • 2
  • 11
0
votes
1 answer

What is wrong with this predicate in Prolog?

findThree([H|T],_,3). findThree([H|T], M, Z):- ( member(H,M) -> Z2 is Z + 1, select(H,M,C), findThree(T,C,Z2) ;select(H,M,C), findThree(T,C,Z) …
Waffles
  • 1
  • 2
0
votes
2 answers

In Prolog, how can I check for N of elements in list A in list B?

I have these two lists = fruits([banana, apple, mangoes, pears]). foodILike([hamburgers, banana, shakes, fries]). I want to write a prolog predicate that will return true as soon as it sees 1 items in the foodsILike list in the fruits list. How…
Waffles
  • 1
  • 2
0
votes
0 answers

Spring repository filter with specification Blob column, which string array in java

i have BLOB column in Mysql database. In java this column parsed as string array: @Column( name = "categories", nullable = false, length = 2048 ) private String[] categories; This class have spring repository method findAll which…
0
votes
1 answer

How to filter realm contacts by phone number with Predicate?

I have a table view show all contacts use RealmSwift. How to filter realm contacts by phone number with Predicate? class Contact: Object { @objc dynamic var firstName = "" @objc dynamic var lastName = "" var number =…
0
votes
0 answers

Hibernate CriteriaQuery, fetch based on timestamp

I have an entity with two column marked as java.util.Date, but the same columns are provided as timestamp in the table (oracle db). @Column(name = "STD_DATT") private Date stdDatt; @Column(name = "ETA_DATT") private Date etaDatt; I am trying to…
Mujahid
  • 127
  • 1
  • 2
  • 10
0
votes
1 answer

Use isEqualByComparingTo in Predicate

normal use of nice assertj-matchers like isEqualByComparingTo: BigDecimal number = ... assertThat(number).isEqualByComparingTo(BigDecimal.valueOf(...)); however I have a list of BigDecimals and want to check each element in the list for equality by…
hotzen
  • 2,800
  • 1
  • 28
  • 42
0
votes
1 answer

Hazelcast LIKE/ILIKE predicate/query on Integer/Long types

Is there a way to perform ILIKE/LIKE querying on Integer/Long object attributes in Hazelcast's distributed query? For eg: In postgres, we can query like, select * from document where CAST(numOfPages AS TEXT) ilike '%2'; to get the documents with…
syed
  • 189
  • 3
  • 13
0
votes
0 answers

C# Solr query, Boost is not working

I'm using C# to query Solr for my site search. The code is fine in regard to filtering and searching for keywords in specific fields, but I can't get Boost to work. I need to use boosting so that items where the keyword is in the Title field are…
Erica Stockwell-Alpert
  • 4,624
  • 10
  • 63
  • 130
0
votes
1 answer

prolog match items from list to predicates

I'm new to prolog and trying to solve my made up following prolog's problem. I have some people person(john, 36). person(jane, 3). person(amber, 32). person(emmy, 2). person(clement, 37). person(patrick, 15). person(emilie, 20). I have a list of…
Wizz
  • 43
  • 6
0
votes
0 answers

Predicate being ignored in core data fetch request

Can anyone tell me why the questionFetch predicate below is being ignored and the questionResults.count being returned is the number of rows in the entire data set? There are only 2 rows in the data set with a questionType equal to 0, which should…
tjdev
  • 1
  • 1
  • 2
0
votes
1 answer

Factorise Common filter in linq to entities

I'm trying to factorise some code. i've got lots of list of custom object. All are filtered on thier own specific fields and on one of their date. the filter date is complex and i would like to factorise it. Here is some code exemple : var…
rdethurens
  • 283
  • 1
  • 4
  • 13
0
votes
2 answers

and two predicate functions in c++

I am looking for a way to create a binary operation between two predicate functions. This is my predicate function declaration: template using Predicate = std::function; I am looking for a way to 'concat' two predicate…
t4dohx
  • 675
  • 4
  • 24