Skip to content

Instantly share code, notes, and snippets.

@Burgestrand
Created October 26, 2009 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Burgestrand/218987 to your computer and use it in GitHub Desktop.
Save Burgestrand/218987 to your computer and use it in GitHub Desktop.
Ternary operator for haskell
module Ternary where
-- | Ternary operator.
-- Usage: (i > 0) ? i $ 1
(?) :: Bool -> a -> a -> a
True ? x = const x
False ? _ = id
-- | Higher order ternary operator.
-- Usage: (not . null) ?? "" $ "default"
(??) :: (a -> Bool) -> a -> a -> a
f ?? x = f x ? x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment