-
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
Add all the typeclasses instance for the zio.prelude.data.Optional
type (copied from the Option
instances)
#1415
Conversation
46f9bf0
to
3dc9c9e
Compare
IdentityBoth
instance for zio.prelude.data.Optional
zio.prelude.data.Optional
type (copied from the Option
instances)
zio.prelude.data.Optional
type (copied from the Option
instances)zio.prelude.data.Optional
type (copied from the Option
instances)
fa match { | ||
case Some(a) => | ||
fb match { | ||
case Some(b) => Some((a, b)) | ||
case None => None | ||
} | ||
case None => 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.
Just optimizing the code here
case Optional.Absent => other | ||
} | ||
final def orElse[B >: A](alternative: => Optional[B]): Optional[B] = | ||
if (isEmpty) alternative else this |
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.
Code copied from Option#orElse
. Avoids the call to the unapply
function in Optional.Present(_)
case Optional.Present(_) => self | ||
case Optional.Absent => other | ||
} | ||
final def orElse[B >: A](alternative: => Optional[B]): Optional[B] = |
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 Option#orElse
method is lazy
@@ -50,7 +50,7 @@ sealed trait Optional[+A] { self => | |||
case Optional.Absent => ifEmpty | |||
} | |||
|
|||
final def flatten[B](implicit ev: A <:< Option[B]): Option[B] = | |||
final def flatten[B](implicit ev: A <:< Optional[B]): Optional[B] = |
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 didn't understand why the evidence what proving that A
was an Option[B]
nor why this method was returning an Option[B]
and not an Optional[B]
.
Probably a copy/paste mistake
c0ff1b0
to
120dcd9
Compare
df65490
to
56c240c
Compare
56c240c
to
0d843e8
Compare
/** | ||
* Derives an `Equal[Optional[A]]` given an `Equal[A]`. | ||
*/ | ||
implicit def OptionalEqual[A: Equal]: Equal[Optional[A]] = |
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.
@sideeffffect I didn't find the tests for this typeclass 🤔
/** | ||
* The [[DeriveEqual]] instance for [[Optional]]. | ||
*/ | ||
implicit val OptionalDeriveEqual: DeriveEqual[Optional] = |
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.
@sideeffffect I didn't find the tests for this typeclass 🤔
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.
Oh, wonderful. This looks good ❤️ Good to merge from what I can see.
@sideeffffect Can we make a new release maybe, please? |
Most definitely! https://github.com/zio/zio-prelude/releases/tag/v1.0.0-RC34 |
@sideeffffect Thanks for the compliments :) I think I already have these rights, I just don't feel legitimate to take these decisions by myself for now but if you tell me I can, then let's go :) |
Please, feel free take these decisions yourself 😉 |
@sideeffffect Did I forget any typeclass? 🤔