Skip to content

Instantly share code, notes, and snippets.

@kell18
Created November 1, 2018 16:13
Show Gist options
  • Save kell18/05261e56504da16d5db8384a4ad65733 to your computer and use it in GitHub Desktop.
Save kell18/05261e56504da16d5db8384a4ad65733 to your computer and use it in GitHub Desktop.
case class FunctionNPhase[Event, States <: HList, Phases <: HList](
function: Seq[Double] => Double,
functionName: String,
innerPhases: Phases
)(implicit ev: Mapped.Aux[States, ({ type T[State] = NumericPhaseParser[Event, State] })#T, Phases])
extends Pattern[Event, States, Double] {
private val initialStateGetter = new (({ type U[State] = NumericPhaseParser[Event, State] })#U ~> Id) {
override def apply[T](f: NumericPhaseParser[Event, T]): Id[T] = f.initialState
}
override def initialState: States = innerPhases.map(initialStateGetter)
override def apply(event: Event, state: States): (PatternResult[Double], States) = ???
{
val allPhasesTogether =
innerPhases.foldLeft((f: NumericPhaseParser[Event, _], g: NumericPhaseParser[Event, _]) => f togetherWith g)
val (results, newState) = allPhasesTogether(event, state)
// FIXME@trolley813: it's pseudocode, won't work
results.map { case x => function(x.toSeq) } -> newState
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment