Documentation
¶
Index ¶
- Variables
- func Execute[E any, S Subjecter[E]](init_fn func() S) iter.Seq[S]
- type History
- func (h *History[E]) AddEvent(event E)
- func (h *History[E]) AdvanceOne(subject Subjecter[E]) (bool, error)
- func (h *History[E]) Align(subject Subjecter[E]) error
- func (h History[E]) Copy() *History[E]
- func (h *History[E]) Event() iter.Seq[E]
- func (h *History[E]) IsNil() bool
- func (h *History[E]) Restart()
- type Pair
- type Subjecter
Constants ¶
This section is empty.
Variables ¶
var ( // SubjectHasError is returned when the subject has an error. SubjectHasError error // SubjectIsDone is returned when the subject is done. SubjectIsDone error // HistoryEnded is returned when the history has ended. HistoryEnded error )
Functions ¶
func Execute ¶
Execute returns a sequence of subjects that can be reached by applying events from the history to the subjects, where the history is updated by adding events to the history, and the subjects are updated by applying events to the subjects.
The function takes a function that returns a subject as an argument. This function is called once for each subject in the sequence.
The sequence is infinite, and will continue to generate subjects until the subject is done due to exhaustion of the history, or until the subject is done due to an error.
The function will panic if an error occurs while executing the sequence.
Types ¶
type History ¶
type History[E any] struct { // contains filtered or unexported fields }
History is a stack of events that can be replayed.
func NewHistory ¶
NewHistory creates a new history.
Returns:
- *History: The new history. Never returns nil.
func (*History[E]) AddEvent ¶
func (h *History[E]) AddEvent(event E)
AddEvent adds an event to the history.
Parameters:
- event: The event to add to the history.
func (*History[E]) AdvanceOne ¶
AdvanceOne advances the history by one event and applies the event to the subject.
Parameters:
- history: The history to advance.
- subject: The subject to apply the event to.
Returns:
- bool: True if the subject is done, false otherwise.
- error: If the subject is nil, or if an error occurs while applying the event.
Errors:
- SubjectHasError: If the subject is done due to an error.
- SubjectIsDone: If the subject is done due to internal success.
- HistoryEnded: If the history has ended.
func (*History[E]) Align ¶
Align applies events from the history to the subject until the subject is at the end of the history.
Parameters:
- history: The history to apply events from. Assumed not nil.
- subject: The subject to apply events to. Assumed not nil.
Returns:
- error: If the subject is nil, or if an error occurs while applying events.
Errors:
- SubjectHasError: If the subject is done due to an error.
- SubjectIsDone: If the subject is done due to internal success.
func (History[E]) Copy ¶
Copy creates a copy of the history.
Returns:
- *History: The copy of the history. Never returns nil.
func (*History[E]) Event ¶
Event returns a sequence of events in the history that have not been applied to the subject yet.
Returns:
- iter.Seq[E]: The sequence of events.
type Pair ¶
type Pair[E any] struct { // contains filtered or unexported fields }
Pair is a pair of a subject and a history.
func NewPair ¶
NewPair creates a new pair from the given history and subject.
If the given history is nil, a new one is created.
Parameters:
- history: The history for the pair. If nil, a new one is created.
- subject: The subject for the pair. Must not be nil.
Returns:
- *Pair[E]: The new pair.
- error: If the subject is nil.
type Subjecter ¶
type Subjecter[E any] interface { // IsNil checks if the subject is nil. // // Returns: // - bool: True if the subject is nil, false otherwise. IsNil() bool // HasError checks if the subject has an error. // // Returns: // - bool: True if the subject has an error, false otherwise. HasError() bool // ApplyEvent applies an event to the subject. // // Parameters: // - event: The event to apply. Assumed not nil. // // Returns: // - bool: True if the subject is done, false otherwise. ApplyEvent(event E) bool // NextEvents returns the next events in the subject. // // Returns: // - []E: The next events in the subject. NextEvents() []E }
Subjecter is an interface for a subject.