Loose ends: Optional
Howard Lovatt
howard.lovatt at gmail.com
Mon Jun 3 20:48:01 PDT 2013
Surely the Elvis operator is only an option [pun intended] for collections that don't contain null? Unfortunately streams might.
The current Optional type seems to do too little to be useful, like Guava's (as pointed out by Fugue etc.).
This leaves three choices:
1. You could return a List and/or Set of up to one element, since that can be easily stream processed (previous suggestion), etc.
2. You could return a Stream of zero or one element (also previously suggested).
3. A Scala style Optional class.
Any of the three above would seem preferable to Elvis or Guava Optional to me.
Sent from my iPad
On 04/06/2013, at 12:54 PM, Joe Bowbeer <joe.bowbeer at gmail.com> wrote:
> To be clear: I'm just asking questions because I don't have a well-formed
> opinion.
>
> Without the extra methods, the Java8 Optional is similar to Guava's.
> Fugue's Option is a more Scala-like replacement. There are a few succinct
> arguments in favor of the extra methods, such as those posted by Jed
> Wesley-Smith (Fugue) and Ben Hutchison (
> http://benhutchison.wordpress.com/2012/06/05/a-rant-on-jdroids-and-wilful-ignorance/).
> I would love to hear the Guava designers respond to Ben's charge of
> willful ignorance(!). I'm also wondering if the new methods added in more
> recent versions of Guava are addressing these deficiencies.
>
> But, alas, I haven't had enough experience with Guava's Optional to form an
> opinion and I've had no experience with Fugue. I have had experience with
> Scala's Option and it seems to work pretty well, but we decided earlier to
> opt for a more limited approach.
>
> For at least one of the few use cases cited in favor of the extra methods,
> the Elvis operator produces the most readable results... Is Elvis an
> Option?
>
> Joe
>
>
> On Mon, Jun 3, 2013 at 5:44 PM, Joe Bowbeer <joe.bowbeer at gmail.com> wrote:
>
>> Fugue's Option adds the controversial methods that are missing from
>> Guava's Optional:
>>
>> From bitbucket.org/atlassian/fugue
>>
>> "This library attempts round out some of the deficiencies that a
>> functional programmer finds when using Guava. In particular it provides
>> Option and Either types similar to the Scala library as well as a Pair."
>>
>> The lambda-dev post that Brian referenced in earlier in this thread was
>> written by Jed Wesley-Smith, who has committed most of Fugue's code.
>>
>> --Joe
>>
>>
>> On Mon, Jun 3, 2013 at 5:32 PM, Mike Duigou <mike.duigou at oracle.com>wrote:
>>
>>>
>>> On Jun 3 2013, at 10:03 , Joe Bowbeer wrote:
>>>> Does everyone agree that Fugue's Option is an improvement on Guava's
>>>> Optional?
>>>
>>> How is Fugue's Optional an improvement? I guess I am pretty satisfied
>>> with Brian's proposal for java.util.Optional and would be similarly
>>> satisfied with the Guava Optional. If there are benefits to Fugue or
>>> other's Optional beyond implementation details I would like to understand
>>> what they are believed to be.
>>>
>>> Mike
>>>
>>>
>>
More information about the lambda-libs-spec-observers
mailing list