functions 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/functions/prelude_lambda/basic.rb +12 -1
- data/lib/functions/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTNkN2M4ZGQwZmUwZmJiNGE4Y2U3ZjViMTZlZTEwNDllNDFiMTZmMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZWEwYmJjNWY2NDVkZDc1NTkwNjZiNzBkY2NmNDc1NGZhMGZlOGNiMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODcyOTczYTFkMDhkN2VlNzg0MWYwOWU5MjhjMjJiMzkwYWEyYTczZGZjMDlm
|
10
|
+
ODdiZjhkMTM4MmFiODVmZjc3ZmMwNGVlM2UzYWUxMzBkMTRiMzI5YzJlZTYz
|
11
|
+
ZTgyYzViNjIxM2ZlNzdkY2E0M2MzNmEwOTgwYWRhZDQ0OGMxM2I=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmJlMGVlMDlmMDU1MTgwMmYwMTAzMWNjNDA4ODYwYWYzYmU3MDQ3ODVjMDI4
|
14
|
+
YzFlYjNjZTEyNzllMzA4M2U3ZmI0M2QyYjZjMWUzM2ExOWUzY2Y1NDNkNjNk
|
15
|
+
ZjJmMTQwMzFiMzZmNmMxMTQ1OTY3N2VjYzM5MzdkYzRiNGQ1MTI=
|
@@ -71,7 +71,6 @@ module Functions
|
|
71
71
|
# Returns the length
|
72
72
|
Length = Send.(:length)
|
73
73
|
|
74
|
-
#
|
75
74
|
Foldl = ->(f, i, a) { a.inject(i) { |r, x| f.(r, x) } }.curry
|
76
75
|
|
77
76
|
ReduceLeft = ->(f, a) { a.inject { |r, x| f.(r, x) } }.curry
|
@@ -84,6 +83,8 @@ module Functions
|
|
84
83
|
|
85
84
|
Map = ->(f, a) { a.map { |x| f.(x) } }.curry
|
86
85
|
|
86
|
+
Map_Hash = ->(f, h) { Hash[h.map{|k, v| [k, f.(v)] }] }.curry
|
87
|
+
|
87
88
|
Filter = ->(f, xs) { xs.select { |x| f.(x) } }.curry
|
88
89
|
|
89
90
|
Parallel = ->(f, g, x) { [f.(x), g.(x)] }.curry
|
@@ -92,10 +93,20 @@ module Functions
|
|
92
93
|
|
93
94
|
Intersect = ->(as) { as.inject(:&) }
|
94
95
|
|
96
|
+
Group_By = ->(f,a) { a.group_by(&f) }.curry # functional friend
|
97
|
+
|
98
|
+
Partition_By = ->(f) { Group_By.(f) >= Send.(:values) } # functional friend
|
99
|
+
|
95
100
|
FromTo = ->(from) { ->(to) { Range.new(from, to) } }
|
96
101
|
|
97
102
|
FromOneTo = FromTo.(1)
|
98
103
|
|
104
|
+
Count_By = ->(f,a) { a.inject( Hash.new(0) ) { |h,e| h[f.(e)] += 1; h } }.curry
|
105
|
+
# count_by = ->(f) { group_by.( f ) >= map_hash.( send.(:length) ) }
|
106
|
+
|
107
|
+
Count = ->(a) { a.inject( Hash.new(0) ) { |h,e| h[e] += 1; h } } # probably a bit faster
|
108
|
+
# count = count_by.(identity) # alternative definition (generic)
|
109
|
+
|
99
110
|
end
|
100
111
|
|
101
112
|
end
|
data/lib/functions/version.rb
CHANGED