package com.correx.core.sessions.projections

import com.correx.core.events.events.StoredEvent

class DefaultStateBuilder<S>(
    private val projection: Projection<S>
) : StateBuilder<S> {

    override fun build(events: List<StoredEvent>): S {
        return events.fold(projection.initial()) { state, event ->
            projection.apply(state, event)
        }
    }
}
