Skip to content

Instantly share code, notes, and snippets.

@goral09
Created October 12, 2016 11:04
Show Gist options
  • Save goral09/0f8fa5ecef6aece8dff0d7846cebfc63 to your computer and use it in GitHub Desktop.
Save goral09/0f8fa5ecef6aece8dff0d7846cebfc63 to your computer and use it in GitHub Desktop.
sealed abstract class StSource[A] {
type S
def init: S
def emit(s: S): (A, S)
}
object StSource {
type Aux[S0, A] = StSource[A] { type S = S0 }
def apply[A, S0](i: S0)(f: S0 => (A, S0)): Aux[S0, A] =
new StSource[A] {
type S = S0
def init = i
def emit(s: S0): (A, S0) = f(s)
}
}
def runStSource[A](ss: StSource[A])(s: ss.S): (A, ss.S) =
ss.emit(s)
val stSource = StSource(100.0)(i => (i / 10, i))
runStSource(stSource)(stSource.init)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment