feat: probing helper functions

This commit is contained in:
Leonardo de Moura 2022-10-15 08:33:15 -07:00
parent 48b6fee467
commit 3505b60a22
2 changed files with 18 additions and 0 deletions

View file

@ -127,6 +127,9 @@ def toString [ToString α] : Probe α String :=
@[inline]
def count : Probe α Nat := fun data => return #[data.size]
@[inline]
def sum : Probe Nat Nat := fun data => return #[data.foldl (init := 0) (·+·)]
def runOnModule (moduleName : Name) (probe : Probe Decl β) (phase : Phase := Phase.base): CoreM (Array β) := do
let ext := getExt phase
let env ← getEnv

View file

@ -142,6 +142,21 @@ def isNum : Name → Bool
| num .. => true
| _ => false
/--
Return `true` if `n` contains a string part `s` that satifies `f`.
Examples:
```
#eval (`foo.bla).anyS (·.startsWith "fo") -- true
#eval (`foo.bla).anyS (·.startsWith "boo") -- false
```
-/
def anyS (n : Name) (f : String → Bool) : Bool :=
match n with
| .str p s => f s || p.anyS f
| .num p _ => p.anyS f
| _ => false
end Name
end Lean