-
Notifications
You must be signed in to change notification settings - Fork 114
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
Make Optional
an IterableOnce
#1418
Conversation
76bba26
to
e55c403
Compare
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 thought Option(al) as Iterable is controversial https://www.wartremover.org/doc/warts.html#option2iterable
But if you really know what you're doing and want it, then I'm not adamantly opposed.
@@ -13,7 +14,7 @@ import scala.language.implicitConversions | |||
* The only difference between this type and [[scala.Option]] is that there is an implicit | |||
* conversion defined from `A`` to `Optional[A]`, and from `Option[A]`` to `Optional[A]`. | |||
*/ | |||
sealed trait Optional[+A] { self => | |||
sealed trait Optional[+A] extends IterableOnce[A] { self => |
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.
Why not Iterable
?
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.
The goal was to make a Chunk[Optional[A]]
behave the same way as a Chunk[Option[A]]
where we can just use flatten
or flatMap
to get rid of the empty values. And those two methods require an IterableOnce
.
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.
Fair enough, but the question still stands. Wouldn't it be better to extend Iterable
since we're changing things anyway? Maybe there are other use cases which won't do with mere IterableOnce
. Or do you think it will be more complicated?
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.
Why not Iterable?
Because Option
doesn't extend Iterable
but IterableOnce
🤷♂️
I'm just copying Option
code 🙂
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.
Ah, I see. Than that should be good enough for us too :)
Seems final override def flatMap[B, That](f: A => GenTraversableOnce[B])(implicit bf: CanBuildFrom[List[A], B, That]): That |
16e685c
to
d0e9519
Compare
Well, my solution is just to make it compile with Scala 2.12. |
So that we can: ``` def get(a: A): Optional[B] = ... val list: List[A] = ... val result: List[B] = list.flatMap(get) ```
d0e9519
to
fac152b
Compare
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 think this is good enough, immediate benefits and minimal maintenance efforts.
Nice, thanks guys 👏 |
So that we can:
TODO: