boostorg / system

Boost.org system module
http://boost.org/libs/system
34 stars 86 forks source link

Add "monadic" operations to result #94

Open pdimov opened 1 year ago

pdimov commented 1 year ago

r & f -> r? f(*r): r.error() r | x -> r? r: x r | f -> r? r: f()

https://godbolt.org/z/YWKKbq859

pdimov commented 1 year ago

More like r | x -> r? *r: x, and similarly r | f -> r? *r: f().

pdimov commented 1 year ago

r &= f; -> if( r ) r = f(*r); r |= x; -> if( !r ) r = x; r |= f; -> if( !r ) r = f();

pdimov commented 10 months ago

Implemented on develop (without |= which is deemed unnecessary.)

In the future, maybe consider error-transforming variants of |, as in

r | f -> r? *r: f( r.error() )

pdimov commented 6 months ago

r |= x should probably be provided for consistency, always with the effective semantics of r = r | x.

It only makes sense for r |= f; where f returns result, but it's probably less surprising to just support all the cases.

pdimov commented 6 months ago

r |= x implemented on develop.