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

eitherMatch' :: forall b. Match (Either String b) -> Match b #67

Open
safareli opened this issue Mar 26, 2019 · 0 comments
Open

eitherMatch' :: forall b. Match (Either String b) -> Match b #67

safareli opened this issue Mar 26, 2019 · 0 comments

Comments

@safareli
Copy link
Contributor

I find this to be useful:

-- same as eitherMatch but Left must be string which will be used for error
eitherMatch' :: forall b. Match (Either String b) -> Match b
eitherMatch' (Match r2eab) = Match $ \r ->
  ValidationSemiRing.unV ValidationSemiRing.invalid runEither $ (r2eab r)
  where
  runEither (Tuple rs eit) =
    case eit of
      Left err -> ValidationSemiRing.invalid $ free $ Fail err
      Right res -> pure $ Tuple rs res

it can be used to reconstruct current eitherMatch like this:

eitherMatch :: forall a b. Match (Either a b) -> Match b
eitherMatch = lmap (const "Nested check failed") >>> eitherMatch'

what you think of adding eitherMatch' or even changing eitherMatch to be eitherMatch'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant