# HG changeset patch # User Michael Pavone # Date 1406543367 25200 # Node ID 56deb4a102dbd6dff723ee0d62875c0898e36ea2 # Parent 056b8ad76559ab493254a346d6d9e2c59b8345b9 Added filter to list diff -r 056b8ad76559 -r 56deb4a102db modules/list.tp --- 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) }