keywords-akka-http-TApply


License

License

MIT
Categories

Categories

KeY Data Data Formats Formal Verification Akka Container Microservices Reactive libraries
GroupId

GroupId

com.thoughtworks.dsl
ArtifactId

ArtifactId

keywords-akka-http-tapply_2.12
Last Version

Last Version

1.0.0+6-49fac01b
Release Date

Release Date

Type

Type

jar
Description

Description

keywords-akka-http-TApply
keywords-akka-http-TApply
Project URL

Project URL

https://github.com/ThoughtWorksInc/Dsl.scala-akka-http
Project Organization

Project Organization

com.thoughtworks.dsl
Source Code Management

Source Code Management

https://github.com/ThoughtWorksInc/Dsl.scala-akka-http

Download keywords-akka-http-tapply_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.thoughtworks.dsl/keywords-akka-http-tapply_2.12/ -->
<dependency>
    <groupId>com.thoughtworks.dsl</groupId>
    <artifactId>keywords-akka-http-tapply_2.12</artifactId>
    <version>1.0.0+6-49fac01b</version>
</dependency>
// https://jarcasting.com/artifacts/com.thoughtworks.dsl/keywords-akka-http-tapply_2.12/
implementation 'com.thoughtworks.dsl:keywords-akka-http-tapply_2.12:1.0.0+6-49fac01b'
// https://jarcasting.com/artifacts/com.thoughtworks.dsl/keywords-akka-http-tapply_2.12/
implementation ("com.thoughtworks.dsl:keywords-akka-http-tapply_2.12:1.0.0+6-49fac01b")
'com.thoughtworks.dsl:keywords-akka-http-tapply_2.12:jar:1.0.0+6-49fac01b'
<dependency org="com.thoughtworks.dsl" name="keywords-akka-http-tapply_2.12" rev="1.0.0+6-49fac01b">
  <artifact name="keywords-akka-http-tapply_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.thoughtworks.dsl', module='keywords-akka-http-tapply_2.12', version='1.0.0+6-49fac01b')
)
libraryDependencies += "com.thoughtworks.dsl" % "keywords-akka-http-tapply_2.12" % "1.0.0+6-49fac01b"
[com.thoughtworks.dsl/keywords-akka-http-tapply_2.12 "1.0.0+6-49fac01b"]

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.8
com.thoughtworks.dsl : dsl_2.12 jar 1.2.0
com.typesafe.akka : akka-http_2.12 jar 10.1.8
com.thoughtworks.dsl : keywords-using_2.12 Optional jar 1.2.0

test (3)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.0.7
com.typesafe.akka : akka-stream-testkit_2.12 jar 2.5.21
com.typesafe.akka : akka-http-testkit_2.12 jar 10.1.8

Project Modules

There are no modules declared in this project.

Dsl.scala

Build Status Maven Central Scaladoc Join the chat at https://gitter.im/ThoughtWorksInc/Dsl.scala

Dsl.scala is a framework to create embedded Domain-Specific Languages in Scala. It can be considered as an alternative syntax to for comprehension, Scala Async and Scala Continuations. It unifies monads, generators, asynchronous functions, coroutines and continuations to a single universal syntax, and can be easily integrate to Scalaz, Cats, Scala Collections, Scala Futures, Akka HTTP, Java NIO, or your custom domains.

A DSL author is able to create language keywords by implementing the Dsl trait, which contains only one abstract method to be implemented. No knowledge about Scala compiler or AST macros is required.

DSLs written in Dsl.scala are collaborative with others DSLs and Scala control flows. A DSL user can create functions that contains interleaved DSLs implemented by different vendors, along with ordinary Scala control flows.

We also provide some built-in keywords, including:

  • The Await keyword for creating memoized asynchronous values as Scala Futures, similar to the await / async keywords in C#, Python and JavaScript.
  • The Shift keyword for creating asynchronous tasks as delimited continuations, similar to the shift operator in Scala Continuations.
  • The AsynchronousIo.Connect, AsynchronousIo.Accept, AsynchronousIo.Read and AsynchronousIo.Write keywords for performing I/O on an asynchronous channel.
  • The Yield keyword for generating lazy streams, similar to yield in C#, Python and JavaScript.
  • The Each keyword for iterating on a collection, similar to the list comprehension feature in Scala, Haskell, OCaml, Python and Lisp.
  • The Continue keyword LDK for skipping an element in an Each collection comprehension, similar to the native continue keyword in C/C++ or the mzero in Haskell.
  • The Fork keyword for duplicating current context, similar to the fork system call in POSIX.
  • The Return keyword for early returning, similar to the native return keyword in Scala.
  • The Using keyword to automatically close resources when exiting a scope, similar to the native using keyword in C#.
  • The Monadic keyword for creating Scalaz or Cats monadic control flow, similar to the !-notation in Idris.
  • The NullSafe keyword for the null safe operator, similar to the ? operator in Kotlin and Groovy.
  • The NoneSafe keyword for the None safe operator, similar to the Maybe monad in Haskell.

All the above keywords can be used together with each others. For example you can perform list comprehension to manipulate native resources in an asynchronous task by using Each, Using and Shift together.

Getting Started

Suppose you want to create a random number generator. The generated numbers should be stored in a lazily evaluated infinite stream, which can be built with the help of our built-in domain-specific keyword Yield.

So, you need to add the library that contains the implementation of the keyword Yield:

// Add the "keywords-yield" library in your build.sbt, to use the `Yield` keyword
libraryDependencies += "com.thoughtworks.dsl" %% "keywords-yield" % "latest.release"

// Add other "keywords-xxx" libraries in your build.sbt, to use other keywords
// libraryDependencies += "com.thoughtworks.dsl" %% "keywords-xxx" % "latest.release"

And the Dsl.scala compiler plug-ins that are shared by all DSLs:

// Add the following settings in your build.sbt 
addCompilerPlugin("com.thoughtworks.dsl" %% "compilerplugins-bangnotation" % "latest.release")
addCompilerPlugin("com.thoughtworks.dsl" %% "compilerplugins-reseteverywhere" % "latest.release")

The random number generator can be implemented as a recursive function that produces the next random number in each iteration.

import com.thoughtworks.dsl.keywords.Yield
// Must not annotated with @tailrec
def xorshiftRandomGenerator(seed: Int): scala.collection.immutable.Stream[Int] = {
  val tmp1 = seed ^ (seed << 13)
  val tmp2 = tmp1 ^ (tmp1 >>> 17)
  val tmp3 = tmp2 ^ (tmp2 << 5)
  !Yield(tmp3)
  xorshiftRandomGenerator(tmp3)
}

Note that a keyword is a plain case class. You need a ! prefix to the keyword to activate the DSL.

It's done. We can test it in ScalaTest:

val myGenerator = xorshiftRandomGenerator(seed = 123)
myGenerator(0) should be(31682556)
myGenerator(1) should be(-276305998)
myGenerator(2) should be(2101636938)

The call to xorshiftRandomGenerator does not throw a StackOverflowError because the execution of xorshiftRandomGenerator will be paused at the keyword Yield, and it will be resumed when the caller is looking for the next number.

Showcases

(Feel free to add your project here)

Links and related works

com.thoughtworks.dsl

ThoughtWorks Incubator

This is ThoughtWorks' sandbox GitHub Organization for short-term experiments. For our main Github organisation, please visit @thoughtworks

Versions

Version
1.0.0+6-49fac01b
1.0.0+5-0e1989fa
1.0.0+4-88aabb1f
1.0.0+2-45074fbd
1.0.0+1-1dbec22f
1.0.0
0.0.0+122-414d2ce2
0.0.0+122-e92453f4
0.0.0+122-d5438640
0.0.0+121-56272595
0.0.0+121-26860860
0.0.0+121-791961ca
0.0.0+121-579207e2
0.0.0+121-ede806b7
0.0.0+120-2b6c96ef
0.0.0+120-ef7698ef
0.0.0+118-436a13e9
0.0.0+118-d138f693
0.0.0+117-44e6206f
0.0.0+117-fcca0ce4
0.0.0+116-44210399
0.0.0+116-3d6d14ea
0.0.0+113-5500c090