Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign comprehension #477

Open
Atry opened this issue Nov 26, 2021 · 3 comments
Open

Redesign comprehension #477

Atry opened this issue Nov 26, 2021 · 3 comments

Comments

@Atry
Copy link
Collaborator

Atry commented Nov 26, 2021

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 Atry changed the title Remove Map Redesign comprehension Dec 11, 2021
@Atry
Copy link
Collaborator Author

Atry commented Dec 12, 2021

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

@Atry
Copy link
Collaborator Author

Atry commented Dec 12, 2021

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
Copy link
Collaborator Author

Atry commented Dec 18, 2021

Implemented. Need documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant