-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make `Optional` an `IterableOnce` So that we can: ``` def get(a: A): Optional[B] = ... val list: List[A] = ... val result: List[B] = list.flatMap(get) ``` * scalafmt * fix compilation * Make it compile with Scala 2.12 * Make tests pass * clean * Clean * Make test fail * Make test pass * Make test fail * Make test pass * Fix CI
- Loading branch information
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
core-tests/shared/src/test/scala-2.13+/zio/prelude/data/OptionalSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package zio.prelude.data | ||
|
||
import zio.Scope | ||
import zio.prelude.ZIOBaseSpec | ||
import zio.test.{Spec, TestEnvironment, assertTrue} | ||
|
||
object OptionalSpec extends ZIOBaseSpec { | ||
|
||
override def spec: Spec[TestEnvironment with Scope, Any] = | ||
suite("Optional")( | ||
test("is an IterableOnce") { | ||
def get(a: Int): Optional[Long] = Optional.Present(a.toLong) | ||
val list: List[Int] = List(1, 2, 3) | ||
val result: List[Long] = list.flatMap(get) | ||
|
||
assertTrue(result == List(1L, 2L, 3L)) | ||
} | ||
) | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
core/shared/src/main/scala-2.12/zio/prelude/IterableOnceCompat.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package zio.prelude | ||
|
||
/** | ||
* Needed because Scala 2.12 doesn't have `IterableOnce` | ||
*/ | ||
private[prelude] trait IterableOnceCompat[+A] { | ||
|
||
/** | ||
* Copied from `IterableOnce#iterator` | ||
*/ | ||
def iterator: Iterator[A] | ||
|
||
/** | ||
* Adapted from `IterableOnce#knownSize` | ||
*/ | ||
def knownSize: Int | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
core/shared/src/main/scala-2.13+/zio/prelude/IterableOnceCompat.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package zio.prelude | ||
|
||
/** | ||
* Needed because Scala 2.12 doesn't have `IterableOnce` | ||
* | ||
* TODO: Remove when support for Scala 2.12 is dropped | ||
*/ | ||
private[prelude] trait IterableOnceCompat[+A] extends IterableOnce[A] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters