View source on GitHub
|
Maps a TFF sequence value pointwise using a given function fn.
tff.sequence_map(
fn, arg
)
This function supports two modes of usage:
When applied to a non-federated sequence, it maps individual elements of the sequence pointwise. If the supplied
fnis of typeT->Uand the sequenceargis of typeT*(a sequence ofT-typed elements), the result is a sequence of typeU*(a sequence ofU-typed elements), with each element of the input sequence individually mapped byfn. In this mode of usage,sequence_mapbehaves like a computatation with type signature<T->U,T*> -> U*.When applied to a federated sequence,
sequence_mapbehaves as if it were individually applied to each member constituent. In this mode of usage, one can think ofsequence_mapas a specialized variant offederated_mapthat is designed to work with sequences and allows one to specify afnthat operates at the level of individual elements. Indeed, under the hood, whensequence_mapis invoked on a federated type, it injectsfederated_map, thus emitting expressions likefederated_map(a -> sequence_map(fn, x), arg).
Args | |
|---|---|
fn
|
A mapping function to apply pointwise to elements of arg.
|
arg
|
A value of a TFF type that is either a sequence, or a federated sequence. |
Returns | |
|---|---|
A sequence with the result of applying fn pointwise to each
element of arg, or if arg was federated, a federated sequence
with the result of invoking sequence_map on member sequences locally
and independently at each location.
|
Raises | |
|---|---|
TypeError
|
If the arguments are not of the appropriate types. |
View source on GitHub