wareismymind / Secundatives

MIT License
3 stars 2 forks source link

Task overloads for UnwrapOr #43

Closed Insomniak47 closed 3 years ago

Insomniak47 commented 4 years ago

Currently UnwrapOr only works on Maybe which is nice but it would be great to have it handle Task<Maybe> as well. This would make things a bit easier overall for fluently chaining together Maybes/Results

This would allow us to do things like:

var value = await _myThing.ReturnsAMaybe()
    .Map(x => DoSomething(x))
    .UnwrapOr(x => new Whatever);

//Right now this ^ looks like

var thing = await _myThing.ReturnsAMaybe()
    .Map(x => DoSomething(x));

var value = _myThing.UnwrapOr(x => new Whatever());

//or 

var value = (await _myThing.ReturnsAMaybe()
//          ^ Yikes
    .Map(x => DoSomething(x))) 
    .UnwrapOr(x => new Whatever());