Skip to content

Commit 11c600c

Browse files
authored
Merge pull request #540 from Atry/let-each-great-again
Rename FromIterable to Each for consistency with Dsl.scala 1.x
2 parents 8c3124f + 0039016 commit 11c600c

File tree

17 files changed

+100
-89
lines changed

17 files changed

+100
-89
lines changed

Dsl/src/main/scala/com/thoughtworks/dsl/Dsl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ object Dsl extends LowPriorityDsl0 {
114114
/** The AST returned from a `for`...`yield` or a `for`...`do` expression.
115115
*
116116
* Note that a [[For]] does not directly support !-notation.
117-
* Instead, [[keywords.FromIterable.ToView]] is used to convert a [[For]] to a
117+
* Instead, [[keywords.Each.ToView]] is used to convert a [[For]] to a
118118
* [[Keyword]] that supports !-notation.
119119
*/
120120
sealed trait For

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ We also provide some built-in keywords, including:
2424
* The `NullSafe` keyword for the null safe operator, similar to the `?` operator in Kotlin and Groovy.
2525
* The `NoneSafe` keyword for the `None` safe operator, similar to the `Maybe` monad in Haskell.
2626

27-
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 `FromIterable`, `Using` and `Shift` together.
27+
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.
2828

2929
## Getting Started
3030

build.sbt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ lazy val `domains-Task` =
3434
`keywords-Shift`,
3535
reset,
3636
`domains-Continuation`,
37-
`keywords-FromIterable` % Test,
3837
`keywords-Using` % Test,
3938
`keywords-Yield` % Test,
40-
`keywords-FromIterable` % Test
39+
`keywords-Each` % Test
4140
)
4241

43-
lazy val `keywords-FromIterable` =
42+
lazy val `keywords-Each` =
4443
crossProject(JSPlatform, JVMPlatform)
4544
.crossType(CrossType.Pure)
4645
.dependsOn(Dsl, reset % Test, `keywords-Pure`, `keywords-FlatMap`)
@@ -116,9 +115,8 @@ lazy val `keywords-AsynchronousIo` =
116115
.crossType(CrossType.Pure)
117116
.dependsOn(
118117
`keywords-Shift`,
119-
`keywords-FromIterable` % Test,
118+
`keywords-Each` % Test,
120119
`keywords-Using` % Test,
121-
`keywords-FromIterable` % Test,
122120
`domains-Task` % Test
123121
)
124122

@@ -153,7 +151,7 @@ lazy val `keywords-Await` =
153151
`keywords-Get` % Test,
154152
`keywords-Return` % Test,
155153
`keywords-Yield` % Test,
156-
`keywords-FromIterable` % Test
154+
`keywords-Each` % Test
157155
)
158156

159157
lazy val `scala-async` =
@@ -167,7 +165,7 @@ lazy val `keywords-Yield` =
167165
.dependsOn(
168166
Dsl,
169167
reset % Test,
170-
`keywords-FromIterable` % Test,
168+
`keywords-Each` % Test,
171169
`keywords-Shift` % Test,
172170
)
173171

domains-Task/.jvm/src/test/scala/com/thoughtworks/dsl/domains/taskSpec.scala

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.thoughtworks.dsl.Dsl.{!!}
66
import org.scalatest.Assertion
77
import scala.language.implicitConversions
88

9-
import com.thoughtworks.dsl.keywords.{Using, FromIterable}
9+
import com.thoughtworks.dsl.keywords.{Using, Each}
1010
import com.thoughtworks.dsl.domains._
1111
import com.thoughtworks.dsl.keywords.Shift
1212

@@ -43,7 +43,7 @@ final class taskSpec extends AsyncFreeSpec with Matchers {
4343
val task1: Task[Int] = Task.now(1)
4444

4545
val ts = *[Task]/* .join */ apply Seq {
46-
!FromIterable(0 until 10) + !Shift(task1)
46+
!Each(0 until 10) + !Shift(task1)
4747
}
4848

4949
!Shift(ts) should be(1 until 11)
@@ -80,6 +80,19 @@ final class taskSpec extends AsyncFreeSpec with Matchers {
8080
!Shift(task2) should be("try: my exception")
8181
})
8282

83+
"try with Each" in {
84+
val listTask = Task {
85+
val x =
86+
try {
87+
List(10 * !Each(List(1, 2)))
88+
} finally {}
89+
x
90+
}
91+
Task.toFuture(listTask).map {
92+
_ should be(List(10, 20))
93+
}
94+
}
95+
8396
"empty try" in {
8497
val logs = ArrayBuffer.empty[String]
8598

@@ -183,11 +196,11 @@ final class taskSpec extends AsyncFreeSpec with Matchers {
183196
t0: Task[Seq[Task[Seq[Task[Seq[Task[Seq[Float]]]]]]]]
184197
): Task[Seq[Seq[Seq[Seq[Float]]]]] = {
185198
Task /*.join*/ apply Seq {
186-
val t1 = !FromIterable(!Shift(t0))
199+
val t1 = !Each(!Shift(t0))
187200
!Shift(Task /*.join*/ apply Seq {
188-
val t2 = !FromIterable(!Shift(t1))
201+
val t2 = !Each(!Shift(t1))
189202
!Shift(Task /*.join*/ apply Seq {
190-
val t3 = !FromIterable(!Shift(t2))
203+
val t3 = !Each(!Shift(t2))
191204
!Shift(t3)
192205
})
193206
})

domains-Task/src/main/scala/com/thoughtworks/dsl/domains/Task.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import scala.util.control.TailCalls.TailRec
2121
*
2222
* @template
2323
* @example A [[Task]] can be created from `for`-comprehension,
24-
* where [[keywords.FromIterable]] can be used together to asynchronously iterate collections.
24+
* where [[keywords.Each]] can be used together to asynchronously iterate collections.
2525
*
2626
* For example, the above `concatenateRemoteData` downloads and concatenates data from multiple URLs.
2727
*
@@ -31,11 +31,11 @@ import scala.util.control.TailCalls.TailRec
3131
* import com.thoughtworks.dsl.keywords._
3232
* import com.thoughtworks.dsl.domains.Task
3333
* import java.net.URL
34-
* def concatenateRemoteData(urls: List[URL], downloader: URL => Task[Vector[Byte]]) = FromIterable.ToView {
34+
* def concatenateRemoteData(urls: List[URL], downloader: URL => Task[Vector[Byte]]) = Each.ToView {
3535
* for {
36-
* url <- FromIterable(urls)
36+
* url <- Each(urls)
3737
* data <- Shift(downloader(url))
38-
* byte <- FromIterable(data)
38+
* byte <- Each(data)
3939
* } yield byte
4040
* }.to[Task]
4141
* }}}

domains-scalaz/src/main/scala/com/thoughtworks/dsl/domains/scalaz.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import scala.util.control.NonFatal
1919
* @example [[scalaz.Free.Trampoline]] is a monadic data type that performs tail call optimization.
2020
* It can be built from a `@[[Dsl.reset reset]]` code block within some [[Dsl.Keyword#unary_$bang !-notation]],
2121
* similar to the [[com.thoughtworks.each.Monadic.EachOps#each each]] method in
22-
* [[https://github.com/ThoughtWorksInc/each ThoughtWorks FromIterable]].
22+
* [[https://github.com/ThoughtWorksInc/each ThoughtWorks Each]].
2323
*
2424
* {{{
2525
* import _root_.scalaz.Trampoline

keywords-AsynchronousIo/src/main/scala/com/thoughtworks/dsl/keywords/AsynchronousIo.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import scala.util.control.NonFatal
4040
* and other keywords can be used together in the same `for` block.
4141
*
4242
* For example, the following `cat` function contains a single `for` block to concatenate file contents.
43-
* It asynchronously iterates elements `Seq`, `ArrayBuffer` and `String` with the help of [[keywords.FromIterable]],
43+
* It asynchronously iterates elements `Seq`, `ArrayBuffer` and `String` with the help of [[keywords.Each]],
4444
* managed native resources with the help of [[keywords.Using]],
4545
* performs previously created `readAll` task with the help of [[keywords.Shift]],
4646
* and finally converts the return type [[comprehension.ComprehensionOps.as as]] a `Task[Vector[Char]]`.
@@ -51,13 +51,13 @@ import scala.util.control.NonFatal
5151
* import com.thoughtworks.dsl.domains.Task
5252
* import com.thoughtworks.dsl.Dsl.to
5353
* import java.net.URL
54-
* def cat(paths: Path*) = FromIterable.ToView {
54+
* def cat(paths: Path*) = Each.ToView {
5555
* for {
56-
* path <- FromIterable(paths)
56+
* path <- Each(paths)
5757
* channel <- Using(AsynchronousFileChannel.open(path))
5858
* charBuffers <- Shift(readAll(channel))
59-
* charBuffer <- FromIterable(charBuffers)
60-
* char <- FromIterable(charBuffer.toString)
59+
* charBuffer <- Each(charBuffers)
60+
* char <- Each(charBuffer.toString)
6161
* } yield char
6262
* }.to[Task]
6363
* }}}

keywords-Await/src/test/scala/com/thoughtworks/dsl/keywords/AwaitTest.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AwaitTest extends AsyncFreeSpec with Matchers with Inside {
3131
type Id[A] = A
3232
"testComprehension1" in {
3333
def inner1 = for {
34-
j <- FromIterable(0 until 3)
34+
j <- Each(0 until 3)
3535
} yield 100 + j
3636

3737
val ast1 = Await(Future(1)).flatMap { i =>
@@ -44,7 +44,7 @@ class AwaitTest extends AsyncFreeSpec with Matchers with Inside {
4444
Await[Int],
4545
Int,
4646
Dsl.For.Yield.Map[
47-
FromIterable[Int],
47+
Each[Int],
4848
Int,
4949
Int
5050
],
@@ -54,20 +54,20 @@ class AwaitTest extends AsyncFreeSpec with Matchers with Inside {
5454

5555
*[Future] {
5656
(!Await(
57-
FromIterable.ToView(ast1).to[Future]
57+
Each.ToView(ast1).to[Future]
5858
)).toVector should be(Vector(100, 101, 102))
5959
}
6060
}
6161

6262
"testComprehension2" in {
6363
import Dsl._
6464
val inner2 = for {
65-
j <- FromIterable(0 until 10)
65+
j <- Each(0 until 10)
6666
} yield 111
6767
summon[
6868
inner2.type
6969
<:<
70-
Dsl.For.Yield.Map[FromIterable[Int], Int, Int]
70+
Dsl.For.Yield.Map[Each[Int], Int, Int]
7171
]
7272
val ast2 = Await(Future(1)).flatMap { i =>
7373
inner2
@@ -79,7 +79,7 @@ class AwaitTest extends AsyncFreeSpec with Matchers with Inside {
7979
Await[Int],
8080
Int,
8181
Dsl.For.Yield.Map[
82-
FromIterable[Int],
82+
Each[Int],
8383
Int,
8484
Int
8585
],
@@ -91,9 +91,9 @@ class AwaitTest extends AsyncFreeSpec with Matchers with Inside {
9191

9292
"testComprehension3" in {
9393
import Dsl._
94-
val ast3 = FromIterable.ToView.toKeyword(for {
94+
val ast3 = Each.ToView.toKeyword(for {
9595
i <- Await(Future(1))
96-
j <- FromIterable(0 until 10)
96+
j <- Each(0 until 10)
9797
} yield 111)
9898
summon[
9999
ast3.type
@@ -102,7 +102,7 @@ class AwaitTest extends AsyncFreeSpec with Matchers with Inside {
102102
Await[Int],
103103
Int,
104104
FlatMap[
105-
FromIterable[Int],
105+
Each[Int],
106106
Int,
107107
Pure[collection.View[Int]]
108108
]
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)