function-composite 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 65b65fdf797182cb101d49ccd14034d7c6ea6c93beb15e802862fe669188b8d7
4
+ data.tar.gz: 2dc04979b6ed0a95050c7e3356a6a45b071ba333facc2eb177225b1336b8038d
5
+ SHA512:
6
+ metadata.gz: a695d0e7a8765743aacf752f5c6106c0f9d6b8312421946cdacb2db55091ce80d780c8981ade4b701a2803c07c90863929a5f27e61cfa5c0a4c775b5a4673c7e
7
+ data.tar.gz: 8d476bf7da8bbf68cf0556d896c2800f39e08bc079e065e8d7bda393df4ca969349bf52849ee28062b91717550860dc9f44b9a5885199feb33e0e33e9700bb0c
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ rvm:
5
+ - 2.7.0
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Function::Composite
2
+
3
+ This gem provides a syntax sugar for `Symbol` with `Proc#<<` and `Proc#>>`.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'function-composite'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install function-composite
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'function-composite'
25
+ using Function::Composite
26
+
27
+ p %w{72 101 108 108 111}.map(&:to_i >> :chr) #=> ["H", "e", "l", "l", "o"]
28
+
29
+ p %w{72 101 108 108 111}.map(&proc { |s| s.to_i } >> :chr) #=> ["H", "e", "l", "l", "o"]
30
+
31
+ h = { Alice: 30, Bob: 60, Cris: 90 }
32
+ p %w{Alice Bob Cris}.map(&(:to_sym >> h)) #=> [30, 60, 90]
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nobu/function-composite.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task :test do
5
+ ruby("test/run-test.rb")
6
+ end
7
+
8
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "function/composite"
4
+
5
+ # You can add fixtures and/or initialization code here to make experimenting
6
+ # with your gem easier. You can also use a different console, if you like.
7
+
8
+ # (If you use this, don't forget to add pry to your Gemfile!)
9
+ # require "pry"
10
+ # Pry.start
11
+
12
+ require "irb"
13
+ IRB.start(__FILE__)
@@ -0,0 +1,32 @@
1
+
2
+ require_relative "lib/function/composite"
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "function-composite"
6
+ spec.version = Function::Composite::VERSION
7
+ spec.authors = ["Nobuyoshi Nakada"]
8
+ spec.email = ["nobu@ruby-lang.org"]
9
+
10
+ spec.summary = %q{Syntax sugar for function composite}
11
+ spec.description = spec.summary
12
+ spec.homepage = "https://github.com/nobu/function-composite"
13
+ spec.required_ruby_version = "2.6"
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+
18
+ spec.files = %w[
19
+ .gitignore
20
+ .travis.yml
21
+ README.md
22
+ Rakefile
23
+ bin/console
24
+ function-composite.gemspec
25
+ lib/function/composite.rb
26
+ test/run-test.rb
27
+ test/test-function-composite.rb
28
+ ]
29
+
30
+ spec.require_paths = ["lib"]
31
+ spec.add_development_dependency "test-unit"
32
+ end
@@ -0,0 +1,29 @@
1
+ module Function
2
+ module Composite
3
+ VERSION = "0.1.0"
4
+
5
+ refine(Symbol) do
6
+ def call(*args, &block)
7
+ to_proc.call(*args, &block)
8
+ end
9
+
10
+ def <<(other = (b = true), &block)
11
+ to_proc << (b ? block : other.to_proc)
12
+ end
13
+
14
+ def >>(other = (b = true), &block)
15
+ to_proc >> (b ? block : other.to_proc)
16
+ end
17
+ end
18
+
19
+ refine(Proc) do
20
+ def <<(other)
21
+ super(other.to_proc)
22
+ end
23
+
24
+ def >>(other)
25
+ super(other.to_proc)
26
+ end
27
+ end
28
+ end
29
+ end
data/test/run-test.rb ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'test/unit'
4
+
5
+ base_dir = File.expand_path("../..", __FILE__)
6
+ $LOAD_PATH.unshift("#{base_dir}/lib")
7
+
8
+ begin
9
+ require 'test/unit/notify'
10
+ rescue LoadError
11
+ end
12
+
13
+ exit Test::Unit::AutoRunner.run(true, "#{base_dir}/test")
@@ -0,0 +1,35 @@
1
+ require 'function/composite'
2
+
3
+ using Function::Composite
4
+
5
+ class Function::CompositeTest < Test::Unit::TestCase
6
+ def test_that_it_has_a_version_number
7
+ assert_not_nil ::Function::Composite::VERSION
8
+ end
9
+
10
+ def test_symbol_to_symbol
11
+ result = %w{72 101 108 108 111}.map(&:to_i >> :chr)
12
+ assert_equal(["H", "e", "l", "l", "o"], result)
13
+ end
14
+
15
+ def test_symbol_from_symbol
16
+ result = %w{72 101 108 108 111}.map(&:chr << :to_i)
17
+ assert_equal(["H", "e", "l", "l", "o"], result)
18
+ end
19
+
20
+ def test_proc_to_symbol
21
+ result = %w{72 101 108 108 111}.map(&proc {|s| s.to_i} >> :chr)
22
+ assert_equal(["H", "e", "l", "l", "o"], result)
23
+ end
24
+
25
+ def test_symbol_from_proc
26
+ result = %w{72 101 108 108 111}.map(&:chr << proc {|s| s.to_i})
27
+ assert_equal(["H", "e", "l", "l", "o"], result)
28
+ end
29
+
30
+ def test_symbol_to_callable
31
+ h = {Alice: 30, Bob: 60, Cris: 90}
32
+ result = %w{Alice Bob Cris}.map(&(:to_sym >> h))
33
+ assert_equal([30, 60, 90], result)
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: function-composite
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nobuyoshi Nakada
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test-unit
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: Syntax sugar for function composite
28
+ email:
29
+ - nobu@ruby-lang.org
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".travis.yml"
36
+ - README.md
37
+ - Rakefile
38
+ - bin/console
39
+ - function-composite.gemspec
40
+ - lib/function/composite.rb
41
+ - test/run-test.rb
42
+ - test/test-function-composite.rb
43
+ homepage: https://github.com/nobu/function-composite
44
+ licenses: []
45
+ metadata:
46
+ homepage_uri: https://github.com/nobu/function-composite
47
+ source_code_uri: https://github.com/nobu/function-composite
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '='
55
+ - !ruby/object:Gem::Version
56
+ version: '2.6'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.0.2
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Syntax sugar for function composite
67
+ test_files: []