Discussion: lookups in maps
Keith
keith.wygant at gmail.com
Tue Jun 9 12:02:01 UTC 2020
I usually end up writing your 'lurkup' when I use maps, so I'd like see it included.
I don't have a better name than 'lookupWith'.
And, yeah, lookupDefault has not been useful in practice.
—
Sent from my phone with K-9 Mail.
On June 8, 2020 7:07:13 PM UTC, David Feuer <david.feuer at gmail.com> wrote:
>Discussion has gotten going again about harmonizing between the names
>findWithDefault and lookupDefault in containers and unordered-containers:
>
> findWithDefault :: Ord k
> => a -> k -> Map k a -> a
> lookupDefault :: (Eq k, Hashable k)
> => a -> k -> HashMap k a -> a
>
>I've been fairly unenthusiastic about adding extra names for this function
>in one package or the other, in large part because I don't like the
>function. I'd much rather have something in the spirit of `either`,
>`maybe`, `bool`, etc.:
>
> lurkup :: Ord k
> => r -> (a -> r) -> k -> Map k a -> r
> lurkup r f k = maybe r f . lookup k
> lookup k = lurkup Nothing Just k
>
>Unfortunately, I haven't been able to come up with a decent name for this
>function. Can anyone help?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20200609/bcb81253/attachment.html>
More information about the Libraries
mailing list