NthItem
See javadoc - uk.gov.gchq.koryphe.impl.function.NthItem
Available since Koryphe version 1.1.0
For a given Iterable, an NthItem will extract the item at the Nth index, where n is a user-provided selection. (Consider that this is array-backed, so a selection of "1" will extract the item at index 1, ie the 2nd item)"
Examples
Extract nth item
Java
JSON
Full JSON
Python
final NthItem<Integer> function = new NthItem<>(2);
{
"class" : "NthItem",
"selection" : 2
}
{
"class" : "uk.gov.gchq.koryphe.impl.function.NthItem",
"selection" : 2
}
g.NthItem(
selection=2
)
Input type:
java.lang.Iterable
Example inputs:
Input Type | Input | Result Type | Result |
---|---|---|---|
java.util.ArrayList | [3, 1, 4] | java.lang.Integer | 4 |
java.util.ArrayList | [1, 5, 9] | java.lang.Integer | 9 |
java.util.ArrayList | [2, 6, 5] | java.lang.Integer | 5 |
java.util.ArrayList | [2, null, 5] | java.lang.Integer | 5 |
java.util.ArrayList | [2, 6, null] | null | |
null | IllegalArgumentException: Input cannot be null |