ThoughtWorksInc/Dsl.scala

Add `In` and `For` as a replacement of `Each` and `ForEach`

Atry opened this issue · 2 comments

Atry commented

Foreach is a hidden keyword automatically generated from foreach calls, for example:

val reified: For[Await[Future[1]], Int, Unit] = for ($x <- Await(Future(1))) {
  print($x)
}

The return type should be
Foreach[Await[Future[Int]], Int, Unit]

In is just a wrapper of collection types to prevent the foreach/map/flatMap/withFilter methods defined on the collection, for example:

val ast3:
  FlatMap[
    Await[Int],
    Int,
    FlatMap[
      In[Int],
      Int,
      Pure[Int]
    ]
  ] =
for {
  i <- Await(Future(1))
  j <- In(0 until 10)
} yield 111

Both In and Foreach are supposed to be used along with for expression instead of !-notation.

Atry commented

Note that the initial version of In and For will reuse type classes for Each and ForEach to make the migration easier.

Atry commented

See #477