comparison modules/list.tp @ 188:7e313849ab41

Add join method to lists
author Mike Pavone <pavone@retrodev.com>
date Mon, 26 Aug 2013 18:21:57 -0700
parents 158444b77c09
children 372cbd2cd243
comparison
equal deleted inserted replaced
187:810edf474f86 188:7e313849ab41
7 map <- :fun { self } 7 map <- :fun { self }
8 | <- :val { 8 | <- :val {
9 list node: val withTail: self 9 list node: val withTail: self
10 } 10 }
11 . <- :right { right } 11 . <- :right { right }
12 join <- { "" }
12 string <- { "[]" } 13 string <- { "[]" }
13 print <- { print: string } 14 print <- { print: string }
14 } 15 }
15 #{ 16 #{
16 empty <- { _empty } 17 empty <- { _empty }
49 . <- :right { 50 . <- :right {
50 foldr: right with: :tail val { 51 foldr: right with: :tail val {
51 node: val withTail: tail 52 node: val withTail: tail
52 } 53 }
53 } 54 }
55 join <- :sep {
56 _tail fold: (string: _val) with: :acc el {
57 acc . sep . el
58 }
59 }
54 string <- { 60 string <- {
55 (fold: "[\n" with: :acc el { 61 (fold: "[\n" with: :acc el {
56 acc . " " . (string: el) . "\n" 62 acc . " " . (string: el) . "\n"
57 }) . "]" 63 }) . "]"
58 } 64 }