I find using Result very neat for modeling AND logic, but what about if I need to branch my logic and provide two different Ok results depending on OR logic?
That should be no problem either, instead of returning Result's you can use values, example:
Ok('some value').map(x=>x.length>4?'long':'short')// .map() will stay an 'Ok'.map(x=>x.toUpperCase()).chain(x=>x==='LONG'?Err('too long'):Ok(x))// switch to Err branch if you want.cata(...)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I find using Result very neat for modeling AND logic, but what about if I need to branch my logic and provide two different Ok results depending on OR logic?
That should be no problem either, instead of returning Result's you can use values, example: