lab42_core 0.0.4 → 0.0.5

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: d7f5a0cfaf9792e16c822da9826afaca6cb96cdf
4
- data.tar.gz: 194ffc45ea41e84095afa8c0bca479425cf73616
3
+ metadata.gz: 028aefd79743422aa1e099ba360099b8195080a4
4
+ data.tar.gz: fef7d4cd84cb13f157133ca2c71a0c9148a8479c
5
5
  SHA512:
6
- metadata.gz: 71a8af599ac63a9a52c416f8d9aa964cf95f91f6558e5560f5fbe1fbc40679d98f4aa89937011636fdb85cd1d18caaffa8e8593b0f42fb21617c866cbd1ce6b0
7
- data.tar.gz: 02f3fa3eeef659ff44f6f552f1f8b47123bbc0484a5df35398041a0b6ec0efcb94b7bee96195495fb8e48e4ac229c11049e5179be9b6a53be52b2374ddac8a20
6
+ metadata.gz: b17bebb308b74058fedcd8a4dee757058347ba1e968f089c23b1e8081f9cb09fec00f2bdff13fc68ef626ffe4a1bff1c4f8eea9035586eae67d31548b4e3c6b5
7
+ data.tar.gz: c73f4623f9af802c1cbf684a8f30bd20a6cd976392f3e6621152118f6a095bb56f6b289803b46a5eca812474b12a88594d065fd5c4a2a4e6edaab35ea8c447d3
data/README.md CHANGED
@@ -26,6 +26,8 @@ Ruby Core Module Extensions (in the spirit of lab419/core)
26
26
 
27
27
  Must be required specifically!
28
28
 
29
+ ### Access to methods
30
+
29
31
  ```ruby
30
32
  require 'lab42/core/fn'
31
33
 
@@ -37,3 +39,38 @@ Must be required specifically!
37
39
  # It also extends some enumerable methods for easier execution
38
40
  %w{hello world}.each printer
39
41
  ```
42
+
43
+ Thusly `fn` gives us access to methods of objects, but what about instance methods?
44
+
45
+ ### Access to instance methods
46
+
47
+ Is realized via `fm`.
48
+
49
+ ```ruby
50
+ require 'lab42/core/fn'
51
+
52
+ (1..100).reduce Fixnum.fm.+ # ---> 5050
53
+ ```
54
+
55
+ ### Objects as constant procs
56
+
57
+ While `Object#self` will return the obvious, so will by extension `object.fn.self`.
58
+
59
+ This can be very useful, e.g. in this nice way to create an empty array ;)
60
+
61
+ ```ruby
62
+ (1..100).filter(false.fn.self)
63
+ ```
64
+
65
+ If you hesitate to use this all, have a look into Kernel#const_lambda
66
+
67
+ ### Partial Application
68
+
69
+ ```ruby
70
+ f = Array.fm.push :next
71
+ [[],[1].map( f ) # ---> [[:next], [1, :next]]
72
+
73
+ a=[]
74
+ f = a.fn.push :first
75
+ f.(1) # a ---> [:first, 1]
76
+ ```
@@ -1,15 +1,23 @@
1
1
  module Lab42
2
2
  module Core
3
3
  class Fn < BasicObject
4
+ def self;
5
+ ->(*args,&blk){ @source } # This is *not* a recursive call
6
+ end
4
7
  private
5
8
  def initialize source
6
9
  @source = source
7
10
  end
8
11
 
9
12
  def method_missing *args, &blk
10
- @source.method args.first
13
+ return @source.method args.first if args.size == 1 && blk.nil?
14
+ s = @source
15
+ -> *a, &b do
16
+ s.method( args.first ).(*(args[1..-1]+a), &(blk||b))
17
+ end
11
18
  end
12
19
  end # class Fn
20
+
13
21
  class Fm < BasicObject
14
22
  private
15
23
  def initialize source
@@ -19,7 +27,7 @@ module Lab42
19
27
  def method_missing *args, &blk
20
28
  m = @source.instance_method args.first
21
29
  -> receiver, *a, &b do
22
- m.bind( receiver ).(*a, &b)
30
+ m.bind( receiver ).(*(args[1..-1]+a), &(blk||b))
23
31
  end
24
32
  end
25
33
  end # class Fn
@@ -2,11 +2,18 @@ module Lab42
2
2
  module Core
3
3
  module IteratorReimpl
4
4
  def self.included into
5
+ # TODO: Try to DRY
5
6
  into.module_eval do
6
7
  alias_method :__lab42_core_iterator_map__, :map
7
8
  def map behavior=nil, &blk
8
9
  __lab42_core_iterator_map__(&(behavior||blk))
9
10
  end
11
+ alias_method :__lab42_core_iterator_select__, :select
12
+ def select behavior=nil, &blk
13
+ __lab42_core_iterator_select__(&(behavior||blk))
14
+ end
15
+ alias_method :filter, :select
16
+
10
17
  alias_method :__lab42_core_iterator_reduce__, :reduce
11
18
  def reduce behavior=nil, &blk
12
19
  if Symbol === behavior
@@ -24,6 +31,9 @@ module Lab42
24
31
  __lab42_core_iterator_inject__(value, &(behavior||blk))
25
32
  end
26
33
  end
34
+
35
+ def filter *args, &blk
36
+ end
27
37
  end
28
38
  end
29
39
  end
@@ -1,4 +1,11 @@
1
1
  module Kernel
2
+
3
+ def const_lambda a_const
4
+ -> *a, &b do
5
+ a_const
6
+ end
7
+ end
8
+
2
9
  def sendmsg *args
3
10
  ->(*a){ a.first.send(*(args + a.drop( 1 ))) }
4
11
  end
@@ -0,0 +1,3 @@
1
+ class Object
2
+ def self; self end
3
+ end
@@ -1,5 +1,5 @@
1
1
  module Lab42
2
2
  module Core
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end # module Core
5
5
  end # module Lab42
data/lib/lab42/core.rb CHANGED
@@ -2,3 +2,4 @@ require 'lab42/core/dir'
2
2
  require 'lab42/core/enumerable'
3
3
  require 'lab42/core/hash'
4
4
  require 'lab42/core/kernel'
5
+ require 'lab42/core/object'
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.4
4
+ version: 0.0.5
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-10-03 00:00:00.000000000 Z
11
+ date: 2013-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -48,13 +48,13 @@ files:
48
48
  - lib/lab42/core/fn/array.rb
49
49
  - lib/lab42/core/fn/basic_object.rb
50
50
  - lib/lab42/core/fn/enumerator/lazy.rb
51
- - lib/lab42/core/fn/fm.rb
52
51
  - lib/lab42/core/fn/iterator_reimpl.rb
53
52
  - lib/lab42/core/fn/enumerable.rb
54
53
  - lib/lab42/core/dir.rb
55
54
  - lib/lab42/core/version.rb
56
55
  - lib/lab42/core/fn.rb
57
56
  - lib/lab42/core/hash.rb
57
+ - lib/lab42/core/object.rb
58
58
  - lib/lab42/core/kernel.rb
59
59
  - lib/lab42/core/enumerable.rb
60
60
  - LICENSE
File without changes