DEV Community

Nick Ciolpan for Graffino

Posted on

Boolean flip helper for Elm

There is no such thing as !True to get a False value in Elm.

Here's how I do it.

module Helpers.Bool exposing (flip)

flip: Bool -> Bool
flip bool = 
    if bool == True then
    False
  else
    True

And then:

import Helpers.Bool

...

Helpers.Bool.flip True

For more: Today I Learned

Top comments (2)

Collapse
 
michaeljones profile image
Michael Jones • Edited

This is a super understandable approach to take and good job for sharing it for other people that are trying to get used to Elm.

I think Elm has a built in function in the Basics module which is automatically available called not which does this flipping. It would be more consistent with other languages of it used "!" instead but operators in Elm are expected to be binary so they opted to used a function instead.

As it is a function you can include it more easily in pipelines that use "|>" and you can combine it with other functions using ">>".

Collapse
 
markewers profile image
Mark Ewers

There is also a not function in Elm core
package.elm-lang.org/packages/elm/...