1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
describe "backcall", ->
it "should support basic backcall with <-", ->
results = {}
mock_map = (list, fn) ->
for item in *list
table.insert results, fn(item)
do
(x) <- mock_map {1, 2, 3}
x * 2
assert.same results, {2, 4, 6}
it "should support nested backcalls", ->
results = {}
mock_map = (list, fn) ->
for item in *list
fn(item)
mock_map {1, 2, 3, 4}, (x) ->
if x > 2
table.insert results, x
assert.same results, {3, 4}
it "should work with method call backcall", ->
results = {}
obj = {
process: (self, fn) ->
fn 42
}
(value) <- obj\process
table.insert results, value
assert.same results, {42}
|