Discord is now Scala’s main chat platform. Please join us at https://discord.com/invite/scala
State[S, A]
, A
is the output
get: State[Int, Int]
State[Int, Int]
(the first Int
is the state, and stays as it is, the second state is the result, and gets incremented)State[Int, String]
(the state is an Int, the result is now String
)
map
yeah :)
State
you don't really look at it as "transforming the output of a program"
map
? (don't worry about making it infix)
get[Int].map(_ + 1).map(_.toString)
is describing the sequence of transformations (that I described above) over an Int
, that we will pass eventually, in run
State
to allow to be called infix
get[Int].map..
etc
def map[A, B]: State[S, A] => (A => B) => State[S, B]
State[S, B]