Redesign comprehension
Atry opened this issue · 3 comments
Atry commented
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 commented
Continue
should be removed and WithFilter
needs to refactor to block based
Atry commented
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 commented
Implemented. Need documentation.