Skip to content

Instantly share code, notes, and snippets.

@zzamboni
Last active March 20, 2018 21:33
Show Gist options
  • Save zzamboni/9c94ce4bb1fdf4f8019d8119de92e46e to your computer and use it in GitHub Desktop.
Save zzamboni/9c94ce4bb1fdf4f8019d8119de92e46e to your computer and use it in GitHub Desktop.
`run-parallel` with slices in Elvish
files = [ "file-"(range 100) ]
fn slice-indices [num inc]{
range $num &step=$inc | each [x]{ put $x':'(+ $x $inc) }
}
fn slices [list inc]{
put $list[(slice-indices (count $list) $inc)]
}
slices $files 5 | each [slice]{
put [
(each [f]{
put { echo "Processing "$f; sleep (randint 0 4) }
} $slice)
]
} | each [fnslice]{ run-parallel $@fnslice }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment