comparison modules/list.tp @ 215:f3d5068cbd43

Add contains? method to list
author Michael Pavone <pavone@retrodev.com>
date Sat, 21 Dec 2013 12:06:10 -0800
parents 372cbd2cd243
children bb4723fec05e
comparison
equal deleted inserted replaced
214:e01137a97654 215:f3d5068cbd43
9 list node: val withTail: self 9 list node: val withTail: self
10 } 10 }
11 . <- :right { right } 11 . <- :right { right }
12 reverse <- { self } 12 reverse <- { self }
13 join <- { "" } 13 join <- { "" }
14 contains? <- :val { false }
14 string <- { "[]" } 15 string <- { "[]" }
15 print <- { print: string } 16 print <- { print: string }
16 } 17 }
17 #{ 18 #{
18 empty <- { _empty } 19 empty <- { _empty }
61 join <- :sep { 62 join <- :sep {
62 _tail fold: (string: _val) with: :acc el { 63 _tail fold: (string: _val) with: :acc el {
63 acc . sep . el 64 acc . sep . el
64 } 65 }
65 } 66 }
67 contains? <- :val {
68 if: _val = val {
69 true
70 } else: {
71 _tail contains?: val
72 }
73 }
66 string <- { 74 string <- {
67 (fold: "[\n" with: :acc el { 75 (fold: "[\n" with: :acc el {
68 acc . " " . (string: el) . "\n" 76 acc . " " . (string: el) . "\n"
69 }) . "]" 77 }) . "]"
70 } 78 }