Mercurial > repos > tabletprog
changeset 309:ed908b7fcec6
Add find method to list
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 01 Aug 2014 18:55:01 -0700 |
parents | 647f7a2d253b |
children | 2308336790d4 |
files | modules/list.tp |
diffstat | 1 files changed, 10 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/modules/list.tp Thu Jul 24 23:55:59 2014 -0700 +++ b/modules/list.tp Fri Aug 01 18:55:01 2014 -0700 @@ -12,6 +12,7 @@ reverse <- { self } join <- { "" } contains? <- :val { false } + find <- :pred { option none } string <- { "[]" } print <- { print: string } jsonEncode <- { "[]" } @@ -72,6 +73,15 @@ _tail contains?: val } } + + find <- :pred { + if: (pred: _val) { + option value: _val + } else: { + _tail find: pred + } + } + string <- { (fold: "[\n" with: :acc el { acc . " " . (string: el) . "\n"