-
Notifications
You must be signed in to change notification settings - Fork 18
Topic/tap each specialized #79
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
Conversation
* collection" contract even though it seems unlikely to matter much in a | ||
* collection with max size 1. | ||
*/ | ||
class WithFilter(p: A => Boolean) { |
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.
Is there a reason for this not to be final
?
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.
I took the code of scala.Option
from the 2.13.x branch. All your findings relate to that code. As @NthPortal points out below writing replacements for existing classes is not the way to go for this repository, so I'll provide an extension method instead (probably in a new PR, that's cleaner).
*/ | ||
@SerialVersionUID(1234815782226070388L) // value computed by serialver for 2.11.2, annotation added in 2.11.4 | ||
final case class Some[+A](value: A) extends Option[A] { | ||
def get: A = value |
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.
def get: A = value | |
override def get: A = value |
*/ | ||
@SerialVersionUID(5066590221178148012L) // value computed by serialver for 2.11.2, annotation added in 2.11.4 | ||
case object None extends Option[Nothing] { | ||
def get: Nothing = throw new NoSuchElementException("None.get") |
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.
def get: Nothing = throw new NoSuchElementException("None.get") | |
override def get: Nothing = throw new NoSuchElementException("None.get") |
* } | ||
* }}} | ||
*/ | ||
final def isDefined: Boolean = !isEmpty |
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.
final def isDefined: Boolean = !isEmpty | |
final def isDefined: Boolean = this ne None |
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.
this library cannot provide replacements for existing library classes. it must instead provide extension methods. and it's possible that it won't have higher priority than the existing conversion
@NthPortal Sorry, I overlooked in the README that changes/additions to existing library classes should be coded as extension methods. I will open a new PR with the specialized extension method, replacing this PR - I think it's cleaner that way... If I provide a specialized tapEach extension for Option, will this stay an extension in Scala 3.1 (which I wouldn't like too much) or will the specialized extension method be "merged" into scala.Option directly eventually? If the latter, would it be a good idea to add a comment how this could be done? |
to be honest, I'm suspicious the conversion to |
Superseded by PR #80 |
Add specialised version of
tapEach
toscala.Option
to preserve the type.The actual addition is in the second commit fb1f19a.
See also https://stackoverflow.com/questions/67017901/why-does-scala-option-tapeach-return-iterable-not-option?noredirect=1#comment118462412_67017901