Package

com.thoughtworks.dsl

keywords

Permalink

package keywords

Contains built-in domain-specific Keywords and their corresponding interpreters.

Source
package.scala
Linear Supertypes
Content Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. keywords
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. trait AsynchronousIo[Value] extends Keyword[AsynchronousIo[Value], Value]

    Permalink
  2. final case class Await[Value](future: Future[Value]) extends AnyVal with Keyword[Await[Value], Value] with Product with Serializable

    Permalink
  3. sealed class Break extends Keyword[Break, Nothing]

    Permalink
  4. final case class Catch[Domain, Value](block: !![Domain, Value], catcher: Catcher[!![Domain, Value]]) extends Keyword[Catch[Domain, Value], Value] with Product with Serializable

    Permalink

    Author:

    杨博 (Yang Bo)

  5. final case class Each[Element](elements: Traversable[Element]) extends Keyword[Each[Element], Element] with Product with Serializable

    Permalink

    Author:

    杨博 (Yang Bo)

  6. final case class Fork[Element](elements: Traversable[Element]) extends AnyVal with Keyword[Fork[Element], Element] with Product with Serializable

    Permalink
  7. final case class Get[A]() extends Keyword[Get[A], A] with Product with Serializable

    Permalink

    Author:

    杨博 (Yang Bo)

    See also

    Put

  8. final case class Monadic[F[*], A](fa: F[A]) extends Keyword[Monadic[F, A], A] with Product with Serializable

    Permalink

    A keyword for creating monadic control flow.

    A keyword for creating monadic control flow.

    To do

    Monadic should be a scala.AnyVal after https://github.com/scala/bug/issues/10595 is resolved.

    See also

    com.thoughtworks.dsl.domains.scalaz for using this Monadic keyword with scalaz.Monad.

    com.thoughtworks.dsl.domains.cats for using this Monadic keyword with cats.Monad.

  9. final case class Put[A](value: A) extends AnyVal with Keyword[Put[A], Unit] with Product with Serializable

    Permalink

    A Keyword to put the value to the context.

    A Keyword to put the value to the context.

    Purely functional programming languages usually do not support native first-class mutable variables. In those languages, mutable states can be implemented in state monads.

    Put and Get are the Dsl-based replacements of state monads.

    Author:

    杨博 (Yang Bo)

    Examples:
    1. Put and Get support multiple states. The following code creates a formatter that Put parts of content into a List[Any] of string buffers.

      def format: Double => Int => List[Any] => String = {
        !Put("x=" :: !Get[List[Any]])
        !Put(!Get[Double] :: !Get[List[Any]])
        !Put(",y=" :: !Get[List[Any]])
        !Put(!Get[Int] :: !Get[List[Any]])
        !Return((!Get[List[Any]]).reverse.mkString)
      }
      format(0.5)(42)(Nil) should be("x=0.5,y=42")
    2. ,
    3. The behavior of the above code is equivalent to the following code based on native Scala var:

      def varBasedState(initialValue: String): Int = {
        var v = initialValue
        v should be("initial value")
        v = "changed value"
        v should be("changed value")
        return 0
      }
      varBasedState("initial value") should be(0)
    4. ,
    5. The parameter of a scala.Function1 can be read from Get keyword, and changed by Put keyword.

      def dslBasedState: String => Int = {
        !Get[String]() should be("initial value")
        !Put("changed value")
        !Get[String]() should be("changed value")
        !Return(0)
      }
      dslBasedState("initial value") should be(0)

      The implementation of Get and Put keywords does not use native Scala var, though its behavior is similar to var.

    See also

    Get

  10. final case class Return[ReturnValue](returnValue: ReturnValue) extends AnyVal with Keyword[Return[ReturnValue], Nothing] with Product with Serializable

    Permalink

    A Keyword to early return a lifted value from the enclosing function.

    A Keyword to early return a lifted value from the enclosing function.

    Author:

    杨博 (Yang Bo)

    Examples:
    1. Since this Return keyword can automatically lift the return type, TailCalls.done can be omitted.

      import scala.util.Random
      import scala.util.control.TailCalls
      import scala.util.control.TailCalls.TailRec
      def randomInt(): TailRec[Int] = {
        while (true) {
          val r = Random.nextInt(100)
          if (r % 10 != r / 10) {
            !Return(r)
          }
        }
        throw new AssertionError("Unreachable code");
      }
      val r = randomInt().result
      r should be < 100
      r % 10 should not be r / 10
    2. ,
    3. Suppose you are generating a random integer less than 100, whose first digit and second digit is different. A solution is generating integers in an infinite loop, and Return from the loop when the generated integer conforms with requirements.

      import scala.util.Random
      import scala.util.control.TailCalls
      import scala.util.control.TailCalls.TailRec
      def randomInt(): TailRec[Int] = {
        while (true) {
          val r = Random.nextInt(100)
          if (r % 10 != r / 10) {
            !Return(TailCalls.done(r))
          }
        }
        throw new AssertionError("Unreachable code");
      }
      val r = randomInt().result
      r should be < 100
      r % 10 should not be r / 10
  11. final case class Shift[Domain, Value](continuation: !![Domain, Value]) extends AnyVal with Keyword[Shift[Domain, Value], Value] with Product with Serializable

    Permalink

    Author:

    杨博 (Yang Bo)

  12. final case class Using[R <: AutoCloseable](open: () ⇒ R) extends AnyVal with Keyword[Using[R], R] with Product with Serializable

    Permalink

    Author:

    杨博 (Yang Bo)

  13. final case class Yield[Element](element: Element) extends AnyVal with Keyword[Yield[Element], Unit] with Product with Serializable

    Permalink

    Author:

    杨博 (Yang Bo)

    Example:
    1. This Yield keyword must be put inside a function that returns Stream[Element] or Stream[Element] !! ..., or it will not compile.

      "def f(): Int = !Yield(1)" shouldNot compile

Value Members

  1. object AsynchronousIo

    Permalink
  2. object Await extends Serializable

    Permalink
  3. object Break extends Break with Product with Serializable

    Permalink

    Author:

    杨博 (Yang Bo)

  4. object Catch extends LowPriorityCatch0 with Serializable

    Permalink
  5. object Each extends Serializable

    Permalink
  6. object Fork extends Serializable

    Permalink
  7. object Get extends Serializable

    Permalink
  8. object Monadic extends Serializable

    Permalink
  9. object Put extends Serializable

    Permalink
  10. object Return extends Serializable

    Permalink
  11. object Shift extends LowPriorityShift0 with Serializable

    Permalink
  12. object Using extends Serializable

    Permalink

  13. object Yield extends Serializable

    Permalink

Inherited from AnyRef

Inherited from Any

Ungrouped