Skip to content

lookupDefault and lookup are curiously lazy #23

@treeowl

Description

@treeowl

Currently,

lookupDefault def cfg name = fromMaybe def <$> lookup cfg name

I'd have expected

lookupDefault def cfg name = maybe (return def) return =<< lookup cfg name

lookup is also a bit weird:

lookup :: Configured a => Config -> Name -> IO (Maybe a)
lookup (Config root BaseConfig{..}) name =
    (join . fmap convert . H.lookup (root `T.append` name)) <$> readIORef cfgMap

There's no obvious reason to delay the lookup to the use site (which keeps the entire HashMap live). Why not use something like this?

lookup (Config root BaseConfig{..}) name =  do
     mp <- readIORef cfgMap
     let result = convert =<< H.lookup (root `T.append` name) mp
     evaluate result
     return result

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions