-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopportunity (copy).rb
40 lines (34 loc) · 962 Bytes
/
opportunity (copy).rb
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
31
32
33
34
35
36
37
38
39
40
# def opportunity
# if yield_1
# @opportunities += 1
# end
# if yield_2
# @performances +=1
# end
# end
#-----------------------------
@opportunities = 0
@performances = 0
def opportunity &b1
method(
def helper b1, &b2
if b1.call
@opportunities += 1
end
if b2.call
@performances += 1
end
end).curry[b1].curry
end
opportunity(){true}[]{true}
p [@opportunities, @performances] #[1, 1]
# opportunity {false}[nil]{true}
# p [@opportunities, @performances] #[1, 2]
# opportunity {false}[nil]{true}
# p [@opportunities, @performances] #[1, 3]
# opportunity {false}[nil]{false}
# p [@opportunities, @performances] #[1, 3]
# opportunity {true}[nil]{false}
# p [@opportunities, @performances] #[2, 3]
# opportunity {true}[nil]{true}
# p [@opportunities, @performances] #[3, 4]