data-functions 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9ad621f3ea2ebf51622484fa1df48e1ca889ee3423dd8b01c125cb8e613a85ef
4
+ data.tar.gz: 41c2893a5442a4b12eae89d38be6d26f94dbbe95cc8c0f5a2d28ad046694e49c
5
+ SHA512:
6
+ metadata.gz: d2dccf2b5c326b57bf47e3332c2e8e9b316e0e02ab98c0a21c07e3f210acb1d5af3b4f2b2ec6509baf7c0e8507bab78188bc6c358a1e2a02b1b4ff6d4e1bd275
7
+ data.tar.gz: 469e3e84e389dbd8bf54a197f702d87ee2e55a31fec227244c07654bc37528ebad46ca7757343b2b571f0492ce2fd11d9ebc62bb3017923bff5a990eaf7b4914
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ tags
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in data-functions.gemspec
6
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ data-functions (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.9.0)
12
+ rspec-core (~> 3.9.0)
13
+ rspec-expectations (~> 3.9.0)
14
+ rspec-mocks (~> 3.9.0)
15
+ rspec-core (3.9.1)
16
+ rspec-support (~> 3.9.1)
17
+ rspec-expectations (3.9.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.9.0)
20
+ rspec-mocks (3.9.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.9.0)
23
+ rspec-support (3.9.2)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.17)
30
+ data-functions!
31
+ rake (~> 10.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 1.17.3
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Delon Newman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,79 @@
1
+ # Data::Functions
2
+
3
+ Treat Hashes, Arrays, Sets and Objects as Functions
4
+
5
+ # Synopsis
6
+
7
+ ```ruby
8
+ require 'data/functions/hash'
9
+
10
+ number_names = { 1 => "One", 2 => "Two", 3 => "Three" }
11
+ [1, 2, 3, 4].map(&number_names) # => ["One", "Two", "Three", nil]
12
+ ```
13
+
14
+ ```ruby
15
+ require 'data/functions/array'
16
+
17
+ alpha = ('a'..'z').to_a
18
+ [1, 2, 3, 4].map(&alpha) # => ["b", "c", "d", "e"]
19
+ ```
20
+
21
+ ```ruby
22
+ require 'data/functions/set'
23
+
24
+ favorite_numbers = Set[3, Math::PI]
25
+ [1, 2, 3, 4].select(&favorite_numbers) # => [3]
26
+ ```
27
+
28
+ ```ruby
29
+ require 'data/functions/object'
30
+
31
+ # service objects
32
+ class GetDataFromSomeService
33
+ def call(user)
34
+ # do the dirt
35
+ end
36
+ end
37
+
38
+ data_for_user = GetDataFromSomeService.new
39
+ User.all.map(&data_for_user)
40
+ ```
41
+
42
+ ```ruby
43
+ require 'data/functions/hash' # loads hash patch
44
+ require 'data/functions/array' # loads array patch
45
+ require 'data/functions/set' # loads set patch
46
+ require 'data/functions/object' # loads object patch
47
+ require 'data/functions' # loads all patches
48
+ ```
49
+
50
+ # Why?
51
+
52
+ A function is a mapping of one value to another with the additional constraint that for the one input value you will
53
+ always get the same output value. So, conceptually, Ruby Hashes, Arrays, Sets, and Objects (when treated immutably)
54
+ are all functions. Why not treat them as such?
55
+
56
+ # Installation
57
+
58
+ Add this line to your application's Gemfile:
59
+
60
+ ```ruby
61
+ gem 'data-functions'
62
+ ```
63
+
64
+ And then execute:
65
+
66
+ > bundle
67
+
68
+ Or install it yourself as:
69
+
70
+ > gem install data-functions
71
+
72
+ # See Also
73
+
74
+ - [Clojure](https://clojure.org)
75
+ - [Arc](http://www.arclanguage.org)
76
+
77
+ # License
78
+
79
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,42 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "data/functions/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "data-functions"
7
+ spec.version = Data::Functions::VERSION
8
+ spec.authors = ["Delon Newman"]
9
+ spec.email = ["contact@delonnewman.name"]
10
+
11
+ spec.summary = %q{Treat Hashes, Arrays, Sets, and Objects as functions}
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/delonnewman/data-functions"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = spec.homepage
23
+ spec.metadata["changelog_uri"] = "#{spec.homepage}#changelog"
24
+ spec.metadata["documentation_uri"] = "https://www.rubydoc.info/gems/data-functions"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "bin"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.17"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ end
@@ -0,0 +1,5 @@
1
+ require "data/functions/version"
2
+ require "data/functions/object"
3
+ require "data/functions/hash"
4
+ require "data/functions/set"
5
+ require "data/functions/array"
@@ -0,0 +1,10 @@
1
+ class Array
2
+ # Convert Array into a Proc that takes an index and returns the value of the Array at that index.
3
+ #
4
+ # @return [Proc]
5
+ def to_proc
6
+ lambda do |i, *_|
7
+ self.at(i)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class Hash
2
+ # Convert Hash into a Proc that takes a key and returns the value of the Hash for that key.
3
+ #
4
+ # @return [Proc]
5
+ def to_proc
6
+ lambda do |k, *_|
7
+ self.fetch(k, nil)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ class Object
2
+ # If object responds to `call` convert into a Proc that takes a key and returns the value of the Hash for that key.
3
+ #
4
+ # @return [Proc]
5
+ def to_proc
6
+ if respond_to?(:call)
7
+ Proc.new do |*args|
8
+ call(*args)
9
+ end
10
+ else
11
+ raise "Don't know how to convert #{self.inspect} into a Proc"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ require 'set'
2
+
3
+ class Set
4
+ # Convert Set into a Proc that takes a value and returns true if the value is an element of the set or false otherwise.
5
+ #
6
+ # @return [Proc]
7
+ def to_proc
8
+ lambda do |v, *_|
9
+ self.include?(v)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ class Data
2
+ module Functions
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: data-functions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Delon Newman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Treat Hashes, Arrays, Sets, and Objects as functions
56
+ email:
57
+ - contact@delonnewman.name
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - data-functions.gemspec
70
+ - lib/data/functions.rb
71
+ - lib/data/functions/array.rb
72
+ - lib/data/functions/hash.rb
73
+ - lib/data/functions/object.rb
74
+ - lib/data/functions/set.rb
75
+ - lib/data/functions/version.rb
76
+ homepage: https://github.com/delonnewman/data-functions
77
+ licenses:
78
+ - MIT
79
+ metadata:
80
+ allowed_push_host: https://rubygems.org
81
+ homepage_uri: https://github.com/delonnewman/data-functions
82
+ source_code_uri: https://github.com/delonnewman/data-functions
83
+ changelog_uri: https://github.com/delonnewman/data-functions#changelog
84
+ documentation_uri: https://www.rubydoc.info/gems/data-functions
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubygems_version: 3.0.6
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Treat Hashes, Arrays, Sets, and Objects as functions
104
+ test_files: []