PhysLean/HepLean/Meta/AllFilePaths.lean

31 lines
899 B
Text
Raw Normal View History

2024-09-04 08:20:10 -04:00
/-
Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved.
Released under Apache 2.0 license.
Authors: Joseph Tooby-Smith
-/
2025-01-22 10:32:39 +00:00
import HepLean.Meta.TODO.Basic
2024-09-04 08:20:10 -04:00
/-!
## Getting an array of all file paths in HepLean.
-/
open System
2024-09-04 08:20:10 -04:00
TODO "Make this definition more functional in style. In other words, remove the for loop."
2024-09-04 08:20:10 -04:00
2024-09-04 08:33:00 -04:00
/-- The recursive function underlying `allFilePaths`. -/
partial def allFilePaths.go (prev : Array FilePath)
2025-01-05 16:00:30 +00:00
(root : String) (path : FilePath) : IO (Array FilePath) := do
2024-09-04 08:20:10 -04:00
let mut r := prev
for entry in ← path.readDir do
if ← entry.path.isDir then
2025-01-05 16:00:30 +00:00
r ← go r (root ++ "/" ++ entry.fileName) entry.path
2024-09-04 08:20:10 -04:00
else
2025-01-05 16:00:30 +00:00
r := r.push (root ++ "/" ++ entry.fileName)
2024-09-04 08:20:10 -04:00
pure r
2024-09-04 08:33:00 -04:00
/-- Gets an array of all file paths in `HepLean`. -/
partial def allFilePaths : IO (Array FilePath) := do
2025-01-05 16:00:30 +00:00
allFilePaths.go (#[] : Array FilePath) "./HepLean" ("./HepLean" : FilePath)