Created
June 2, 2018 10:09
-
-
Save ShahOdin/597e7de69322d960e3ab47d51a1075f1 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
object FSM { | |
sealed trait State | |
object State { | |
sealed trait State1 extends State | |
sealed trait State2 extends State | |
sealed trait State3 extends State | |
} | |
def state1 = new FSM[State.State1] | |
def state2 = new FSM[State.State2] | |
def state3 = new FSM[State.State3] | |
} | |
class FSM[S <: FSM.State] { | |
import FSM.State._ | |
def to2()(implicit ev: S =:= State1) = { | |
println("State1 => State2") | |
new FSM[State2] | |
} | |
def to3()(implicit ev: S =:= State2) = { | |
println("State2 => State3") | |
new FSM[State3] | |
} | |
def to1()(implicit ev: S =:= State3) = { | |
println("State3 => State1") | |
new FSM[State1] | |
} | |
} | |
FSM.state1.to2().to3().to1().to2() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment