Skip to content

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

Description

@safareli

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'

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions