parent
fd31e8ff6f
commit
de7f2372be
1 changed files with 7 additions and 0 deletions
|
|
@ -809,10 +809,17 @@ template foldl*(sequence, operation: untyped): untyped =
|
||||||
multiplication = foldl(numbers, a * b)
|
multiplication = foldl(numbers, a * b)
|
||||||
words = @["nim", "is", "cool"]
|
words = @["nim", "is", "cool"]
|
||||||
concatenation = foldl(words, a & b)
|
concatenation = foldl(words, a & b)
|
||||||
|
procs = @["proc", "Is", "Also", "Fine"]
|
||||||
|
|
||||||
|
|
||||||
|
proc foo(acc, cur: string): string =
|
||||||
|
result = acc & cur
|
||||||
|
|
||||||
assert addition == 25, "Addition is (((5)+9)+11)"
|
assert addition == 25, "Addition is (((5)+9)+11)"
|
||||||
assert subtraction == -15, "Subtraction is (((5)-9)-11)"
|
assert subtraction == -15, "Subtraction is (((5)-9)-11)"
|
||||||
assert multiplication == 495, "Multiplication is (((5)*9)*11)"
|
assert multiplication == 495, "Multiplication is (((5)*9)*11)"
|
||||||
assert concatenation == "nimiscool"
|
assert concatenation == "nimiscool"
|
||||||
|
assert foldl(procs, foo(a, b)) == "procIsAlsoFine"
|
||||||
|
|
||||||
let s = sequence
|
let s = sequence
|
||||||
assert s.len > 0, "Can't fold empty sequences"
|
assert s.len > 0, "Can't fold empty sequences"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue