Created
October 12, 2016 11:04
-
-
Save goral09/0f8fa5ecef6aece8dff0d7846cebfc63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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