const guards =const a b c = 1 3 7const result = `| a > b = 1337| b > c = 999| c > a = 42| c > b = 11`console // 42
Please note that, like in Haskell, the first truthy guard will be returned.
Guards can also be inlined:
`a < b = 'yep' | b > c = 'nope' | c > a = 'maybe'`
And they support all comparison operators
< <= == === !== != >= > and the logical operators too
&& || !.
In Haskell, the
otherwise keyword is used as a catch-all. To avoid using this keyword as variable name, this logic is not implemented in the module, you can simply emulate the same behaviour by using
const a b c = 1 2 3const result = `| a > b = 'nope'| b > c = 'nope'| c < a = 'nope'| true = 'yep'`console // 'yep'
Released under the MIT license by Davy Duperron.