-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BFS for jq parity and imperative to avoid call stack limit.
- Loading branch information
1 parent
7d662ad
commit 5f34622
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ export module str.nu | |
# commands | ||
export use fs.nu * | ||
export use set-env.nu * | ||
export use recurse.nu * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export def main [ | ||
--filter: closure | ||
]: any -> list<any> { | ||
mut todo = [$in] | ||
mut done = [] | ||
while ($todo | length) > 0 { | ||
# pop | ||
let value = $todo | last | ||
$todo = ($todo | drop) | ||
# save | ||
if $filter == null or ($value | do $filter $value) { | ||
$done ++= [$value] | ||
} | ||
# push | ||
$todo ++= (match ($value | describe --detailed | get type) { | ||
table => ($value | values | flatten) | ||
record => ($value | values) | ||
list => $value | ||
_ => continue | ||
} | reverse) | ||
} | ||
$done | ||
} |