Lean4
/-- Retrieve all names in the environment satisfying a predicate,
gathered together into a `HashMap` according to the module they are defined in.
-/
def allNamesByModule (p : Name → Bool) : CoreM (Std.HashMap Name (Array Name)) := do
(← getEnv).constants.foldM (init := ∅) fun names n _ => do
if p n && !(← isBlackListed n) then
let some m ← findModuleOf? n |
return names
match names[m]? with
| some others =>
return names.insert m (others.push n)
| none =>
return names.insert m #[n]
else
return names