sanctuary-js / sanctuary

:see_no_evil: Refuge from unsafe JavaScript
https://sanctuary.js.org
MIT License
3.03k stars 94 forks source link

boolean :: a -> a -> Boolean -> a #577

Closed davidchambers closed 5 years ago

davidchambers commented 6 years ago

We have S.ifElse, but we currently lack straightforward case folding for the Boolean type (S.maybe and S.either provide case folding for Maybe a and Either a b respectively).

I think S.boolean would be a good addition to the library.

> S.boolean ('false') ('true') (false)
'false'

> S.boolean ('false') ('true') (true)
'true'

The one thing I very much dislike about the function is that one must learn that the constructors are essentially defined in false | true order rather than in true | false order. This is arbitrary, and does not match the argument order of S.ifElse. If we decide to add this function we should make it consistent with Haskell's bool, so some confusion is unavoidable.