• CanadaPlus@lemmy.sdf.org
    link
    fedilink
    arrow-up
    14
    ·
    edit-2
    1 month ago

    That honestly seems like the best way to write conditionalBaptize but I still hate it. Probably because IRL you’d just rewrite baptism instead of retrofitting the function with a clever use of id.

    • expr@programming.dev
      link
      fedilink
      arrow-up
      4
      ·
      edit-2
      1 month ago

      It looks pretty normal to me as a professional Haskeller, though I suppose it’s perhaps slightly cleaner to write it as conditionalBaptize p = fromMaybe p $ baptize p. It’s largely just a matter of taste and I’d accept either version when reviewing an MR.

      Edit: I just thought of another version that actually is far too clever and shouldn’t be used:

      conditionalBaptize = ap fromMaybe baptize, making use of the monad instance for ->. But yeah, don’t do this.