Declaring Func dynamically

You can do this by using an open generic type definition, and then making the specific type from that: typeof(Func<,>).MakeGenericType(typeof(int), orderType); However, what you’re trying to do (calling Lambda<TDelegate>) is not directly possible. You must call Lambda without a type parameter: var propertyinfo = typeof(T).GetProperty(sortExpressionStr); Type orderType = propertyinfo.PropertyType; var param = Expression.Parameter(typeof(T), “x”); var … Read more

Combine Multiple Predicates

How about: public static Predicate<T> Or<T>(params Predicate<T>[] predicates) { return delegate (T item) { foreach (Predicate<T> predicate in predicates) { if (predicate(item)) { return true; } } return false; }; } And for completeness: public static Predicate<T> And<T>(params Predicate<T>[] predicates) { return delegate (T item) { foreach (Predicate<T> predicate in predicates) { if (!predicate(item)) { … Read more

Is there a way to modify fetched results with a predicate after they are initialized?

Is there a way to modify fetched results with a predicate after they are initialized? Well… no, not in the way you try to do this, and even if you’d try to create it with NSFetchRequest instance, which is reference, and allows to change predicate later, that wouldn’t work, because SwiftUI’s FetchRequest stores copy of … Read more

How to apply multiple predicates to a java.util.Stream?

If you have a Collection<Predicate<T>> filters you can always create a single predicate out of it using the process called reduction: Predicate<T> pred=filters.stream().reduce(Predicate::and).orElse(x->true); or Predicate<T> pred=filters.stream().reduce(Predicate::or).orElse(x->false); depending on how you want to combine the filters. If the fallback for an empty predicate collection specified in the orElse call fulfills the identity role (which x->true does … Read more

How to make Selenium wait until an element is present?

You need to call ignoring with an exception to ignore while the WebDriver will wait. FluentWait<WebDriver> fluentWait = new FluentWait<>(driver) .withTimeout(30, TimeUnit.SECONDS) .pollingEvery(200, TimeUnit.MILLISECONDS) .ignoring(NoSuchElementException.class); See the documentation of FluentWait for more information. But beware that this condition is already implemented in ExpectedConditions, so you should use: WebElement element = (new WebDriverWait(driver, 10)) .until(ExpectedConditions.elementToBeClickable(By.id(“someid”))); *Fewer … Read more

How to wait until a predicate condition becomes true in JavaScript?

Javascript is single threaded, hence the page blocking behaviour. You can use the deferred/promise approach suggested by others. The most basic way would be to use window.setTimeout. E.g. function checkFlag() { if(flag === false) { window.setTimeout(checkFlag, 100); /* this checks the flag every 100 milliseconds*/ } else { /* do something*/ } } checkFlag(); Here … Read more

Predicate in Java

I’m assuming you’re talking about com.google.common.base.Predicate<T> from Guava. From the API: Determines a true or false value for a given input. For example, a RegexPredicate might implement Predicate<String>, and return true for any string that matches its given regular expression. This is essentially an OOP abstraction for a boolean test. For example, you may have … Read more