Skip to content
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

Merged
merged 19 commits into from
Nov 13, 2024

Conversation

guizmaii
Copy link
Member

@guizmaii guizmaii commented Nov 13, 2024

@sideeffffect Did I forget any typeclass? 🤔

@guizmaii guizmaii self-assigned this Nov 13, 2024
@guizmaii guizmaii changed the title Add IdentityBoth instance for zio.prelude.data.Optional Add all typeclass instance for the zio.prelude.data.Optional type (copied from the Option instances) Nov 13, 2024
@guizmaii guizmaii changed the title Add all typeclass instance for the zio.prelude.data.Optional type (copied from the Option instances) Add all the typeclasses instance for the zio.prelude.data.Optional type (copied from the Option instances) Nov 13, 2024
Comment on lines +1189 to +1197
fa match {
case Some(a) =>
fb match {
case Some(b) => Some((a, b))
case None => None
}
case None => None
}
}
Copy link
Member Author

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
Copy link
Member Author

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] =
Copy link
Member Author

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] =
Copy link
Member Author

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

@guizmaii guizmaii force-pushed the optional_instances branch 3 times, most recently from df65490 to 56c240c Compare November 13, 2024 07:49
/**
* Derives an `Equal[Optional[A]]` given an `Equal[A]`.
*/
implicit def OptionalEqual[A: Equal]: Equal[Optional[A]] =
Copy link
Member Author

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] =
Copy link
Member Author

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 🤔

@guizmaii guizmaii marked this pull request as ready for review November 13, 2024 07:51
@guizmaii guizmaii requested a review from a team as a code owner November 13, 2024 07:51
Copy link
Member

@sideeffffect sideeffffect left a 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.

@guizmaii guizmaii merged commit fe4e256 into series/2.x Nov 13, 2024
21 checks passed
@guizmaii guizmaii deleted the optional_instances branch November 13, 2024 22:26
@guizmaii
Copy link
Member Author

@sideeffffect Can we make a new release maybe, please?

@sideeffffect
Copy link
Member

Most definitely! https://github.com/zio/zio-prelude/releases/tag/v1.0.0-RC34

@sideeffffect
Copy link
Member

@jdegoes could we please add @guizmaii the privileges to make releases? 🙏 He's proven to be an outstandingly good co-maintainer.

@guizmaii
Copy link
Member Author

@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 :)

@sideeffffect
Copy link
Member

Please, feel free take these decisions yourself 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants