Skip to content

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

Open
@safareli

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'

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