Skip to content

Instantly share code, notes, and snippets.

@malcolmgreaves
Last active June 29, 2017 00:27
Show Gist options
  • Select an option

  • Save malcolmgreaves/bbfa863f3fe4bb2163d94394d7b60899 to your computer and use it in GitHub Desktop.

Select an option

Save malcolmgreaves/bbfa863f3fe4bb2163d94394d7b60899 to your computer and use it in GitHub Desktop.
Listing all files from a given directory using functional programming.
from functools import partial
from operator import concat
from os.path import isfile
from fold import foldl
def _list_files_from(part, prev):
current = "%s/%s" % (prev, part)
if isfile(current):
return [current]
else:
ls = partial(_list_files_from, prev=current)
return foldl([], concat, map(ls, listdir(current)))
def list_files_from(start):
return _list_files_from(start, ".")
@malcolmgreaves
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment