GitHub

EventGroup

API reference for EventGroup.

class EventGroup[Ev: AnyEvent = Never]

An immutable group of the events Ev, by tag.

Attributes

AttributeTypeDescription
emptyEventGroup[Never]

The group without events (Effect's EventGroup.empty).

eventsMapping[str, AnyEvent]

Functions

__init__

__init__(events) -> None
ParameterTypeDescription
eventsMapping[str, AnyEvent]
def __init__(self, events: Mapping[str, AnyEvent]) -> None:
    self._events = MappingProxyType(dict(events))

add

add[P, A, E](event) -> EventGroup[Ev | Event[P, A, E]]

This group and event (an event of the same tag is replaced).

ParameterTypeDescription
eventEvent[P, A, E]

Returns EventGroup[Ev | Event[P, A, E]]

def add[P, A, E](self, event: Event[P, A, E], /) -> EventGroup[Ev | Event[P, A, E]]:
    """This group and ``event`` (an event of the same tag is replaced)."""
    return EventGroup({**self._events, event.tag: event})

add_error

add_error(error) -> EventGroup[AnyEvent]

Every event of the group may also fail with error (Effect's addError). The result's events are typed loosely: give each event its error with event.add_error to keep their types.

ParameterTypeDescription
errorS.Codec[Any, Any, Any, Any]

Returns EventGroup[AnyEvent]

def add_error(self, error: S.Codec[Any, Any, Any, Any], /) -> EventGroup[AnyEvent]:
    """Every event of the group may also fail with ``error`` (Effect's
    ``addError``). The result's events are typed loosely: give each
    event its error with ``event.add_error`` to keep their types."""
    return EventGroup({tag: add_error(event, error) for tag, event in self._events.items()})