Class/Object

com.thoughtworks.dsl.keywords

Put

Related Docs: object Put | package keywords

Permalink

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

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)

Source
Put.scala
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

Linear Supertypes
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Put
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. Keyword
  7. AnyVal
  8. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Put(value: A)

    Permalink

Value Members

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

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

    Permalink
    Definition Classes
    Any
  3. def +(other: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from Put[A] to any2stringadd[Put[A]] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (Put[A], B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from Put[A] to ArrowAssoc[Put[A]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  6. final def apply[Domain](handler: (Unit) ⇒ Domain)(implicit dsl: Dsl[Put[A], Domain, Unit]): Domain

    Permalink

    An alias to cpsApply.

    An alias to cpsApply.

    Definition Classes
    Keyword
    Annotations
    @inline()
  7. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  8. final def cpsApply[Domain](handler: (Unit) ⇒ Domain)(implicit dsl: Dsl[Put[A], Domain, Unit]): Domain

    Permalink
    Definition Classes
    Keyword
    Annotations
    @inline()
  9. def ensuring(cond: (Put[A]) ⇒ Boolean, msg: ⇒ Any): Put[A]

    Permalink
    Implicit information
    This member is added by an implicit conversion from Put[A] to Ensuring[Put[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  10. def ensuring(cond: (Put[A]) ⇒ Boolean): Put[A]

    Permalink
    Implicit information
    This member is added by an implicit conversion from Put[A] to Ensuring[Put[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  11. def ensuring(cond: Boolean, msg: ⇒ Any): Put[A]

    Permalink
    Implicit information
    This member is added by an implicit conversion from Put[A] to Ensuring[Put[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  12. def ensuring(cond: Boolean): Put[A]

    Permalink
    Implicit information
    This member is added by an implicit conversion from Put[A] to Ensuring[Put[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  13. def formatted(fmtstr: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from Put[A] to StringFormat[Put[A]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  14. def getClass(): Class[_ <: AnyVal]

    Permalink
    Definition Classes
    AnyVal → Any
  15. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  16. final def unary_!: Unit

    Permalink
    Definition Classes
    Keyword
    Annotations
    @shift() @compileTimeOnly( ... )
  17. val value: A

    Permalink
  18. def [B](y: B): (Put[A], B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from Put[A] to ArrowAssoc[Put[A]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from Keyword[Put[A], Unit]

Inherited from AnyVal

Inherited from Any

Inherited by implicit conversion any2stringadd from Put[A] to any2stringadd[Put[A]]

Inherited by implicit conversion StringFormat from Put[A] to StringFormat[Put[A]]

Inherited by implicit conversion Ensuring from Put[A] to Ensuring[Put[A]]

Inherited by implicit conversion ArrowAssoc from Put[A] to ArrowAssoc[Put[A]]

Ungrouped