I support this feature. The arguments for
- a solution that composes well with pipes and - the linters rejecting the most common solution of !! are all particularly good ones. From my perspective, I teach composition with pipes in the core, `with` in the boundary, and I try to have students return a boolean rather than a truthy result as part of good API design. The inability to convert from truthy to boolean has always felt like a missing feature to me. -bt On Wed, Dec 23, 2020 at 10:42 AM Andrea Leopardi <an.leopa...@gmail.com> wrote: > What's the particular advantage of "to_boolean(term)" over "not > is_nil(term)"? That it supports also booleans, which however could be used > directly in predicates? > > Andrea > > On Wed, Dec 23, 2020 at 4:32 PM Moxley Stratton <moxley.strat...@gmail.com> > wrote: > >> 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 >> <https://groups.google.com/d/msgid/elixir-lang-core/CAFJDP5fJWCVCU41R0CQWx-q6RD1ENUtw92bcpSunf6SBNfQtsg%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/CAM9Rf%2BLMgPAwYN8FyEs0t%3DVvmAQzP9gx-VjykT6Q11Dvd%3DsVyA%40mail.gmail.com > <https://groups.google.com/d/msgid/elixir-lang-core/CAM9Rf%2BLMgPAwYN8FyEs0t%3DVvmAQzP9gx-VjykT6Q11Dvd%3DsVyA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- Regards, Bruce Tate CEO <https://bowtie.mailbutler.io/tracking/hit/f8218219-d2a8-4de4-9fef-1cdde6e723f6/c7c97460-016e-45fb-a4ab-0a70318c7b97> Groxio, LLC. 512.799.9366 br...@grox.io grox.io -- 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/CAFXvW-47q8nXAKw%2B8ZH_NHh2booBmEYtDf-dB70GHXPDXnZmXw%40mail.gmail.com.