I've tried to simplify a real code but not to much.
Given the following input, implementation of f and g are just for examples, real one are more complicated
scala> val m = Map("a" -> 1, "b" -> 2, "c" -> 3, "d" -> 4)
m: scala.collection.immutable.Map[String,Int] = Map(a -> 1, b -> 2, c -> 3, d -> 4)
scala> val f : Int => Option[Int] = i => if (i % 2 == 0) Some(i) else None
f: Int => Option[Int] = <function1>
scala> val g = (a:Int, l:List[Int]) => a :: l
g: (Int, List[Int]) => List[Int] = <function2>
Here is the process :
m.foldLeft(List[Int]()) { case (l, (k, v)) =>
f(v) match {
case Some(w) => g(w, l)
case None => l
}
}
Is it possible to use scalaz to better reveal the intent ?
I'm thinkink about m.traverseS