Skip to content

Instantly share code, notes, and snippets.

@takayahilton
Created November 9, 2020 07:14
Show Gist options
  • Save takayahilton/eded271c2bb1dd57ca7d4bf8d497dead to your computer and use it in GitHub Desktop.
Save takayahilton/eded271c2bb1dd57ca7d4bf8d497dead to your computer and use it in GitHub Desktop.
import cats.implicits._
import cats.data._
List("a", "b", "b", "c", "b").traverse(s => State((map: Map[String, Int]) => map.get(s) match {
case Some(i) => (map.updated(s, i + 1), s + s"${i + 1}")
case None => (map.updated(s, 0), s)
})).run(Map.empty).value._2 //List("a", "b", "b1", "c", "b2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment