lab42_core 0.0.6 → 0.0.7

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: b8604c795cdfac60ef4c57d18e1fd7df61817540
4
- data.tar.gz: 5f238687507445c9b448e66eeeaad3e75a37e7fd
3
+ metadata.gz: 6c1c6148c550240fac9cbd4b175be6f44986fd3e
4
+ data.tar.gz: 630f25d0a92570a4c1c23c46f963520ac7e3f5b1
5
5
  SHA512:
6
- metadata.gz: e95293ca068e18547faf0892b75512fa55382a54d62cfd989066dd9c6276ad4d4043a717701fb5da782018122e801141691bce9afb0b0ebf98435d46e52c972f
7
- data.tar.gz: afbe49cb75fc522ad820ab333a468325767bfd505eda6630480d87f0deb41c233e7f256964507ce67ce5e160295c3662857a194cec658b18e51a6980138bfe56
6
+ metadata.gz: c971f1782da35b2c340b275e0d195b99e7506ed9a85fa240110e847b1a9bcc63f4a081e97514ceb6a3f39e711ffb171447eb4f6d1baa3b94eaf9a411091ecf82
7
+ data.tar.gz: 242a5a8b5c2f6866b0be0a62698b39a887309a71ce82781bba43e3001c2318ae2ac060408d8162b88d6e38353d8f321ce8a5a26ca01cf57e4acec6044c882908
data/README.md CHANGED
@@ -68,7 +68,7 @@ If you hesitate to use this all, have a look into Kernel#const_lambda
68
68
 
69
69
  ```ruby
70
70
  f = Array.fm.push :next
71
- [[],[1].map( f ) # ---> [[:next], [1, :next]]
71
+ [[],[1]].map( f ) # ---> [[:next], [1, :next]]
72
72
 
73
73
  a=[]
74
74
  f = a.fn.push :first
@@ -1,8 +1,20 @@
1
1
  module Lab42
2
2
  module Core
3
3
  module IteratorReimpl
4
+
5
+
6
+ def self.decompose_args args, block
7
+ raise ArgumentError, 'too many arguments' if args.size + ( block ? 1 : 0 ) > 2
8
+ return [args,block] if block
9
+ b, a = args.partition{|x| behavior? x}
10
+ behave = b.pop
11
+ a = b if a.empty?
12
+ raise ArgumentError, "No behavior specified" unless behave
13
+ return [a,behave]
14
+ end
15
+
4
16
  def self.included into
5
- # TODO: Try to DRY
17
+ _self = self
6
18
  into.module_eval do
7
19
  alias_method :__lab42_core_iterator_map__, :map
8
20
  def map behavior=nil, &blk
@@ -14,29 +26,21 @@ module Lab42
14
26
  end
15
27
  alias_method :filter, :select
16
28
 
17
- alias_method :__lab42_core_iterator_reduce__, :reduce
18
- def reduce behavior=nil, &blk
19
- if Symbol === behavior
20
- __lab42_core_iterator_reduce__ behavior
21
- else
22
- __lab42_core_iterator_reduce__(&(behavior||blk))
23
- end
24
- end
25
-
26
29
  alias_method :__lab42_core_iterator_inject__, :inject
27
- def inject *args, &blk
28
- return reduce(&blk) if args.empty?
29
- value, behavior = args
30
- if Symbol === behavior
31
- __lab42_core_iterator_inject__ value, behavior
32
- else
33
- __lab42_core_iterator_inject__(value, &(behavior||blk))
34
- end
30
+ define_method :inject do |*args, &blk|
31
+ args, behavior = _self.decompose_args args, blk
32
+ __lab42_core_iterator_inject__( *args, &behavior )
35
33
  end
34
+ alias_method :reduce, :inject
36
35
 
37
36
  def filter *args, &blk
38
37
  end
39
38
  end
39
+
40
+ private
41
+ def self.behavior? x
42
+ Symbol === x || Proc === x || Method === x
43
+ end
40
44
  end
41
45
  end
42
46
  end # module Core
@@ -1,5 +1,5 @@
1
1
  module Lab42
2
2
  module Core
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end # module Core
5
5
  end # module Lab42
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lab42_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-01 00:00:00.000000000 Z
11
+ date: 2014-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -44,22 +44,22 @@ executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
+ - LICENSE
48
+ - README.md
47
49
  - lib/lab42/core.rb
50
+ - lib/lab42/core/dir.rb
51
+ - lib/lab42/core/enumerable.rb
52
+ - lib/lab42/core/fn.rb
48
53
  - lib/lab42/core/fn/array.rb
49
54
  - lib/lab42/core/fn/basic_object.rb
55
+ - lib/lab42/core/fn/enumerable.rb
50
56
  - lib/lab42/core/fn/enumerator/lazy.rb
51
57
  - lib/lab42/core/fn/iterator_reimpl.rb
52
- - lib/lab42/core/fn/enumerable.rb
53
- - lib/lab42/core/dir.rb
54
- - lib/lab42/core/module.rb
55
- - lib/lab42/core/version.rb
56
- - lib/lab42/core/fn.rb
57
58
  - lib/lab42/core/hash.rb
58
- - lib/lab42/core/object.rb
59
59
  - lib/lab42/core/kernel.rb
60
- - lib/lab42/core/enumerable.rb
61
- - LICENSE
62
- - README.md
60
+ - lib/lab42/core/module.rb
61
+ - lib/lab42/core/object.rb
62
+ - lib/lab42/core/version.rb
63
63
  homepage: https://github.com/RobertDober/lab42_core
64
64
  licenses:
65
65
  - MIT
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  version: '0'
81
81
  requirements: []
82
82
  rubyforge_project:
83
- rubygems_version: 2.1.5
83
+ rubygems_version: 2.2.0
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: What I am missing in Ruby