Re: Different behaviour from Option map in scala compared to Optional map in java
David Starner <[email protected]> Sun, 17 Apr 2016 16:08:16 +0000
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <CAMZ=zj7axh_+PX7yBzUt1W+o375URSrDqGhy28A2aSsf_ASM-Q@mail.gmail.com> |
On Sun, Apr 17, 2016 at 3:27 AM Marc Arndt <[email protected]> wrote: > In scala the method map in Option is implemented as followed: > > > * @inline final def map[B](f: A => B): Option[B] = if (isEmpty) None > else Some(f(this.get))*This method requires, that f doesn't return null. > That just means that if f returns null, the map returns Some(null). > I'm not sure if this behaviour is intended. > Scala treats null generally as being something that is supported for legacy Java-compatibility reasons only. In that context, it makes perfect sense to just pass through the null here. Java 8's choice may be reasonable in its context, but less so for Scala. -- 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.