Here are examples: def has_access? do at_least_logged_in? and !!get_csrf_cookie(session) end
%{event_form | submitted: !!event_form.submitted_at} case !!(membership_ends_on || trial_ends_on || dues_exempt) do true -> changeset false -> add_error(changeset, :membership_ends_on, "is required") end case !!previous_value and !!new_value do true -> put_change(changeset, :unconfirmed_email, new_value) false -> changeset end submitted? = !!Ecto.Changeset.get_change(changeset, :submitted_at) %{rsvpd: !!participation.rsvpd} On Tue, Dec 22, 2020 at 11:48 PM José Valim <jose.va...@dashbit.co> wrote: > Can we revisit in which scenarios an explicit boolean conversion is > necessary? > > On Wed, Dec 23, 2020 at 1:21 AM Moxley Stratton <moxley.strat...@gmail.com> > wrote: > >> I would like revisit this issue. >> >> The issue was last discussed 5 years ago. Much has changed in that time. >> The given solution was to use a double-negative (!!) to convert a given >> value to a pure boolean. >> >> Here are the problems with the suggested solution: >> 1. I believe this solution is a hack that is not intuitive to beginners. >> It's rarely seen by mid and senior developers, meaning they have to pause >> to interpret what !! means. >> 2. A double negative can't be part of an Elixir pipeline. >> 3. The Credo package warns about double negatives: "Double boolean >> negation found". Linters in other languages have a similar warning. Other >> languages have a built-in function (JavaScript has Boolean()) to convert to >> boolean. >> 4. The alternative to double-negative is verbose: "if expr, do: true, >> else: false", or the less readable "expr && true || false" >> >> I would be happy to submit a PR to add Kernel.to_boolean/1. >> >> On Sunday, November 1, 2015 at 5:48:28 AM UTC-8 José Valim wrote: >> >>> Not necessarily , but the ones in Kernel are. :) >>> >>> -- >>> >>> >>> *José Valim* >>> www.plataformatec.com.br >>> Skype: jv.ptec >>> Founder and Director of R&D >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "elixir-lang-core" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to elixir-lang-core+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/elixir-lang-core/45dc9a7b-1657-4d02-933b-fe8fe182c2bcn%40googlegroups.com >> <https://groups.google.com/d/msgid/elixir-lang-core/45dc9a7b-1657-4d02-933b-fe8fe182c2bcn%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- > You received this message because you are subscribed to a topic in the > Google Groups "elixir-lang-core" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/elixir-lang-core/KKqjMbXoIJA/unsubscribe > . > To unsubscribe from this group and all its topics, send an email to > elixir-lang-core+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2B7iTRj%3Do62adGM%3DspKxnscAT1QoVC-0uqLDS_YPcDGAA%40mail.gmail.com > <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2B7iTRj%3Do62adGM%3DspKxnscAT1QoVC-0uqLDS_YPcDGAA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAFJDP5fJWCVCU41R0CQWx-q6RD1ENUtw92bcpSunf6SBNfQtsg%40mail.gmail.com.