-
Notifications
You must be signed in to change notification settings - Fork 0
/
Currying.fold
75 lines (47 loc) · 1.89 KB
/
Currying.fold
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
--
-- Currying
-- http://rosettacode.org/wiki/Currying#Fold
--
-- http://en.wikipedia.org/wiki/Currying
-- https://github.com/JuliaLang/julia/issues/554
-- http://opendylan.org/documentation/library-reference/dylan/alternative-curry-syntax.html
Fold supports natural parameter currying.
--
-- (((curry +) 3) 2) ; =>5
sum x y = x + y
alter_elements = !(map ~ [1, 2, 3])
alter_elements (+ 1)
--> [2, 3, 4]
--> elements_length = \ x -> map length ~1
~1 + ~1
elements_length [[1, 2, 3], [1, 2], [1]]
def visits_duration_by_device(visits_list: [Visits]) -> [Detections]:
durations = lambda V: list(map(lambda v: last(v) - first(v), V))
return map(star(to_argn(durations, n=1)), visits_list)
visits_durations_by_device :: {Device : [Visit]} -> {Device : [Time]}
visits_durations_by_device visits_by_device =
visit_duration = \v -> (last v) - (first v)
map_values (\V -> map visit_duration V) visits_by_device
map_values \(map visit_duration ~) visits_by_device
visits_durations_by_device :: {Device : [Visit]} -> {Device : [Time]} =
map_values (map (\[first, ... , last] -> first - last))
sum = a b -> a + b
map (x -> sum 3 x) [1, 2, 3]
map sum 3 [1, 2, 3]
map (sum 3 ~) [1, 2, 3]
map {sum 3 ~} [1, 2, 3]
function visits_durations_by_device
visits_by_device::{Device: [Visit]} -> {Device: [Time]} = {
visit_duration = \visit => last visit - first visit
map (\visits => map visit_duration visits) visits_by_device
}
function visits_durations_by_device
visits_by_device::{Device: [Visit]} -> {Device: [Time]} =
visit_duration = \visit => last visit - first visit
map (\visits => map visit_duration visits) visits_by_device
end
function visits_durations_by_device
visits_by_device::{Device: [Visit]} -> {Device: [Time]} = {
visit_duration = \visit => last visit - first visit
map (\visits => map visit_duration visits) visits_by_device
}