functionalist 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/CHANGELOG.md +5 -0
- data/MIT-LICENSE +20 -0
- data/lib/core_ext/kernel.rb +8 -0
- data/lib/core_ext/string.rb +55 -0
- data/lib/functionalist.rb +10 -0
- data/lib/functionalist/point_free.rb +1 -0
- data/lib/functionalist/point_free/expression.rb +39 -0
- data/lib/functionalist/point_free/operator.rb +40 -0
- data/lib/functionalist/point_free/string_extensions.rb +31 -0
- data/lib/functionalist/version.rb +5 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZjFjNmY2Y2FmMDJjZTVmMmVlZmZiM2NhZDhkYjE1M2IxOGE5NWFmNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Zjc0OGY0YmY0Njg5MWIyMmE1YjYyNmRlNTNlZmIwZjA2YjZkMjU3MQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTEwOTk3ZWE0ODgwNmIzYWQ0Y2MwZDBkZjIzOWIyN2U5YjFhZDAyNGUxOWE4
|
10
|
+
ZTZhMzcxMGQyYzhlMmVjZDUwM2ZjYzE2MTc4ZTk2OWMxY2NjY2Q5ZTc5Mjk3
|
11
|
+
ZGU2N2EyMmRmNjY0MzFhNWIwZWRlYzU5YTNhYzQyMGZhNWUyNzI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MGFhMjQ2YzBlYTkwNjMyNTdkYWI0YzU4NTMxMGYyOGU4NDUxNGU3NDMwOGQy
|
14
|
+
NDdiZDA4Y2E1ODFmMDk3MDMxYmYyM2M3YjlkYTk0ODJmMTU2ZDY4N2U0YmQ5
|
15
|
+
MzJiZWYwOTVlY2YyYWYyNzAyODc4NzkzMDEyZjYwMDZlMThjMWQ=
|
data/CHANGELOG.md
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Miguel Regedor
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
OPERATOR_AFTER = ' < '
|
4
|
+
|
5
|
+
def r(receiver)
|
6
|
+
@point_free_receiver = receiver
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def args(*array)
|
11
|
+
@point_free_args = array
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def to_proc
|
16
|
+
parse_expression(self)
|
17
|
+
expression.to_proc
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def expression
|
24
|
+
@expression ||= Functionalist::PointFree::Expression.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def parse_expression(exp)
|
28
|
+
# carimbar
|
29
|
+
exp.strip.split(OPERATOR_AFTER).reverse.each do |sub_exp|
|
30
|
+
# descarimbar
|
31
|
+
next if parse_functionalist_method(expression, sub_exp)
|
32
|
+
|
33
|
+
_, receiver_string, method_name, args_string = /(\w*\.)?(\w+)(\(.*\))?/.match(sub_exp).to_a
|
34
|
+
parse_receiver expression, receiver_string
|
35
|
+
parse_args expression, args_string
|
36
|
+
expression.send method_name
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def parse_receiver(expression, receiver_string)
|
42
|
+
expression.point_free_reciever(receiver_string) if receiver_string
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def parse_args(expression, args_string)
|
47
|
+
expression.point_free_inject_args(args_string) if args_string
|
48
|
+
end
|
49
|
+
|
50
|
+
def parse_functionalist_method(expression, exp)
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
$: << File.expand_path(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'functionalist/version'
|
4
|
+
require 'functionalist/point_free'
|
5
|
+
require 'functionalist/point_free/operator'
|
6
|
+
require 'functionalist/point_free/expression'
|
7
|
+
|
8
|
+
require 'core_ext/kernel'
|
9
|
+
#require 'core_ext/string'
|
10
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
module PointFree ; end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Functionalist
|
2
|
+
module PointFree
|
3
|
+
class Expression
|
4
|
+
|
5
|
+
undef_method(*(instance_methods.map(&:to_sym) - [:__id__, :__send__, :object_id]))
|
6
|
+
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@methods = []
|
10
|
+
end
|
11
|
+
|
12
|
+
#def _(reciever)
|
13
|
+
# self.functionalist_point_free_change_reciever(reciever)
|
14
|
+
#end
|
15
|
+
|
16
|
+
|
17
|
+
def method_missing(*method_and_args, &block)
|
18
|
+
@methods << [method_and_args, block] unless method_and_args == [:respond_to?, :to_proc]
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def to_proc
|
24
|
+
lambda do |obj|
|
25
|
+
reciever, value = @methods.inject(obj) do |left, right|
|
26
|
+
Functionalist::PointFree::Operator.caculate(left, right)
|
27
|
+
end
|
28
|
+
reciever
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def queue
|
33
|
+
@methods
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Functionalist
|
2
|
+
module PointFree
|
3
|
+
module Operator
|
4
|
+
|
5
|
+
def self.caculate(left, right)
|
6
|
+
receiver, value = left
|
7
|
+
method_and_args, block = right
|
8
|
+
#puts "#{reciever.inspect} >> ##{method_and_args}"
|
9
|
+
|
10
|
+
a = case method_and_args.first
|
11
|
+
when :point_free_itself
|
12
|
+
left
|
13
|
+
|
14
|
+
when :point_free_map
|
15
|
+
[receiver.map(&method_and_args[1]), nil]
|
16
|
+
|
17
|
+
when :point_free_split
|
18
|
+
[method_and_args[1..-1].map {|x| x.to_proc.call(receiver)}, nil]
|
19
|
+
|
20
|
+
when :point_free_change_receiver
|
21
|
+
[method_and_args[1],receiver]
|
22
|
+
|
23
|
+
when :point_free_inject_args
|
24
|
+
#[method_and_args[1],receiver]
|
25
|
+
|
26
|
+
else #:point_free_concatenate
|
27
|
+
method_and_args = [method_and_args[0]] + [value] if value
|
28
|
+
|
29
|
+
[receiver.send(*method_and_args, &block), nil]
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
#puts a.inspect ;puts
|
34
|
+
return a
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module StringExtensions
|
2
|
+
|
3
|
+
OPERATOR_AFTER = ' < '
|
4
|
+
|
5
|
+
def r(receiver)
|
6
|
+
@point_free_receiver = receiver
|
7
|
+
end
|
8
|
+
|
9
|
+
def args(*args)
|
10
|
+
@point_free_args = args
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def point
|
15
|
+
|
16
|
+
def to_proc
|
17
|
+
self.strip.split(OPERATOR_AFTER).reverse.each do |node|
|
18
|
+
parse node
|
19
|
+
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def expression
|
28
|
+
@@expression ||= Functionalist::PointFree::Expression.new
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: functionalist
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Miguel Regedor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest-colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: The beauty of functional programing in ruby!
|
28
|
+
email: miguelregedor@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- CHANGELOG.md
|
34
|
+
- MIT-LICENSE
|
35
|
+
- lib/core_ext/kernel.rb
|
36
|
+
- lib/core_ext/string.rb
|
37
|
+
- lib/functionalist.rb
|
38
|
+
- lib/functionalist/point_free.rb
|
39
|
+
- lib/functionalist/point_free/expression.rb
|
40
|
+
- lib/functionalist/point_free/operator.rb
|
41
|
+
- lib/functionalist/point_free/string_extensions.rb
|
42
|
+
- lib/functionalist/version.rb
|
43
|
+
homepage: http://rubygems.org/gems/functionalist
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.9.3
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.4.1
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: The beauty of functional programing in ruby!
|
67
|
+
test_files: []
|