Class/Object

com.thoughtworks.dsl.keywords

Put

Related Docs: object Put | package keywords

Permalink

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

Put is a Keyword to replace the value of the current 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.

We use unary function as the domain of mutable state. The parameter of the unary function can be read from the Get keyword, and changed by the Put keyword.

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 Vector[Any] of string buffers.

    def formatter: Double => Int => Vector[Any] => String = {
      !Put(!Get[Vector[Any]] :+ "x=")
      !Put(!Get[Vector[Any]] :+ !Get[Double])
      !Put(!Get[Vector[Any]] :+ ",y=")
      !Put(!Get[Vector[Any]] :+ !Get[Int])
      !Return((!Get[Vector[Any]]).mkString)
    }
    formatter(0.5)(42)(Vector.empty) should be("x=0.5,y=42")
  2. ,
  3. The following example creates a function that accepts a string parameter and returns the upper-cased last character of the parameter.

    def upperCasedLastCharacter: String => Char = {
      val initialValue = !Get[String]()
      !Put(initialValue.toUpperCase)
      val upperCased = !Get[String]()
      Function.const(upperCased.last)
    }

    For example, given a string of foo, the upper-cased last character should be O.

    // Output: O
    upperCasedLastCharacter("foo") should be('O')
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: S)

    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[S] to any2stringadd[Put[S]] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (Put[S], B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from Put[S] to ArrowAssoc[Put[S]] 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[S], 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[S], Domain, Unit]): Domain

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

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

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

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

    Permalink
    Implicit information
    This member is added by an implicit conversion from Put[S] to Ensuring[Put[S]] 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[S] to StringFormat[Put[S]] 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: S

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

    Permalink
    Implicit information
    This member is added by an implicit conversion from Put[S] to ArrowAssoc[Put[S]] 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[S], Unit]

Inherited from AnyVal

Inherited from Any

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

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

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

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

Ungrouped