cats state monad
-
Statescala/cats2 2023. 1. 10. 09:49
문제 https://wefree.tistory.com/44 의 문제를 cats State Monad 를 이용해 구현해 본다. 코드 import cats._ import cats.data._ import cats.syntax.all._ object GolfState { def swing(n: Int): State[Int, Int] = State(s => (s+n, s+n)) def main(args: Array[String]): Unit = { val states: Seq[State[Int, Int]] = List(swing(20), swing(10), swing(15)) val finalState: State[Int, Int] = states.reduce(_ *> _) val (s,a) = finalSt..