canal 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b81b65446b6c651771e77fddbaa58e7ba9bbfa5
4
- data.tar.gz: 94be62c8a0023ed5f9b0c7873420b6c091b2f4ce
3
+ metadata.gz: 307ba1a54d39dd5c2ec842cb31f54704eeaf511c
4
+ data.tar.gz: a338c6d5760da25c790bf7d272f2ecaf193a87c9
5
5
  SHA512:
6
- metadata.gz: fc725c6d274e4f80d574b387538e97219f20274be99737f61affbef79f59218ff168e6aa1b2f0fa6ce2873280c22317abd8cc29bd5fd26e71f75088d3724ab37
7
- data.tar.gz: 2a4ca92c1c56c9e9c4db9b3a80e5189ac5292396a2597eb848db13a7be78bf2026cb6d95e2b348eb151d8765f43b689d45acbdc52dcd71a6b4ce39ddd9b5b6db
6
+ metadata.gz: d0e2a8d19f533949fd2660f4361080a9c98e21a2538db9b239f573f16ba19ebf2501ddc3e1fe94e14bc61621f75d4d6968f1d084334e1d34142a03b748cd9007
7
+ data.tar.gz: de6e2c4646544e66da0e4fd7b12c8b537c9aba4a31037cd4737d2cfc9b9c56d6d6e3be3dd1645257418f0b537142a020eec7c0f05688448d498520005e39ac74
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Canal
2
2
 
3
- Partial application of a chain of methods.
3
+ Build functions out of methods.
4
4
 
5
- ## Example
5
+ ## Examples
6
6
 
7
7
  Canal can allow point-free expressions. For example, when using `map`:
8
8
 
@@ -10,12 +10,47 @@ Canal can allow point-free expressions. For example, when using `map`:
10
10
  %w{10010101 11100 10110}.map(&canal.to_i(2).to_s.reverse.to_i.to_s(2))
11
11
  ```
12
12
 
13
+ is equivalent to
14
+
13
15
  ```ruby
14
16
  %w{10010101 11100 10110}.map do |x|
15
17
  x.to_i(2).to_s.reverse.to_i.to_s(2)
16
18
  end
17
19
  ```
18
20
 
21
+ ### Identity
22
+
23
+ An empty canal is the identity function.
24
+
25
+ ```ruby
26
+ [1, 2, 3].map(&canal)
27
+ => [1, 2, 3]
28
+ ```
29
+
30
+ Exemple: Count truthy values.
31
+
32
+ ```ruby
33
+ [true, false, nil, "hey", 4].count(&canal)
34
+ => 3
35
+ ```
36
+
37
+ ### Operators
38
+
39
+ Fetch key in list of hash.
40
+
41
+ ```ruby
42
+ people = [{ name: "Alice" }, { name: "Bob" }]
43
+ people.map(&canal[:name])
44
+ => ["Alice", "Bob"]
45
+ ```
46
+
47
+ Multiply list of number by 2.
48
+
49
+ ```ruby
50
+ (0..5).map(&canal * 2)
51
+ => [0, 2, 4, 6, 8, 10]
52
+ ```
53
+
19
54
  ## Installation
20
55
 
21
56
  Add this line to your application's Gemfile:
data/lib/canal/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Canal
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/canal.rb CHANGED
@@ -18,13 +18,15 @@ module Canal
18
18
  end
19
19
  end
20
20
 
21
- def to_s(*args)
22
- method_missing(:to_s, *args)
23
- end
24
-
25
21
  def to_proc
26
22
  ->(object) { call(object) }
27
23
  end
24
+
25
+ %w{ to_s ! == <=> != === =~ !~ }.each do |method|
26
+ define_method(method) do |*args|
27
+ method_missing(method, *args)
28
+ end
29
+ end
28
30
  end
29
31
  end
30
32
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benoit Cote-Jodoin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-15 00:00:00.000000000 Z
11
+ date: 2015-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler