IterableFunction

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

Available since Koryphe version 1.1.0

An IterableFunction is useful for applying a provided function, or functions, to each entry of a supplied Iterable.

Examples

Apply function iteratively

Java
JSON
Full JSON
Python
final IterableFunction<Integer, Integer> function = new IterableFunction<>(new MultiplyBy(2));
{
  "class" : "IterableFunction",
  "functions" : [ {
    "class" : "MultiplyBy",
    "by" : 2
  } ]
}
{
  "class" : "uk.gov.gchq.koryphe.impl.function.IterableFunction",
  "functions" : [ {
    "class" : "uk.gov.gchq.koryphe.impl.function.MultiplyBy",
    "by" : 2
  } ]
}
g.IterableFunction( 
  functions=[ 
    g.MultiplyBy( 
      by=2 
    ) 
  ] 
)

Input type:

java.lang.Object

Example inputs:

Input TypeInputResult TypeResult
java.util.ArrayList[1, 2, 3]uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable[2, 4, 6]
java.util.ArrayList[5, 10, 15]uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable[10, 20, 30]
java.util.ArrayList[7, 9, 11]uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable[14, 18, 22]
java.util.ArrayList[1, null, 3]uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable[2, null, 6]
nullnull

Apply multiple functions

Here we build a chain of functions using the IterableFunction's Builder, whereby the output of one function is the input to the next.

Java
JSON
Full JSON
Python
final IterableFunction<Integer, Integer> function = new IterableFunction.Builder<Integer>()
        .first(new MultiplyBy(2))
        .then(new MultiplyBy(4))
        .build();
{
  "class" : "IterableFunction",
  "functions" : [ {
    "class" : "MultiplyBy",
    "by" : 2
  }, {
    "class" : "MultiplyBy",
    "by" : 4
  } ]
}
{
  "class" : "uk.gov.gchq.koryphe.impl.function.IterableFunction",
  "functions" : [ {
    "class" : "uk.gov.gchq.koryphe.impl.function.MultiplyBy",
    "by" : 2
  }, {
    "class" : "uk.gov.gchq.koryphe.impl.function.MultiplyBy",
    "by" : 4
  } ]
}
g.IterableFunction( 
  functions=[ 
    g.MultiplyBy( 
      by=2 
    ), 
    g.MultiplyBy( 
      by=4 
    ) 
  ] 
)

Input type:

java.lang.Object

Example inputs:

Input TypeInputResult TypeResult
java.util.ArrayList[2, 4, 10]uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable[16, 32, 80]
java.util.ArrayList[3, 9, 11]uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable[24, 72, 88]
java.util.ArrayList[1, null, 3]uk.gov.gchq.koryphe.util.IterableUtil$MappedIterable[8, null, 24]
nullnull

results matching ""

    No results matching ""