lodash like utility/algorithms library for D

aliak something at something.com
Sun Sep 30 22:17:05 UTC 2018


On Saturday, 29 September 2018 at 19:27:29 UTC, Paul Backus wrote:
> On Saturday, 29 September 2018 at 12:40:14 UTC, aliak wrote:
>> I.e. by allowing you to define the unexepcted you could for 
>> instance:
>>
>> enum JSONError {
>>   invalidKey, notString, notNumber
>> }
>>
>> auto a = parse(jsonData);
>>
>> a.getAsString("key").match!(
>>     (string value) => // yay
>>     (JSONError error) => // small domain of what went wrong
>> );
>
> I agree that this is useful, but why not just return a naked 
> `SumType!(string, JSONError)` in that case? Is there some 
> additional value added by the `Expect` wrapper that I'm not 
> seeing?

That's an option as well I guess. But then you'd need to rely on 
convention and you couldn't do SumType!(int, int) f(), and Expect 
also gives you some more purposeful APIs that makes the code's 
intent clear. Plus I'm considering range behavior as well.

Could you also return a union voldermort type then instead of a 
SumType?


More information about the Digitalmars-d-announce mailing list