That can be abused to add a 2nd empty state, which can be tempting. "It's either here, not here or not here yet!" I don't really mind what the implementation is, but it should not be possible to add a subtype as a third party.
https://github.com/JamesIry/jADT does quite well at generating algebraic data types (no flatMap yet though) given a brief definition, which might help anyone who is thinking about extending Optional. On Fri, Oct 26, 2012 at 2:29 PM, clay <[email protected]> wrote: > I prefer this algebraic data type design that is standard in every other > implementation of Option/Optional/Maybe (Scala, Haskell, F#, Functional Java > library, Atlassian's library, and even Guava) > > However, as mentioned earlier, JDK 8's Optional is completely and > purposefully avoiding this, and has Optional as more of a traditonal Java > class with a boolean flag. > > > On Friday, October 26, 2012 11:30:46 AM UTC-5, Ricky Clarkson wrote: >> >> Optional should really be a closed type, as it's basically an >> algebraic datatype, something like: >> >> abstract class Option<T> { >> private Option() { } >> static final class None<T> extends Option<T> { } >> static final class Some<T> extends Option<T> { ... } >> } >> >> I would not expect it to be something you can subtype as a third party. >> > -- > You received this message because you are subscribed to the Google Groups > "Java Posse" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/javaposse/-/eiZshlECKfEJ. > > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/javaposse?hl=en. -- You received this message because you are subscribed to the Google Groups "Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
