Is there some function with signature like
lensMapState[S, T, A](lens : Lens[S, T]): State[T, A] => State[S, A]
With semantics run modification of chosen part and get result
One implementation could be
def lensMapState[S, T, A](lens: Lens[S, T]): State[T, A] => State[S, A] =
stateT => State { s =>
val (result, x) = stateT.run(lens.get(s))
(lens.set(result)(s), x)
}
but if there more straightforward way using monocle or scalaz.Lens ?
I think what you are looking for is something like this:
which results in
There are many lens/state related functions defined in https://github.com/scalaz/scalaz/blob/series/7.1.x/core/src/main/scala/scalaz/Lens.scala Monocle follows a similiar principle. The related functions are defined in monocle.state as far as I know.