Mercurial > repos > tabletprog
comparison modules/list.tp @ 308:56deb4a102db
Added filter to list
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 28 Jul 2014 03:29:27 -0700 |
parents | ea94b1e43c97 |
children | dfd204c82849 |
comparison
equal
deleted
inserted
replaced
307:056b8ad76559 | 308:56deb4a102db |
---|---|
2 _empty <- #{ | 2 _empty <- #{ |
3 length <- { 0 } | 3 length <- { 0 } |
4 empty? <- { true } | 4 empty? <- { true } |
5 fold:with <- :acc :fun { acc } | 5 fold:with <- :acc :fun { acc } |
6 foldr:with <- :acc :fun { acc } | 6 foldr:with <- :acc :fun { acc } |
7 filter <- :pred { self } | |
7 foreach <- :self fun { self } | 8 foreach <- :self fun { self } |
8 map <- :fun { self } | 9 map <- :fun { self } |
9 | <- :val { | 10 | <- :val { |
10 list node: val withTail: self | 11 list node: val withTail: self |
11 } | 12 } |
35 } | 36 } |
36 acc | 37 acc |
37 } | 38 } |
38 foldr:with <- :acc fun { | 39 foldr:with <- :acc fun { |
39 fun: (_tail foldr: acc with: fun) _val | 40 fun: (_tail foldr: acc with: fun) _val |
41 } | |
42 filter <- :pred { | |
43 reverse: (fold: [] with: :acc el { | |
44 if: (pred: el) { el | acc } else: { acc } | |
45 }) | |
40 } | 46 } |
41 map <- :fun { | 47 map <- :fun { |
42 node: (fun: _val) withTail: (_tail map: fun) | 48 node: (fun: _val) withTail: (_tail map: fun) |
43 } | 49 } |
44 foreach <- :self fun { | 50 foreach <- :self fun { |