"Elvis" operator (?:) as a reverse infix form of "fromMaybe"

Nikita Volkov nikita.y.volkov at gmail.com
Sat Oct 12 12:40:05 UTC 2013

I suggest to include this operator in "Data.Maybe" and "Prelude".


    (?:) :: Maybe a -> a -> a
    maybeA ?: b = fromMaybe b maybeA

*Use cases:*

        maybeValue ?: error "Value is unexpectedly empty. This is a bug."

    instead of

        fromMaybe (error "Value is unexpectedly empty. This is a bug.")

        maybeA ?: maybeB ?: c

    instead of

        fromMaybe (fromMaybe c maybeB) maybeA

*Name collisions:*

    Hayoo search gives only 6 collisions with 5 hardly fundamental

* The nickname and the operator itself are inspired by the ones from Groovy

** The symbols of the operator are a reminder of plain old ternary

*** To understand the nickname look at the operator as on emoticon.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20131012/2b49a834/attachment.html>

More information about the Libraries mailing list