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

Add to Parser functions orElse() & orElseEither() #23

Merged
merged 3 commits into from
Jan 7, 2024

Conversation

routis
Copy link

@routis routis commented Jan 5, 2024

This PR adds two new ways of combining two parsers.

Parser.orElse(other)

This function combines two parsers by trying the first one and if it fails trying the other. This function allows the combination of individual parsers for each member of a sealed hierarchy, thus producing a parser for a sum type.

Parser.orElseEither(other)

This is combines two parsers like Parser.orElse() but contrary to the orElse() case the two parser can produce unrelated outputs. Effectively, allows the combination of an two unrelated parsers (outcome wise) with an OR relationship.

@sksamuel
Copy link
Owner

sksamuel commented Jan 7, 2024

Great thanks.

@sksamuel sksamuel merged commit 2d7ef6e into sksamuel:master Jan 7, 2024
1 check passed
samporapeli pushed a commit to samporapeli/tribune that referenced this pull request Jan 29, 2024
Add to `Parser` functions `orElse()` & `orElseEither()`
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

Successfully merging this pull request may close these issues.

2 participants