Skip to content

Instantly share code, notes, and snippets.

@wk-j
Forked from Burgestrand/Ternary.hs
Created June 15, 2017 07:59
Show Gist options
  • Save wk-j/367d0c84de796d14418637093be0ad65 to your computer and use it in GitHub Desktop.
Save wk-j/367d0c84de796d14418637093be0ad65 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