Questions tagged [predicates]

Predicates are functions that return the boolean values, `True` or `False`.

In computing, Predicates are functions that return the boolean values, True or False. Some languages and frameworks treat them specially.

See also Wikipedia.

There are alternate (and possibly more mainstream) meanings. See Wikipedia.

108 questions
20
votes
3 answers

XPath query with descendant and descendant text() predicates

I would like to construct an XPath query that will return a "div" or "table" element, so long as it has a descendant containing the text "abc". The one caveat is that it can not have any div or table descendants.
juan234
  • 203
  • 1
  • 2
  • 4
14
votes
2 answers

Pass parameters to Predicates

I have the following map of the search criteria: private final Map searchMap = new HashMap<>(); private void initSearchMap() { Predicate allDrivers = p -> p.getAge() >= 16; Predicate allDraftees = p ->…
mr.M
  • 851
  • 6
  • 23
  • 41
12
votes
1 answer

Creating String representation of lambda expression

For debugging purposes I am trying to create string representations of lambda expressions (specifically of Predicates, though it would be interesting for other lambda expressions too) in Java 8. My idea would be something like this: public class…
blalasaadri
  • 5,990
  • 5
  • 38
  • 58
12
votes
7 answers

Predicate Searching in Java

Not quite sure how to word this question. I am wondering if there is a method to check certain parts of a custom java class to see if it matches a certain criteria. Such as this public Name(String forename, String middlename, String surname) And…
pie154
  • 603
  • 3
  • 10
  • 28
10
votes
3 answers

How to debug Predicates in C#/Visual Studio?

In debugging mode, if I hover over a predicate, what I see is just some type names and some non-understandable symbols. This makes it very difficult to debug a code, for example to know what predicate some variable is holding. I usually assign this…
Louis Rhys
  • 34,517
  • 56
  • 153
  • 221
9
votes
1 answer

Haskell/GHC: How to write predicates on type-level naturals

I could have sworn I saw an article on this recently, but I can't find it. I'm trying to make a type to do binary encoding of the numbers mod n, but to do so, I need to be able to write predicates on the type level naturals: {-# LANGUAGE…
rampion
  • 87,131
  • 49
  • 199
  • 315
9
votes
3 answers

C# method accepting a predicate - does this look ok?

I'd like a method that has the following API: //get all users with a role of admin var users = myRepository.GetUsers(u => u.Role == Role.Admin); Will something like this work? IList GetUsers(Func predicate) { var…
Ben Aston
  • 53,718
  • 65
  • 205
  • 331
8
votes
4 answers

Where to find basic Predicates like greaterThan for Guava?

I am using the guava library and have noticed that a very useful Predicate is not defined - "greater than". Is there another place I should be looking for basic predicates like this, or am I doomed to create my own functional support jar that…
Peter Recore
  • 14,037
  • 4
  • 42
  • 62
7
votes
1 answer

Creating Dynamic Predicates- passing in property to a function as parameter

I am trying to create dynamic predicate so that it can be used against a list for filtering public class Feature { public string Color{get;set;} public string Weight{get;set;} } I want to be able to create a dynamic predicate so that a…
venkod
  • 73
  • 1
  • 4
6
votes
3 answers

Turning remove_if into remove_not_if

How can I reverse a predicate's return value, and remove the elements that return false instead of true? Here is my code: headerList.remove_if(FindName(name)); (please ignore lack of erase) with FindName a simple functor: struct FindName { …
DanDan
  • 10,462
  • 8
  • 53
  • 69
6
votes
2 answers

Java8, Is there a filtering collector?

I want to group a collection but I don't want the aggregations to include some values. What's the best solution to do that? A solution could be a collector filtering(Predicate,Collector) but there is no such collector. Is there any way to do it…
Marcin Król
  • 1,555
  • 2
  • 16
  • 31
5
votes
3 answers

Select a node based on value of another node using an xsl predicate

Similar problem to this question: XPath: select a node based on another node? The object is to select a node based on the value of a sibling node-in this case the Pagetitle node based on the value of the Pagetype…
matt
  • 2,690
  • 2
  • 16
  • 17
5
votes
2 answers

NSArray filtering: in which case using predicates and which case using blocks?

Performance wise, on a relatively large array (so far the usual count for the original array is ±20000), which method is best suited to filter it? Blocks or predicates? Most of the ivars of the contained objects are strings and I want to query…
jibay
  • 105
  • 6
4
votes
3 answers

JAVA 8 Extract predicates as fields or methods?

What is the cleaner way of extracting predicates which will have multiple uses. Methods or Class fields? The two examples: 1.Class Field void someMethod() { IntStream.range(1, 100) .filter(isOverFifty) …
ZeDonDino
  • 5,072
  • 8
  • 27
  • 28
4
votes
1 answer

Is it possible to pass Take(), Skip(), OrderBy() etc. as predicates to a function?

Is this possible in an easy way or should I just add skip/take as parameters? public IEnumerable GetKittens(Expression> predicate = null) where T : KittenViewModel, new() { var kittenModels = GetModels(); //…
NibblyPig
  • 51,118
  • 72
  • 200
  • 356
1
2 3 4 5 6 7 8