functions 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Yjc3YjRkZDYwYmMzZjZmYmUwMzVjMTVkZGQxYWJkMThlZWEyZWJiMg==
4
+ OTNkN2M4ZGQwZmUwZmJiNGE4Y2U3ZjViMTZlZTEwNDllNDFiMTZmMQ==
5
5
  data.tar.gz: !binary |-
6
- Y2ZmYjg4OGJiNTg1ZmQxY2M1MjMxNmZmMzZjNWE2ODU5NWY1YzljOA==
6
+ ZWEwYmJjNWY2NDVkZDc1NTkwNjZiNzBkY2NmNDc1NGZhMGZlOGNiMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NGRmMWYxMmY1ZTU0OWY1ZTM0ODk5ZmJhNTZkNjQwYmJmNWU3NmExZmViYWM3
10
- NzQxOTYwMzliNTRhMDczNDE5OTRhZmYzYWE0MjhhNjZkODYyOTBiYTlkM2Y3
11
- YzQwMmM2YjkxZTZkMjczNWM5YWVjNGQ0NmM2ODRmZjhiZjgxN2Q=
9
+ ODcyOTczYTFkMDhkN2VlNzg0MWYwOWU5MjhjMjJiMzkwYWEyYTczZGZjMDlm
10
+ ODdiZjhkMTM4MmFiODVmZjc3ZmMwNGVlM2UzYWUxMzBkMTRiMzI5YzJlZTYz
11
+ ZTgyYzViNjIxM2ZlNzdkY2E0M2MzNmEwOTgwYWRhZDQ0OGMxM2I=
12
12
  data.tar.gz: !binary |-
13
- MDNmNDYxZDRlMDMzN2ZkM2U0ODY3MTkyZGMzN2JhMDAyMzA0ZGFkMmJiZWVi
14
- NGRmYzFkZGY3OWI1ZjAzZjJiZDk0NmQ2M2JkZDI1ZjRjNWQyM2U4YTdmOGZj
15
- ZjM5Nzg2NzlhZTVlYTNlMTMzOGFjYThjZTdkYzRkMTcxNmZiNDQ=
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
@@ -1,3 +1,3 @@
1
1
  module Functions
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: functions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koen Handekyn