Last active
June 29, 2017 00:27
-
-
Save malcolmgreaves/bbfa863f3fe4bb2163d94394d7b60899 to your computer and use it in GitHub Desktop.
Listing all files from a given directory using functional programming.
This file contains hidden or 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
| 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, ".") |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uses
foldmodule here: https://gist.github.com/malcolmgreaves/b02010db05645b667cae1231832bfa39