iolite 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: f8bdc1d07b8278aae627184301b8ccbdca18c586
4
- data.tar.gz: 7988f1205a24e40ed0a4ab0943d74775464a21c7
3
+ metadata.gz: ca583ddc0ee05346e49ff9e57117ac7d862c5d75
4
+ data.tar.gz: 19e569dcd85a77f321b6b1ecc77c68f83ebdee43
5
5
  SHA512:
6
- metadata.gz: 0c81d0be5cbda84687152fd2c1d58148bea44a1e0049e0a4efd43025786fb8813a9a50f339ec0b4d3e848ec8bb69898fdef8005976ef46d2505119cff0854044
7
- data.tar.gz: 2f94fba7d27a8e0e2e998b5fb8ddfdc1575468cebe04b37051afa70d89db273190581386f861a2b394c1f486b5dc34d81e78cd16e7b29730f56a720c0782cb24
6
+ metadata.gz: 9712e7d1c7a086d1c40caec943080762345e8d0462c50b3fc0d907245a743edc0b4b564cd02bd0a55bbd03a3a9cea5a5b36a2d07efadedd26d33ed43b2ee980a
7
+ data.tar.gz: dccbce505799d82ea4226bcabebe11f5c5c36e10d801273d1f7017fd2e68a179d8bfc6bf3c9c8d2fabee403fcf2c059b37d710d828e6d9e335693bc0745c1612
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Iolite
4
4
 
5
- TODO: Write a gem description
5
+ Lazy block library.
6
6
 
7
7
  ## Installation
8
8
 
@@ -68,3 +68,16 @@ p [{name: :homu}, {name: :mami}].map &arg1[:name]
68
68
  3. Commit your changes (`git commit -am 'Add some feature'`)
69
69
  4. Push to the branch (`git push origin my-new-feature`)
70
70
  5. Create a new Pull Request
71
+
72
+ ## Release note
73
+
74
+ ### v0.0.2
75
+
76
+ * Fix Iolite::Statement module method.
77
+ * Add `iolite/adaptored/proc_with_callable`.
78
+
79
+ ### v0.0.1
80
+
81
+ * Release
82
+
83
+
data/docs/iolite.md CHANGED
@@ -197,6 +197,7 @@ it = Iolite::Lazy.new { |it| it }
197
197
  # => ["mami", "mado"]
198
198
  ```
199
199
 
200
+
200
201
  ## プレースホルダ
201
202
 
202
203
  プレースホルダは任意の引数値に対して遅延評価を行うために使用します。
@@ -235,6 +236,41 @@ arg1.to_s.length.call(:homu)
235
236
  # => [:homu, :mami]
236
237
  ```
237
238
 
239
+ ## Proc と併用して使用する
240
+
241
+ 定義した式の中で `Iolite::Lazy` やプレースホルダ使用すると評価時に `Iolite::Lazy` オブジェクトが遅延評価されます。
242
+ しかし、Proc などを渡した場合には `Iolite::Lazy` のように評価時に処理は行われません。
243
+
244
+ ```ruby
245
+ a = Iolite::Lazy.new { |it| it }
246
+ b = Proc.new { |it| it + it }
247
+
248
+ # Proc は遅延評価されないので 3 + Proc が行われようとしてエラーになる
249
+ p (a + b).call(3)
250
+ # => error: `+': Proc can't be coerced into Fixnum (TypeError)
251
+ ```
252
+
253
+ これは、意図しない副作用を抑えるためにデフォルトでは Proc は遅延評価を行わないようにしているからです。
254
+ Proc も同様に評価して欲しい場合は以下の `require` を追加してモンキーパッチを適用してください。
255
+
256
+ ```ruby
257
+ # モンキーパチを適用させるための require
258
+ require "iolite/adaptored/proc_with_callable"
259
+
260
+ a = Iolite::Lazy.new { |it| it }
261
+ b = Proc.new { |it| it + it }
262
+
263
+ # Proc が遅延評価されるようになるので
264
+ # a.call(3) + b.call(3)
265
+ # と評価される
266
+ (a + b).call(3)
267
+ # => 9
268
+
269
+ # こんな使い方とか
270
+ p (arg1 + :to_s.to_proc.call(arg2)).call("homu", 42)
271
+ # => "homu42"
272
+ ```
273
+
238
274
  ## Object#to_lazy
239
275
 
240
276
  `Object#to_lazy` は自身を遅延評価するオブジェクト(Iolite::Lazy オブジェクト)として返すメソッドです。
@@ -0,0 +1,11 @@
1
+ # リリースノート
2
+
3
+ ## v0.0.2
4
+
5
+ * Iolite::Statement のモジュールメソッドが呼び出せなかった不具合を修正
6
+ * iolite/adaptored/proc_with_callable を追加
7
+
8
+ ## v0.0.1
9
+
10
+ * リリース
11
+
@@ -0,0 +1,78 @@
1
+ # Compare lambda_driver and iolite
2
+ # lambda_driver : http://yuroyoro.github.io/lambda_driver/
3
+ # http://yuroyoro.hatenablog.com/entry/2013/03/27/190640
4
+
5
+ require "iolite"
6
+ require "lambda_driver"
7
+
8
+ include Iolite::Placeholders
9
+ using Iolite::Refinements::ObjectWithToLazy
10
+
11
+
12
+ ###########################################################
13
+ # default
14
+ [:foo, :bar, :baz].map{|s| s.to_s }.map{|s| s.upcase }
15
+ # or
16
+ [:foo, :bar, :baz].map(&:to_s).map(&:upcase)
17
+ # => ["FOO", "BAR", "BAZ"]
18
+
19
+ # lambda_driver
20
+ [:foo, :bar, :baz].map(&:to_s >> :upcase )
21
+
22
+ # iolite
23
+ [:foo, :bar, :baz].map &arg1.to_s.upcase
24
+
25
+
26
+ ###########################################################
27
+ # default
28
+ [:foo, :hoge, :bar, :fuga].select{|s| s.to_s.length > 3}
29
+ # => [:hoge, :fuga]
30
+
31
+ # lambda_driver
32
+ [:foo, :hoge, :bar, :fuga].select(&:to_s >> :length >> 3._(:<))
33
+
34
+ # iolite
35
+ [:foo, :hoge, :bar, :fuga].select &arg1.to_s.length > 3
36
+
37
+
38
+ ###########################################################
39
+ # default
40
+ [:foo, :hoge, :bar, :fuga].select{|s| s.to_s.length > 3}
41
+ # => [:hoge, :fuga]
42
+
43
+ # lambda_driver
44
+ [:foo, :hoge, :bar, :fuga].select(&:to_s >> :length >> 3._(:<))
45
+
46
+ # iolite
47
+ [:foo, :hoge, :bar, :fuga].select &arg1.to_s.length > 3
48
+
49
+
50
+ ###########################################################
51
+ # default
52
+ (1..10).select { |it| it % 2 == 0 }
53
+ # => [2, 4, 6, 8, 10]
54
+
55
+ # lambda_driver
56
+ (1..10).select &(:% * 2) >> (:== * 0)
57
+
58
+ # iolite
59
+ (1..10).select &arg1 % 2 == 0
60
+
61
+
62
+ ###########################################################
63
+ def twice n
64
+ n + n
65
+ end
66
+
67
+ # default
68
+ puts twice(10).to_s.length
69
+
70
+ # lambda_driver
71
+ _.twice >> :to_s >> :length >> _.puts < 10
72
+
73
+ # iolite
74
+ using Iolite::Refinements::ObjectWithToLazy
75
+ to_l.puts(to_l.twice(arg1).to_s.length).call(10)
76
+
77
+
78
+
@@ -0,0 +1,14 @@
1
+ require "iolite"
2
+
3
+ include Iolite::Placeholders
4
+
5
+ # Using Object#to_lazy
6
+ using Iolite::Refinements::ObjectWithToLazy
7
+
8
+ evens = (1..Float::INFINITY).to_lazy # to lazy list
9
+ .first(arg1).select(&arg1 % 2 == 0)
10
+
11
+ p evens.call(10)
12
+ # => [2, 4, 6, 8, 10]
13
+ p evens.call(20)
14
+ # => [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
@@ -0,0 +1,5 @@
1
+ require "iolite/adaptor/callable"
2
+
3
+ class Proc
4
+ include Iolite::Adaptor::Callable
5
+ end
@@ -45,4 +45,6 @@ module Iolite module Statement
45
45
  If.new cond
46
46
  end
47
47
 
48
+ module_function :if_
49
+
48
50
  end end
@@ -8,4 +8,5 @@ module Iolite module Statement
8
8
  end
9
9
  }
10
10
  end
11
+ module_function :if_else
11
12
  end end
@@ -1,3 +1,3 @@
1
1
  module Iolite
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -65,10 +65,14 @@ describe "Iolite Adaptored" do
65
65
  expect(proc { |a, b| a - b }.bind(2, arg1).call(1)).to eq(1)
66
66
  end
67
67
  end
68
+ describe "Symbol" do
69
+ it "#to_proc" do
70
+ expect((arg1.to_s + :to_s.to_proc).call(42)).to eq("4242")
71
+ end
72
+ end
68
73
  end
69
74
 
70
75
  describe "String" do
71
- include Iolite::Placeholders
72
76
  it "call" do
73
77
  expect("value:#{arg1}:#{arg2}".call(1, 2)).to eq("value:1:2")
74
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iolite
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
  - manga_osyo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-03 00:00:00.000000000 Z
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,9 +67,12 @@ files:
67
67
  - README.md
68
68
  - Rakefile
69
69
  - docs/iolite.md
70
+ - docs/release_note.md
70
71
  - example/array.rb
72
+ - example/compare_lambda_driver.rb
71
73
  - example/fizzbuzz.rb
72
74
  - example/hash.rb
75
+ - example/lazy_list.rb
73
76
  - example/minimal_implement.rb
74
77
  - example/simple.rb
75
78
  - example/to_lazy.rb
@@ -91,6 +94,7 @@ files:
91
94
  - lib/iolite/adaptored/iolite_lazy_with_hash.rb
92
95
  - lib/iolite/adaptored/object_with_to_lazy.rb
93
96
  - lib/iolite/adaptored/proc.rb
97
+ - lib/iolite/adaptored/proc_with_callable.rb
94
98
  - lib/iolite/adaptored/string.rb
95
99
  - lib/iolite/functinal.rb
96
100
  - lib/iolite/functinal/bind.rb