TartanLlama / expected

C++11/14/17 std::expected with functional-style extensions
https://tl.tartanllama.xyz
Creative Commons Zero v1.0 Universal
1.55k stars 135 forks source link

Ussage of the opposite of and_then() #160

Closed badumbatish closed 5 months ago

badumbatish commented 5 months ago

Hi there, thank you for your library. I have a question about the library.

If I want to continue the chain of the function call in case the first one doesn't succeed, how should i do it?

For example, i have a bunch of function that takes in a type A and spits out tl::expected<A, std::string>

Is there a way to do

XYZ.and_then(function_A).or(function_B).or(function_C) ? in case that if function A doesn't succeed, I want function B to be executed and if function B doesn't succeed, i want function C to be executed and etc etc

Edit: i think this is a bit weird why I would want this. Ill close the issue now.