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
0 answers

How can Predicate be a Functional Interface if it has more than one abstract method?

How can Predicate be considered and used as a functional interface when it has several abstract methods? For example: As well as test(T t); it has: and(Predicate other), negate() and isEqual(Object targetRef ). This question is not a…
IqbalHamid
  • 2,324
  • 1
  • 18
  • 24
0
votes
0 answers

iOS Coredata query issue using predicate

I have two database table, DeviceCatalogue and SkuDetails. DeviceCatalogue has a one to many relationship with SkuDetails, since skudetails is an array. The issue is coming when i'm filtering skudetails based on prices. for querying the database…
0
votes
5 answers

Creating an empty List based on Generics

So I am currenty trying to implement a method which does some filtering on lists regardless of their actual type. Here is the actual method: public static > T filterList(T list, Predicate predicate) { T newList =…
0
votes
1 answer

Lambda exercise

I'm doing some Java OCA test simulations. I don't understand the answer for this exercise: interface Climb { boolean isTooHigh(int height, int limit); } public class Lambdas { public static void main(String[] args) { check((h,l) ->…
Sam
  • 536
  • 5
  • 23
0
votes
2 answers

Java 6 guava Predicate to Java 8 Predicate & Lambda

I have been developing in Java 6 and using guava predicates. But I want to switch to Java 8 and use java util predicates instead. I can simply convert the below method to use the predicate but is there a smart way to use Lambda expressions and…
PK0513
  • 57
  • 10
0
votes
1 answer

Swift: Using Extensions in NSPredicate

Could I do the following Predicate in Swift 4 to the following string 'name': let predicate = NSPredicate(format: "name.dropLast() = %@", searchText) Basically, could I add the extension 'dropLast()' inside the predicate? If not, what is an…
kiwidude89
  • 63
  • 1
  • 7
0
votes
0 answers

Breeze OData function on related Entity

How can I apply an OData function on a related property of a breeze entity query? For example, I have two entities EntityA and EntityB public class EnityA{ public ICollection Collection {get; set;} } public class EnityB{ public…
jpo
  • 3,959
  • 20
  • 59
  • 102
0
votes
2 answers

How to filter a dictionary of arrays

I have a dictionary of arrays which I want to filter based on an element in the arrays. My dictionary looks like this... "Abu Dhabi, U.A.E." = ( "24.466665", "54.416668", "Asia/Dubai" ); "Accra, Ghana" = ( "5.583333", …
user278859
  • 10,379
  • 12
  • 51
  • 74
0
votes
1 answer

Swift - Grouping and Ordering List Items

Fellow developers. I have a Store in which I need to print each customer purchases list grouped by item's category. Please consider the following code for the purpose of grouping and ordering: protocol GroceryItem{ func cost () -> Float func…
0
votes
1 answer

Scala filter on all elements of an alias Set

Here is the question. I have this type Set: type Set = Int => Boolean Which i can use like this: val belowNegFive: Set = (i) => i < -5 belowNegFive(10) I mean to return a bool depending if the elem 10 pertains to the set of numbers below -5. I…
kaileena
  • 121
  • 9
0
votes
6 answers

predicate for a map from string to int

I have this small program that reads a line of input & prints the words in it, with their respective number of occurrences. I want to sort the elements in the map that stores these values according to their occurrences. I mean, the words that only…
Ramila
  • 135
  • 2
  • 7
  • 18
0
votes
1 answer

Prolog XPCE display predicate

Hi I have program ("expert program") in which user choose few button options and this program search in predicates cars with this checked options. After this I wish to display this one or more predicates in window. This is few line of program.…
didi
  • 21
  • 3
0
votes
1 answer

get all matching non null elements if all the conditions are given in predicate

How to get all elements with id = 2? The below code is giving only the last one i.e. channelMetadataDetail3: import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; public class APICheck { public static void…
sjain
  • 23,126
  • 28
  • 107
  • 185
0
votes
1 answer

How to filter columns of a matrix whose IQR is below a specific value?

filter <- apply(expressionMatrix, 2, function (x) (colIQRs(x, na.rm = TRUE) < 1.6)) "Argument x is of class numeric, should be a matrix" error was thrown. How to cope with that? I think logically this code is correct: I remove all columns, whose IQR…
mercury0114
  • 1,341
  • 2
  • 15
  • 29
0
votes
1 answer

How to mock CriteriaQuery.where() followed by order by

I have the class where CriteriaQuery cq=criteriaQuery.root(); ..... ..... cq.where(predictes.toArray(new Predicate[0])).orderBy(criteriaBuilder.asc(root.get(ENTITY.COLUMNNAME)) I need to mock this line , unable to pass this line. I…
1 2 3
99
100