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#
| Attribute | Type | Description |
|---|---|---|
make_collector | Effect[CollectorService] |
Classes#
Functions#
make_collector_unsafe#
make_collector_unsafe() -> CollectorServiceReturns 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.
| Parameter | Type | Description |
|---|---|---|
values | Iterable[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.
| Parameter | Type | Description |
|---|---|---|
f | Callable[[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.
| Parameter | Type | Description |
|---|---|---|
self | S.Codec[T_, E, RD, RE] | |
f | Callable[[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)