Skip to content

Instantly share code, notes, and snippets.

@LSLeary
Created July 5, 2023 21:35
Show Gist options
  • Save LSLeary/d26da34d28e9935e71408e40d157bc95 to your computer and use it in GitHub Desktop.
Save LSLeary/d26da34d28e9935e71408e40d157bc95 to your computer and use it in GitHub Desktop.
Fancy if-then-else with triangles!
module Triangles ((<|), (|>)) where
(<|) :: a -> Bool -> Maybe a
a <| True = Just a
_ <| False = Nothing
infix 2 <|
(|>) :: Maybe a -> a -> a
Just a |> _ = a
Nothing |> a = a
infix 1 |>
_green, _blue :: String
_green = "green" <| True |> "blue"
_blue = "green" <| False |> "blue"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment