Mercurial > repos > tabletprog
changeset 308:56deb4a102db
Added filter to list
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 28 Jul 2014 03:29:27 -0700 |
parents | 056b8ad76559 |
children | dfd204c82849 |
files | modules/list.tp |
diffstat | 1 files changed, 6 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/modules/list.tp Sun Jul 27 13:21:38 2014 -0700 +++ b/modules/list.tp Mon Jul 28 03:29:27 2014 -0700 @@ -4,6 +4,7 @@ empty? <- { true } fold:with <- :acc :fun { acc } foldr:with <- :acc :fun { acc } + filter <- :pred { self } foreach <- :self fun { self } map <- :fun { self } | <- :val { @@ -38,6 +39,11 @@ foldr:with <- :acc fun { fun: (_tail foldr: acc with: fun) _val } + filter <- :pred { + reverse: (fold: [] with: :acc el { + if: (pred: el) { el | acc } else: { acc } + }) + } map <- :fun { node: (fun: _val) withTail: (_tail map: fun) }