Skip to content

Commit

Permalink
Replace append with gather
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Masak committed Sep 16, 2019
1 parent a30b45b commit 7f3d9c7
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions ven-walker/walker.alma
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,29 @@ func walkAtType(walkers, rootType) {
}
}

# XXX maybe we need `append` in Alma?
func append(to, from) {
if from {
for from -> x {
to.push(x);
func gather(blockFn) {
my result = [];

blockFn(func (arrayOrNone) {
for arrayOrNone // [] -> e {
result.push(e);
}
}
});

return result;
}

func findAllAttributes(rootType) {
my attrs = [];
return gather(func (take) {
take(atType(attrList, rootType));

append(attrs, atType(attrList, rootType));

if atType(inheritList, rootType) -> parentTypes {
# no breadth-first here since order shouldn't matter...
for parentTypes -> parentType {
append(attrs, findAllAttributes(parentType));
if atType(inheritList, rootType) -> parentTypes {
# no breadth-first here since order shouldn't matter...
for parentTypes -> parentType {
take(findAllAttributes(parentType));
}
}
}

return attrs;
});
}

func walk(root, walkers) {
Expand Down

0 comments on commit 7f3d9c7

Please sign in to comment.