Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.39 KB | None | 0 0
  1. object Foo {
  2.   type Trans[T] = T => Option[T]
  3.  
  4.   def foo[T](t: T, ts: List[Trans[T]]): Option[T] = {
  5.     def aux(acc: T, ts: List[Trans[T]], success: Boolean = false): Option[T] = ts match {
  6.       case t :: rest => t(acc) match {
  7.         case Some(v) => aux(v, rest, success = true)
  8.         case None => aux(acc, rest)
  9.       }
  10.       case _ => Option(acc)
  11.     }
  12.     aux(t, ts)
  13.   }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement