Packages

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. Protected

Instance Constructors

  1. new Defers()

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  6. def defer(body: => Unit): Unit

    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
    Definition Classes
    AnyRef
  8. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  9. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  14. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  15. def processResult(x: Try[T]): T

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

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

    called inside defer blocks, where argument(t)

  17. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  18. def toString(): String
    Definition Classes
    AnyRef → Any
  19. def tryProcess(x: Try[T]): Try[T]
  20. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  21. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  22. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from AnyRef

Inherited from Any

Ungrouped