funkify 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1509b7e4e421ff184a3ddebf8bae52b54063883
4
- data.tar.gz: 30e1768e67a4a65de187b0035050c795fa572e61
3
+ metadata.gz: 45022580a84d3526daa607b98036af6b25a5866c
4
+ data.tar.gz: b16a211aebf621fa75120b2936fb286c7b5a231e
5
5
  SHA512:
6
- metadata.gz: d0ba7e0c32a65562b351b001264506ed55c13980382c25169dd76839cc23feb8138df7715aaf0cc9b8e000fe3cb56277bbc6684a3f2674f9e0263bf121594d58
7
- data.tar.gz: e22735ce17f3f5e11ef60952c176d9d07ce1cb71f99370043035c0314e9998af8ba6b31ebf0e7f55760651713cba23dac33986947addedd82e1c05e77cd518c1
6
+ metadata.gz: 7e8d44488265a956d845f8ce1a701ab1f09f0922494feb4f8cbc5945aa76c5b258b14e551be2ee28cf380c65166958221cf7ec6b03961d88cbad0ba6f8d1d194
7
+ data.tar.gz: 98937ae54c307757bd8d9720183bccb4f62795d751f0d10d80e52ca527c564d610d45757343211e741cce3d3699ca88713df29b7f338126a15865ec15454980f
data/README.md CHANGED
@@ -2,17 +2,22 @@
2
2
 
3
3
  _Haskell-style partial application and composition for Ruby methods_
4
4
 
5
- "In computer science, partial application refers to the process of
6
- fixing a number of arguments to a function, producing another function of smaller arity."
7
- --[Wikipedia](http://en.wikipedia.org/wiki/Partial_application)
5
+ Function composition when used in conjunction with partial application can yield exceptionally concise code, often more concise than the idiomatic Ruby counterpart. Check out the links
6
+ below for further explanations of these features and examples of their use in Haskell:
8
7
 
9
- [Curring in Haskell](http://www.haskell.org/haskellwiki/Currying)<br>
10
8
  [Partial application in Haskell](http://www.haskell.org/haskellwiki/Partial_application)<br>
11
- [Function composition in Haskell](http://www.haskell.org/haskellwiki/Function_composition)
9
+ [Function composition in Haskell](http://www.haskell.org/haskellwiki/Function_composition)<br>
10
+ [Curring in Haskell](http://www.haskell.org/haskellwiki/Currying)
12
11
 
12
+ Also, watch [this video](http://www.youtube.com/watch?v=m3svKOdZijA) to learn about some of the cool things you can do with
13
+ function composition and partial application (the video is in Javascript but the ideas still apply to Ruby with Funkify)
13
14
 
14
15
  ## Usage
15
16
 
17
+ ### Autocurrying
18
+
19
+ In order for a Ruby method to be amenable to partial application and composition it must first be autocurried:
20
+
16
21
  ```ruby
17
22
  class MyFunkyClass
18
23
  include Funkify
@@ -48,12 +53,12 @@ funky = MyFunkyClass.new
48
53
 
49
54
  funky.add(1, 2) #=> This works normally and returns 3
50
55
  add_1 = funky.add(1) #=> The `1` is partially applied and a `Proc` is returned
51
- add_1.(2) #=> We invoke that `Proc` with the remaining argument and the final result (`3`) is returned.
56
+ add_1.(2) #=> 3 (We invoke that `Proc` with the remaining argument)
52
57
  ```
53
58
 
54
59
  ### Function composition
55
60
 
56
- We compose methods using the `*` and `|` operators.
61
+ We compose methods using the `*` and `|` operators.
57
62
 
58
63
  `*` composes right to left, this is the standard way to compose functions found in languages like Haskell:
59
64
  ```ruby
@@ -68,9 +73,9 @@ We compose methods using the `*` and `|` operators.
68
73
  (mult(5) | add(1) | negate).(3) #=> -16
69
74
  ```
70
75
 
71
- As a cute bonus, we can inject values from the left into a pipeline with the `pass` method ([see more](http://showterm.io/47f46234281cf2c25f44a#fast)):
76
+ As a cute bonus, we can inject values from the left into a pipeline with the `pass` method together with the `>=` (pipeline operator) (([see more](http://showterm.io/47f46234281cf2c25f44a#fast)):
72
77
  ```ruby
73
- pass(3) | (mult(5) | add(1) | negate) #=> -16
78
+ pass(3) >= mult(5) | add(1) | negate #=> -16
74
79
  ```
75
80
 
76
81
  #### Other examples:
@@ -84,7 +89,7 @@ Add 10 to every item in an Enumerable:
84
89
  Multiply by 10 and negate every item in an Enumerable:
85
90
 
86
91
  ```ruby
87
- (1..5).map &(funky.negate * funky.mult(10)) => [-10, -20, -30, -40, -50]
92
+ (1..5).map &(funky.negate * funky.mult(10)) #=> [-10, -20, -30, -40, -50]
88
93
  ```
89
94
 
90
95
  ## Installation
@@ -100,7 +105,7 @@ And then execute:
100
105
  Or install it yourself as:
101
106
 
102
107
  $ gem install funkify
103
-
108
+
104
109
  ## Dedication
105
110
 
106
111
  This library was inspired in part by stimulating conversations with [epitron](https://github.com/epitron) on Freenode.
@@ -11,11 +11,11 @@ module Funkify
11
11
  end
12
12
 
13
13
  def |(other)
14
- if arity.zero?
15
- other.(*self.())
16
- else
17
- Funkify.compose(other, self)
18
- end
14
+ Funkify.compose(other, self)
15
+ end
16
+
17
+ def >=(other)
18
+ other.(*self.())
19
19
  end
20
20
  end
21
21
 
@@ -1,3 +1,3 @@
1
1
  module Funkify
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -143,11 +143,11 @@ describe Funkify do
143
143
 
144
144
  describe "pass method" do
145
145
  it 'passes values into a reverse-composition stream' do
146
- (@c.pass(5) | ( @c.add(5) | @c.mult(5))).should == 50
146
+ (@c.pass(5) >= @c.add(5) | @c.mult(5)).should == 50
147
147
  end
148
148
 
149
149
  it 'passes values into a normal-composition stream' do
150
- (@c.pass(5) | ( @c.add(5) * @c.mult(5))).should == 30
150
+ (@c.pass(5) >= @c.add(5) * @c.mult(5)).should == 30
151
151
  end
152
152
  end
153
153
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: funkify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mair