Basic Scalaz State question

青春壹個敷衍的年華 提交于 2019-11-30 08:46:42
def index[M[_]:Traverse, A](m: M[A]) =
  m.traverse[({type λ[x] = State[Int,x]})#λ, (A, Int)](a =>
    state(i => (i + 1, (a, i)))) ! 0

Or even...

def index[M[_]:Traverse, A](m: M[A]) =
  m.traverse[({type λ[x] = State[Int,x]})#λ, (A, Int)](a =>
    (Lens.self[Int] += 1) map ((a, _)) ! -1

See The Essence of the Iterator Pattern for more on traversing with State.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!