Is there a succinct way to compare equality between two Options, but which returns false in the case of None?
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
I think I like yours better, assuming that opt1 == opt2 is the same as
opt1.get == opt2.get if they're both Some[X] and false if they're not.
Weirdly enough, I can't figure out where the equals/== method is
defined for Option.
And I mean better than this:opt1.isDefined && opt1 == opt2which is succinct, but not FP "pretty" :-)
I can't help but ask "What's wrong with your original code?" It is clear and to the point. Wrap it in a function and who cares how it is implemented. Are the words "pretty" and "cryptic" being mixed up? What is not functional about the original?
-Chris
On Saturday, May 25, 2013 8:29:59 PM UTC-4, Nils wrote:And I mean better than this:opt1.isDefined && opt1 == opt2which is succinct, but not FP "pretty" :-)On Sat, May 25, 2013 at 7:28 PM, Nils Kilden-Pedersen <nil...@gmail.com> wrote:
Is there a succinct way to compare equality between two Options, but which returns false in the case of None?
On Sun, May 26, 2013 at 6:39 PM, Nils Kilden-PedersenFrom an aesthetic point of view I think that both Kevin's solution and
<ni...@kilden-pedersen.net> wrote:
> I think the one that comes closest, by being both succinct, readable, and
> doesn't feel hacky, is Kevin's proposal:
>
> opt1.map(_ => opt1 == opt2).getOrElse(false)
>
> But again, it's hard to see that it's any substantial improvement.
>
> I was hoping for something like op1 === opt2, or some other succinct
> operator.
your original are lacking in that they mask the symmetry between opt1
and opt2 ... and I suspect it's that symmetry that makes your
hypothetical op1 === opt2 seem more attractive.
Both Stefan's solution
and mine are nicely symmetric (which I guess is really what I meant by
"cute" ;-)
Cheers,
Miles
--
Miles Sabin
tel: +44 7813 944 528
skype: milessabin
gtalk: mi...@milessabin.com
g+: http://www.milessabin.com
http://twitter.com/milessabin
Yes, but yours is also more "noisy" by involving Either (Right to be exact), and Stefan's is just unreadable to me, and probably anyone else who isn't intimate with scalaz.
On 27 May 2013 04:30, "Stefan Hoeck" <efasc...@gmail.com> wrote:
> Which of course does not prevent you from learning something from these solutions.
Agreed. Mine illustrates how projecting values into a richer type allows finer discriminations to be made: observe how after the .toRights both the LHS and RHS inhabit Either[Int, Boolean] in a way which trivializes the equivalence you're looking for.
Cheers,
Miles