ForEach
See javadoc - uk.gov.gchq.gaffer.operation.impl.ForEach
Available since Gaffer version 1.7.0
Runs supplied operation on Iterable of inputs
Required fields
No required fields
Examples
For each in chain example
Using this directed graph:
--> 4 <--
/ ^ \
/ | \
1 --> 2 --> 3
\
--> 5
Java
JSON
Full JSON
Python
final OperationChain<Iterable<?>> opChain = new OperationChain.Builder()
.first(new GetAdjacentIds.Builder()
.input(new EntitySeed(1))
.build())
.then(new ForEach.Builder<>()
.operation(new OperationChain.Builder()
.first(new ToSingletonList<EntitySeed>())
.then(new GetAdjacentIds())
.then(new ToVertices())
.build())
.build())
.build();
{
"class" : "OperationChain",
"operations" : [ {
"class" : "GetAdjacentIds",
"input" : [ {
"class" : "EntitySeed",
"vertex" : 1
} ]
}, {
"class" : "ForEach",
"operation" : {
"class" : "OperationChain",
"operations" : [ {
"class" : "ToSingletonList"
}, {
"class" : "GetAdjacentIds"
}, {
"class" : "ToVertices"
} ]
}
} ]
}
{
"class" : "uk.gov.gchq.gaffer.operation.OperationChain",
"operations" : [ {
"class" : "uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds",
"input" : [ {
"class" : "uk.gov.gchq.gaffer.operation.data.EntitySeed",
"vertex" : 1
} ]
}, {
"class" : "uk.gov.gchq.gaffer.operation.impl.ForEach",
"operation" : {
"class" : "uk.gov.gchq.gaffer.operation.OperationChain",
"operations" : [ {
"class" : "uk.gov.gchq.gaffer.operation.impl.output.ToSingletonList"
}, {
"class" : "uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds"
}, {
"class" : "uk.gov.gchq.gaffer.operation.impl.output.ToVertices"
} ]
}
} ]
}
g.OperationChain(
operations=[
g.GetAdjacentIds(
input=[
g.EntitySeed(
vertex=1
)
]
),
g.ForEach(
operation=g.OperationChain(
operations=[
g.ToSingletonList(),
g.GetAdjacentIds(),
g.ToVertices()
]
)
)
]
)
Result:
Java
JSON
[ 4 --> 3 --> 1 --> 5 ]
[ 3 --> 1 --> 2 ]
[ [ 4, 3, 1, 5 ], [ 3, 1, 2 ] ]