Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this duckmap blocking?

Tags:

raku

I'm trying to list all files in a directory with this function:

sub list-directory($dir = '.') {
    my @todo = $dir.IO.dir;
    @todo = @todo.duckmap( -> $_ where $_.d { @todo.push($_.IO.dir); } );
    @todo = @todo.duckmap( -> $_ where IO {.Str} );
    return @todo;
}

The first duckmap is to list all subdirectories and the second one (this doesn't finish) is to convert the IO objects to Str.

Anyone knows why the second one isn't stopping?

like image 577
Antonio Gamiz Delgado Avatar asked May 09 '19 06:05

Antonio Gamiz Delgado


1 Answers

As Hakon has said, it was a infinite loop. Here is the code fixed:

sub list-directory($dir = '.') {
    my @todo = $dir.IO.dir;
    @todo = @todo.duckmap( -> $_ where $_.d { @todo.push($_.IO.dir); $_; } );
    grep { !.IO.d }, @todo.List.flat;
    @todo.map({.Str});
}
like image 97
Antonio Gamiz Delgado Avatar answered Nov 11 '22 10:11

Antonio Gamiz Delgado