GitHub

transferable

API reference for transferable.

Values to move with a worker message rather than copy (Effect's Transferable).

Encoding a message with a Collector in the context gathers the values that schemas made with schema(s, f) report; a platform that moves values passes them as the message's transfer list. The Python platforms copy (processes) or share (threads) every message, so they ignore the list: the module is here for platforms and schemas written against Effect's API.

Values

AttributeTypeDescription
make_collectorEffect[CollectorService]

Classes

Functions

make_collector_unsafe

make_collector_unsafe() -> CollectorService

Returns CollectorService

def make_collector_unsafe() -> CollectorService:
    return CollectorService()

add_all

add_all(values) -> Effect[None]

Add values to the Collector in the context, if there is one.

ParameterTypeDescription
valuesIterable[object]

Returns Effect[None]

def add_all(values: Iterable[object]) -> Effect[None]:
    """Add ``values`` to the ``Collector`` in the context, if there is one."""
    return service_option(Collector).map(
        lambda found: None if found is None else found.value.add_all_unsafe(values)
    )

getter_add_all

getter_add_all[A](f) -> G.Getter[A, A, Any]

A getter passing its value through, adding f(value) to the Collector in the context, if there is one.

ParameterTypeDescription
fCallable[[A], Iterable[object]]

Returns G.Getter[A, A, Any]

def getter_add_all[A](f: Callable[[A], Iterable[object]]) -> G.Getter[A, A, Any]:
    """A getter passing its value through, adding ``f(value)`` to the
    ``Collector`` in the context, if there is one."""

    def collect(value: A, _options: ParseOptions) -> Effect[A, Any, Any]:
        return add_all(f(value)).map(lambda _: value)

    return G.transform_effect(collect)

schema

schema[T_, E, RD, RE](self, f) -> S.DecodeToSchema[T_, E, Any, Any]

self, reporting f of each encoded value to the Collector when encoding. Unlike Effect's, its JSON codec is self's: Python messages are values, not structured clones.

ParameterTypeDescription
selfS.Codec[T_, E, RD, RE]
fCallable[[E], Iterable[object]]

Returns S.DecodeToSchema[T_, E, Any, Any]

def schema[T_, E, RD, RE](
    self: S.Codec[T_, E, RD, RE], f: Callable[[E], Iterable[object]]
) -> S.DecodeToSchema[T_, E, Any, Any]:
    """``self``, reporting ``f`` of each encoded value to the ``Collector``
    when encoding. Unlike Effect's, its JSON codec is ``self``'s: Python
    messages are values, not structured clones."""
    transformation: T.Transformation[E, E, Any, Any] = T.Transformation(
        G.passthrough(), getter_add_all(f)
    )
    return S.encode(transformation)(self)