Skip to content

Commit 81cb991

Browse files
authored
Merge pull request #405 from AVSystem/opt-to-immutable-iterable
Convert optional value wrappers to immutable Iterable
2 parents b21609f + 3f30fbc commit 81cb991

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

commons-core/src/main/scala/com/avsystem/commons/misc/NOpt.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.avsystem.commons.misc
22

3+
import com.avsystem.commons.IIterable
4+
35
object NOpt {
46
// These two are used as NOpt's raw value to represent empty NOpt and NOpt(null).
57
// Unfortunately, null itself can't be used for that purpose because https://github.com/scala/bug/issues/7396
@@ -20,7 +22,7 @@ object NOpt {
2022
def some[A](value: A): NOpt[A] =
2123
new NOpt(if (value == null) NullMarker else value)
2224

23-
implicit def opt2Iterable[A](xo: NOpt[A]): Iterable[A] = xo.toList
25+
implicit def opt2Iterable[A](xo: NOpt[A]): IIterable[A] = xo.toList
2426

2527
final val Empty: NOpt[Nothing] = new NOpt(EmptyMarker)
2628

commons-core/src/main/scala/com/avsystem/commons/misc/Opt.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.avsystem.commons.misc
22

3+
import com.avsystem.commons.IIterable
4+
35
object Opt {
46
// Used as Opt's raw value to represent empty Opt. Unfortunately, null can't be used for that purpose
57
// because https://github.com/scala/bug/issues/7396
@@ -12,7 +14,7 @@ object Opt {
1214
if (value != null) new Opt[A](value)
1315
else throw new NullPointerException
1416

15-
implicit def opt2Iterable[A](xo: Opt[A]): Iterable[A] = xo.toList
17+
implicit def opt2Iterable[A](xo: Opt[A]): IIterable[A] = xo.toList
1618

1719
final val Empty: Opt[Nothing] = new Opt(EmptyMarker)
1820

commons-core/src/main/scala/com/avsystem/commons/misc/OptRef.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.avsystem.commons.misc
22

3+
import com.avsystem.commons.IIterable
4+
35
object OptRef {
46
def apply[A >: Null](value: A): OptRef[A] = new OptRef[A](value)
57
def unapply[A >: Null](opt: OptRef[A]): OptRef[A] = opt //name-based extractor
@@ -13,7 +15,7 @@ object OptRef {
1315
if (optRef.isEmpty) Opt.Empty else Opt(unboxing.fun(optRef.get))
1416
}
1517

16-
implicit def opt2Iterable[A >: Null](xo: OptRef[A]): Iterable[A] = xo.toList
18+
implicit def opt2Iterable[A >: Null](xo: OptRef[A]): IIterable[A] = xo.toList
1719

1820
final val Empty: OptRef[Null] = new OptRef[Null](null)
1921

commons-core/src/test/scala/com/avsystem/commons/misc/OptTest.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.avsystem.commons.misc
22

3-
import com.avsystem.commons
4-
import org.scalatest.funsuite.AnyFunSuite
53
import com.avsystem.commons.JInteger
4+
import org.scalatest.funsuite.AnyFunSuite
65

76
class OptTest extends AnyFunSuite {
87
test("nonempty test") {

0 commit comments

Comments
 (0)