I know I've had cases where I didn't have a good default `a` but did have an `r` (and I wanted to apply a function to the result if there was a value in the Map anyway).


On mobile; please excuse any tpyos.

On Tue, 9 Jun 2020, 5:49 am Oliver Charles, <ollie@ocharles.org.uk> wrote:
Could you share why you are more enthusiastic about such a function?

On Mon, 8 Jun 2020, at 8:07 PM, David Feuer 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?
_______________________________________________
Libraries mailing list

_______________________________________________
Libraries mailing list
Libraries@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries