Re: Option flatten does not use an implicit conversion
Bruno Bieth <[email protected]> Wed, 9 Mar 2016 00:46:19 -0800 (PST)
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
But all traversables implement flatten with an implicit conversion: https://github.com/scala/scala/blob/2.12.x/src/library/scala/collection/generic/GenericTraversableTemplate.scala#L169 There's this comment though: /*<:<!!!*/ which I couldn't track in github. So I'd guess that for backward compatibility reasons this was kept but flatten on Option came at a later point when they realized that an implicit conversion brings troubles? Do you have an example of a surprising behavior if Option.flatten were to use an implicit conversion? Thanks On Friday, March 4, 2016 at 4:18:59 PM UTC+1, nafg wrote: > > I think he means it should use the equivalent of view bounds, rather than > requiring evidence that it's an actual subtype. def flatten[B](implicit > view: A => Option[B]): ... > > The answer is the same issue with all implicit conversions: They make > behavior more surprising and less type-constrained. > > > On Fri, Mar 4, 2016 at 10:01 AM Oliver Ruebenacker <[email protected] > <javascript:>> wrote: > >> >> Hello, >> >> How would it work with an implicit conversion? >> >> Best, Oliver >> >> On Fri, Mar 4, 2016 at 5:33 AM, Bruno Bieth <[email protected] >> <javascript:>> wrote: >> >>> I was surprised that Some(Success(1)).flatten does not compile? >>> What is the rationale behind this: >>> >>> def flatten[B](implicit ev: A <:< Option[B]): Option[B] = if (isEmpty) >>> None else ev(this.get) >>> >>> Why not having an implicit conversion: (implicit conv: A => Option[B])? >>> >>> Bruno >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "scala-language" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected] <javascript:>. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> Oliver Ruebenacker >> Senior Software Engineer, Diabetes Portal >> <http://www.type2diabetesgenetics.org/>, Broad Institute >> <http://www.broadinstitute.org/> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "scala-language" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "scala-language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.