Class/Object

gopher

Defers

Related Docs: object Defers | package gopher

Permalink

class Defers[T] extends AnyRef

Construction Defers: defer/recover is alternative mechanism to exception handling, simular to one in Go language.

We use one hidden in go and goScope construct are transformed to withDefers usage with help of macroses.

It is also possible to use one unsugared (as in next example), but this is a bit verbose.

def parseCsv(fname: String): Either[String, Seq[Seq[Double]]] =
 withDefer[Either[String,Seq[Seq[Double]]]]{ d =>
   val in = Source.fromFile(fname)
   d.defer{
      var r = d.recover{
                case FileNotFoundException => Left("fileNotFound")
              }
      if (!r) in.close()
      d.recover {
        case ex: Throwable => Left(ex.getMessage)
      }
   }
   val retval:Either[String,Seq[Seq[Double]]] = Right{
       for( (line, nLine) <- in.getLines.toSeq zip Stream.from(1) ) yield withDefer[Seq[Double]] { d =>
          line.split(",") map { s=>
                                d.defer{
                                 d.recover{
                                    case ex: NumberFormatException =>
                                      throw new RuntimeException(s"parse error in line ${nLine} file ${fname} ")
                                 }
                                }
                                s.toDouble
                              }
       }.toSeq
     }
   retval
}

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Defers
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Defers()

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. def defer(body: ⇒ Unit): Unit

    Permalink

    can be used in main block (which can be plain or async) and store body for defered execution after evaluation of main block

  7. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  9. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  11. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  12. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. def processResult(x: Try[T]): T

    Permalink

    called after execution of main block, where all 'defered' blocks will be executed in one thread in LIFO order.

  17. def recover(f: PartialFunction[Throwable, T]): Boolean

    Permalink

    called inside defer blocks, where argument(t)

  18. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  19. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  20. def tryProcess(x: Try[T]): Try[T]

    Permalink
  21. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped