Dsl.scala icon indicating copy to clipboard operation
Dsl.scala copied to clipboard

Redesign comprehension

Open Atry opened this issue 4 years ago • 3 comments

Currently, for comprehension is considered a way to transform keywords.

For example, the following code are equivalent.


def fetchURL(url: Uri): Future[ByteString] = ???

def fetchScalaWebsite(uriListFuture: Future[List[Uri]]): Future[List[ByteString]] = {
  (for {
    uriList <- Await(uriListFuture)
    uri <- Each(uriList)
    content <- Await(fetchURL(uri))
  } yield content).to[Future[List[ByteString]]]
}
// Dsl.scala 2.x
def fetchScalaWebsite(uriListFuture: Future[List[Uri]]): Future[List[ByteString]] = reset[Future[List[ByteString]]] {
  val uriList: List[Uri] = !Await(uriListFuture)
  val uri: Uri = !Each(uriList)
  val content: ByteString = !Await(fetchURL(uri))
  !Return(content)
}
// Dsl.scala 1.x
def fetchScalaWebsite(uriListFuture: Future[List[Uri]]): Future[List[ByteString]] = {
  val uriList: List[Uri] = !Await(uriListFuture)
  val uri: Uri = !Each(uriList)
  val content: ByteString = !Await(fetchURL(uri))
  !Return(content)
} : @reset

However, we cannot mix together comprehension and !-notation:

// Dsl.scala 2.x
def fetchScalaWebsite(uriListFuture: Future[List[Uri]]): Future[List[ByteString]] = reset[Future[List[ByteString]]] {
  val uriList: List[Uri] = !Await(uriListFuture)
  val contentList: List[ByteString] =
    for (uri <- Each(uriList)) yield {
      !Await(fetchURL(uri))
    }
  !Return(contentList)
}

Do we want to change the comprehension design to support the above use case?

Atry avatar Nov 26 '21 08:11 Atry

Continue should be removed and WithFilter needs to refactor to block based

Atry avatar Dec 12 '21 04:12 Atry

Currently we need manual import of extension methods for comprehension, this is not ideal because manual import could result conflicts with other extension methods. We should let all keywords <: Keyword[Value] to enable comprehension automatically

Atry avatar Dec 12 '21 04:12 Atry

Implemented. Need documentation.

Atry avatar Dec 18 '21 20:12 Atry