constraints icon indicating copy to clipboard operation
constraints copied to clipboard

Deferrable with default values

Open Icelandjack opened this issue 8 years ago • 1 comments

These might be useful for Data.Constraint.Deferrable

deferWithDefault_ :: forall c. Deferrable c => forall r. r -> (c => r) -> r
deferWithDefault_ def r =
  case deferEither_ @c r of
    Left  err -> def
    Right a   -> a

deferWithDefault :: Deferrable c => proxy c -> r -> (c => r) -> r
deferWithDefault proxy def r =
  case deferEither proxy r of
    Left  err -> def
    Right a   -> a

Icelandjack avatar May 20 '17 15:05 Icelandjack

I have no particular objection to adding these.

ekmett avatar Jun 01 '17 16:06 ekmett