FirstValid

See javadoc - uk.gov.gchq.koryphe.impl.function.FirstValid

Available since Koryphe version 1.9.0

Provides the first valid item from an iterable based on a predicate.

Examples

With a predicate

Java
JSON
Full JSON
Python
final FirstValid function = new FirstValid(new StringContains("my"));
{
  "class" : "FirstValid",
  "predicate" : {
    "class" : "StringContains",
    "value" : "my",
    "ignoreCase" : false
  }
}
{
  "class" : "uk.gov.gchq.koryphe.impl.function.FirstValid",
  "predicate" : {
    "class" : "uk.gov.gchq.koryphe.impl.predicate.StringContains",
    "value" : "my",
    "ignoreCase" : false
  }
}
g.FirstValid( 
  predicate=g.StringContains( 
    value="my", 
    ignore_case=False 
  ) 
)

Input type:

java.lang.Iterable

Example inputs:

Input TypeInputResult TypeResult
java.util.ArrayList[1, 2, 3]ClassCastException: java.lang.Integer cannot be cast to java.lang.String
java.util.ArrayList[Hello, my, value]java.lang.Stringmy
java.util.ArrayList[MY, tummy, my, My]java.lang.Stringtummy
nullnull

With no predicate

FirstValid always returns null if no predicate is specified

Java
JSON
Full JSON
Python
final FirstValid function = new FirstValid(null);
{
  "class" : "FirstValid"
}
{
  "class" : "uk.gov.gchq.koryphe.impl.function.FirstValid"
}
g.FirstValid()

Input type:

java.lang.Iterable

Example inputs:

Input TypeInputResult TypeResult
java.util.ArrayList[a, b, c]null
java.util.ArrayList[1, 2, 3]null
java.util.ArrayList[]null

results matching ""

    No results matching ""