Mercurial > repos > tabletprog
diff modules/list.tp @ 309:ed908b7fcec6
Add find method to list
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 01 Aug 2014 18:55:01 -0700 |
parents | bb4723fec05e |
children | dfd204c82849 |
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"