Mercurial > repos > tabletprog
diff modules/list.tp @ 311:dfd204c82849
Merge
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 01 Aug 2014 18:56:50 -0700 |
parents | ed908b7fcec6 56deb4a102db |
children | eef8a5cea812 |
line wrap: on
line diff
--- a/modules/list.tp Fri Aug 01 18:56:39 2014 -0700 +++ b/modules/list.tp Fri Aug 01 18:56:50 2014 -0700 @@ -4,6 +4,8 @@ empty? <- { true } fold:with <- :acc :fun { acc } foldr:with <- :acc :fun { acc } + filter <- :pred { self } + foreach <- :self fun { self } map <- :fun { self } | <- :val { list node: val withTail: self @@ -38,6 +40,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) }