The default value is decided by the caller who is unwrapping the Option, not when the Option is constructed.
I think that's perhaps the point I struggled most with when adopting Option: never use it if you "know" it will never be None, just use the type itself. When I say "know" in inverted commas, I mean, it *could* be null, due to a bug. But if you define such a case to be a bug, then it's a bug. For me that's not the use case of an Option-like thing*. Failing fast, or collecting the problems and continuing, is a different, orthogonal discussion. Regards, Graham * But if I'm at the point where I'm incorrectly foisting my own definition/perspective into the discussion, then that's worse than useless :) On 5 June 2012 22:14, Cédric Beust ♔ <[email protected]> wrote: > On Tue, Jun 5, 2012 at 2:11 PM, Kevin Wright <[email protected]>wrote: > >> Nat Price's solution does offer some nice extra goodies though, >> `otherwise` is very handy for providing default values > > > Providing default values seems to be antithetical to Option, though. > What's the point of creating an Option if you know it will never be None? > > -- > Cédric > > -- 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.
