comparison 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
comparison
equal deleted inserted replaced
298:647f7a2d253b 309:ed908b7fcec6
10 } 10 }
11 . <- :right { right } 11 . <- :right { right }
12 reverse <- { self } 12 reverse <- { self }
13 join <- { "" } 13 join <- { "" }
14 contains? <- :val { false } 14 contains? <- :val { false }
15 find <- :pred { option none }
15 string <- { "[]" } 16 string <- { "[]" }
16 print <- { print: string } 17 print <- { print: string }
17 jsonEncode <- { "[]" } 18 jsonEncode <- { "[]" }
18 } 19 }
19 #{ 20 #{
70 true 71 true
71 } else: { 72 } else: {
72 _tail contains?: val 73 _tail contains?: val
73 } 74 }
74 } 75 }
76
77 find <- :pred {
78 if: (pred: _val) {
79 option value: _val
80 } else: {
81 _tail find: pred
82 }
83 }
84
75 string <- { 85 string <- {
76 (fold: "[\n" with: :acc el { 86 (fold: "[\n" with: :acc el {
77 acc . " " . (string: el) . "\n" 87 acc . " " . (string: el) . "\n"
78 }) . "]" 88 }) . "]"
79 } 89 }