Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chain operator for Result (like fp-ts Either.chain) #42

Closed
alexn-s opened this issue Aug 25, 2022 · 2 comments
Closed

chain operator for Result (like fp-ts Either.chain) #42

alexn-s opened this issue Aug 25, 2022 · 2 comments

Comments

@alexn-s
Copy link

alexn-s commented Aug 25, 2022

i wanted to chain multiple Results in a pipe & noticed that there is not a chain operator.

can it be done with something else in this lib or did i miss something?
i am grateful for help

@alexn-s
Copy link
Author

alexn-s commented Aug 25, 2022

perhaps something like this:

const chain =
	<A, B>(s: (input) => R.Result<A, B>) =>
	(last: R.Result<A, B>) => {
		if (R.isOk(last)) {
			return s(last._0);
		} else {
			return last;
		}
	};

@mobily
Copy link
Owner

mobily commented Aug 25, 2022

@alexn-s flatMap is what you're looking for :)

@mobily mobily closed this as completed Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants