Skip to content

Instantly share code, notes, and snippets.

@eamelink
Created November 16, 2015 12:05
Show Gist options
  • Save eamelink/df52be4b71c76992bfa2 to your computer and use it in GitHub Desktop.
Save eamelink/df52be4b71c76992bfa2 to your computer and use it in GitHub Desktop.

Revisions

  1. eamelink created this gist Nov 16, 2015.
    11 changes: 11 additions & 0 deletions traverse.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    val myList = List("foo")
    val myFun: (String) => EitherT[Future, Exception, Int] = (in: String) => EitherT { Future { try { \/-(in.toInt) } catch { case NonFatal(e: Exception) => -\/(e) } }}

    // Regular traverse
    Traverse[List].traverse[({type G[A]=EitherT[Future,Exception,A]})#G, String, Int](myList)(myFun)

    // TraverseU to the rescue!
    Traverse[List].traverseU(myList)(myFun)

    // Pimpin' to the rescue!
    myList.traverseU(myFun)