EventIterator

A decorator for iterating over domain events with convenient access methods.

This class provides type-safe methods for traversing domain event streams, allowing easy access to event bodies and skipping events during testing.

Example usage:

val eventIterator = EventIterator(domainEventStream.iterator())

// Skip the first event
eventIterator.skip(1)

// Get the next event as a specific type
val orderCreated = eventIterator.nextEventBody<OrderCreated>()

// Get the full event with metadata
val paymentEvent = eventIterator.nextEvent<OrderPaid>()

Parameters

delegate

the underlying iterator to decorate

Constructors

Link copied to clipboard
constructor(delegate: Iterator<DomainEvent<*>>)

Properties

Link copied to clipboard
open override val delegate: Iterator<DomainEvent<*>>

Functions

Link copied to clipboard
open operator override fun hasNext(): Boolean
Link copied to clipboard
open operator override fun next(): DomainEvent<*>
Link copied to clipboard
inline fun <E : Any> nextEvent(): DomainEvent<E>

Retrieves the next event with reified type validation.

fun <E : Any> nextEvent(eventType: Class<E>): DomainEvent<E>

Retrieves the next event and validates its type using Class.

fun <E : Any> nextEvent(eventType: KClass<E>): DomainEvent<E>

Retrieves the next event and validates its type using KClass.

Link copied to clipboard
inline fun <E : Any> nextEventBody(): E

Retrieves the body of the next event with reified type validation.

fun <E : Any> nextEventBody(eventType: Class<E>): E

Retrieves the body of the next event and validates its type using Class.

fun <E : Any> nextEventBody(eventType: KClass<E>): E

Retrieves the body of the next event and validates its type using KClass.

Link copied to clipboard
fun skip(skip: Int): EventIterator

Skips a specified number of events in the iterator.