Discord is now Scala’s main chat platform. Please join us at https://discord.com/invite/scala
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]
State[S, B]
? at this point the only thing we have that type checks, it's the constructor
how do we create a
State[S, B]
? at this point the only thing we have that type checks, it's the constructor
so that's where we got to
S => (S, B)
def map[A, B](fa: State[S, A])(f: A => B) : State[S, B] = State[S, B] { s: S =>
// more work to do here
def result: (S, B) = ???
result
}