-
Notifications
You must be signed in to change notification settings - Fork 7
Make UNone extend WrappedNone, with a depth of 0. #4
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
base: master
Are you sure you want to change the base?
Conversation
This design removes one case in `USome.apply()`.
How about: diff --git src/main/scala/uoption/package.scala src/main/scala/uoption/package.scala
index a153621..02b5ccf 100644
--- src/main/scala/uoption/package.scala
+++ src/main/scala/uoption/package.scala
@@ -14,11 +14,12 @@ package object uoption {
override def toString(): String = stringRepr
}
- object UNone extends WrappedNone(0, null) {
+ type UNone <: AnyRef
+ val UNone: UNone = new WrappedNone(0, null) {
override def toString(): String = "UNone"
- }
+ }.asInstanceOf[UNone]
- type UOption[+A] >: UNone.type <: AnyRef
+ type UOption[+A] >: UNone <: AnyRef
object UOption {
@inline // only for Scala.js?? |
| private[uoption] val wrap: WrappedNone = new WrappedNone(1, this) | ||
|
|
||
| object UNone extends WrappedNone(0, null) { | ||
| override def toString(): String = "UNone" |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Unfortunately that increases the amount of instructions necessary to load the instance. It's a module-load (i.e., a static field read) plus a field access, instead of just a module-load. Moreover, it changes the type inferred for |
|
I see what you mean. |
Me neither, which is why I'm afraid of them. ;) |
| private[uoption] val unwrap: WrappedNone // null when this is UNone | ||
| ) { | ||
| lazy val wrap: WrappedNone = | ||
| private[uoption] lazy val wrap: WrappedNone = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, are these required with the class being private[uoption]?
Is this in case you forget to hide these if you make the class non-private?
This design removes one case in
USome.apply().However, it does require the public
object UNoneto extend theprivate[uoption] class WrappedNone, a design I'm not really fond of.