rammed 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b344d7bcfd200c8f5a6120dffa4bc93207be67e
4
+ data.tar.gz: 8c00175f8280c2a9a309834cf55eb08143273b8f
5
+ SHA512:
6
+ metadata.gz: cf637648a47da9e061cd6cf8b8e038290bce6aeac0f50eed19d3f044cf1eff4419517887e92239aa46bfe10f512b3073016cc5aa1e453e8e0e2dd4aeb197bb94
7
+ data.tar.gz: 7a462b50ce5091d463f66cf29a454b60457beda045bea353de7581286bf9893cb5783e519c41b18c78bfa45469bdd98a14c421421972b2bfe6bd456f1b49fdc9
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ Documentation:
2
+ Enabled: false
3
+ AllCops:
4
+ RunRailsCops: true
5
+ DisplayCopNames: true
6
+ Metrics/MethodLength:
7
+ CountComments: false # count full line comments?
8
+ Max: 20
9
+ Metrics/LineLength:
10
+ Max: 120
11
+ AllowURI: true
12
+ URISchemes:
13
+ - http
14
+ - https
15
+ Metrics/AbcSize:
16
+ Max: 50
17
+ Metrics/ClassLength:
18
+ Max: 500
19
+ Style/SpaceInsideHashLiteralBraces:
20
+ EnforcedStyle: no_space
21
+ Style/SpaceAroundEqualsInParameterDefault:
22
+ EnforcedStyle: no_space
23
+ Style/LambdaCall:
24
+ EnforcedStyle: false
25
+ Style/OpMethod:
26
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rammed.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rammed (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.4.2)
11
+ rantly (0.3.2)
12
+ rspec (3.4.0)
13
+ rspec-core (~> 3.4.0)
14
+ rspec-expectations (~> 3.4.0)
15
+ rspec-mocks (~> 3.4.0)
16
+ rspec-core (3.4.1)
17
+ rspec-support (~> 3.4.0)
18
+ rspec-expectations (3.4.0)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.4.0)
21
+ rspec-mocks (3.4.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.4.0)
24
+ rspec-support (3.4.1)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.10)
31
+ rake (~> 10.0)
32
+ rammed!
33
+ rantly
34
+ rspec
35
+
36
+ BUNDLED WITH
37
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Brandon Keown
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # rammed
2
+ A port of ramda to ruby.
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rammed"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/monad/base.rb ADDED
@@ -0,0 +1,34 @@
1
+ module Rammed
2
+ module Monad
3
+ COMMON_FUNCS = {
4
+ bind: Rammed.invoker(1, :bind),
5
+ ap: Rammed.invoker(1, :ap),
6
+ map: Rammed.invoker(1, :map)
7
+ }.freeze
8
+ module Base
9
+ def >>(f)
10
+ bind(f)
11
+ end
12
+
13
+ def <(other)
14
+ ap(other)
15
+ end
16
+
17
+ def >(other)
18
+ other.ap(self)
19
+ end
20
+
21
+ def ap(other)
22
+ self >> (lambda do |f|
23
+ other >> (lambda do |x|
24
+ mreturn f.(x)
25
+ end)
26
+ end)
27
+ end
28
+
29
+ def map(f)
30
+ self >> ->(x) { mreturn f.(x) }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,75 @@
1
+ require 'monad/base'
2
+ require 'ostruct'
3
+
4
+ module Rammed
5
+ module Monad
6
+ module EitherConstructors
7
+ class Right
8
+ include Monad::Base
9
+ def initialize(v)
10
+ @v = v
11
+ end
12
+
13
+ def right?
14
+ true
15
+ end
16
+
17
+ def left?
18
+ false
19
+ end
20
+
21
+ def bind(f)
22
+ f.(@v)
23
+ end
24
+
25
+ def ==(other)
26
+ other.respond_to?(:right?) && other.right? && other.instance_variable_get(:@v) == @v
27
+ end
28
+
29
+ def mreturn(v)
30
+ self.class.new(v)
31
+ end
32
+
33
+ def extract
34
+ @v
35
+ end
36
+ end
37
+
38
+ class Left
39
+ include Monad::Base
40
+ def initialize(v)
41
+ @v = v
42
+ end
43
+
44
+ def right?
45
+ false
46
+ end
47
+
48
+ def left?
49
+ true
50
+ end
51
+
52
+ def bind(_)
53
+ self
54
+ end
55
+
56
+ def ==(other)
57
+ other.respond_to?(:left?) && other.left? && other.instance_variable_get(:@v) == @v
58
+ end
59
+
60
+ def extract
61
+ @v
62
+ end
63
+ end
64
+ end
65
+
66
+ Either = OpenStruct.new(COMMON_FUNCS.merge(
67
+ of: ->(v) { v.nil? ? EitherConstructors::Left.new(nil) : EitherConstructors::Right.new(v) },
68
+ right?: Rammed.invoker(0, :right?),
69
+ left?: Rammed.invoker(0, :left?),
70
+ right: EitherConstructors::Right.method(:new),
71
+ left: EitherConstructors::Left.method(:new),
72
+ extract: Rammed.invoker(0, :extract)
73
+ ))
74
+ end
75
+ end
@@ -0,0 +1,65 @@
1
+ require 'monad/base'
2
+ require 'ostruct'
3
+
4
+ module Rammed
5
+ module Monad
6
+ module MaybeConstructors
7
+ class Just
8
+ include Monad::Base
9
+ def initialize(v)
10
+ @v = v
11
+ end
12
+
13
+ def just?
14
+ true
15
+ end
16
+
17
+ def none?
18
+ false
19
+ end
20
+
21
+ def bind(f)
22
+ f.(@v)
23
+ end
24
+
25
+ def map(f)
26
+ self >> ->(x) { Just.new(f.(x)) }
27
+ end
28
+
29
+ def ==(other)
30
+ other.respond_to?(:just?) && other.just? && other.instance_variable_get(:@v) == @v
31
+ end
32
+
33
+ def mreturn(v)
34
+ self.class.new(v)
35
+ end
36
+ end
37
+
38
+ class None
39
+ include Monad::Base
40
+ def just?
41
+ false
42
+ end
43
+
44
+ def none?
45
+ true
46
+ end
47
+
48
+ def bind(_)
49
+ self
50
+ end
51
+
52
+ def ==(other)
53
+ other.respond_to?(:none?) && other.none?
54
+ end
55
+ end
56
+ end
57
+ Maybe = OpenStruct.new(COMMON_FUNCS.merge(
58
+ of: ->(v) { v.nil? ? MaybeConstructors::None.new : MaybeConstructors::Just.new(v) },
59
+ none?: Core.invoker.(0, :none?),
60
+ just?: Core.invoker.(0, :just?),
61
+ none: MaybeConstructors::None.method(:new),
62
+ just: MaybeConstructors::Just.method(:new)
63
+ ))
64
+ end
65
+ end
data/lib/rammed.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'ostruct'
2
+
3
+ module Rammed
4
+ module_function
5
+
6
+ def adjust(f, i, l)
7
+ new_list = l.clone
8
+ new_list[i] = f.(l[i])
9
+ new_list.freeze
10
+ end
11
+
12
+ def curry_n(n, f)
13
+ f.curry(n)
14
+ end
15
+
16
+ def invoker(n, sym, block=-1)
17
+ curry_n(n + 1, (lambda do |*args|
18
+ block_removed_args = block >= 0 ? args.slice(0...block) + args.slice(block + 1..-1) : args
19
+ actual_args = block_removed_args.slice(0...-1)
20
+ obj = args.last
21
+ block_arg = args[block] if block >= 0
22
+ if block_arg
23
+ obj.send(sym, *(actual_args), &block_arg)
24
+ else
25
+ obj.send(sym, *(actual_args))
26
+ end
27
+ end))
28
+ end
29
+ Core = OpenStruct.new(
30
+ identity: ->(x) { x },
31
+ const: ->(x) { ->(*_) { x } },
32
+ compose: ->(f, g) { ->(*args) { f.(g.(*args)) } },
33
+ compose_all: ->(*args) { args.reduce(identity, &compose) },
34
+ partial: ->(f, *args) { ->(*in_args) { f.(*(args + in_args)) } },
35
+ partial_block: ->(f, b) { ->(*args) { f.(*args, &b) } },
36
+ curry: (lambda do |f|
37
+ throw 'Variadic and nullary functions may not be curried.' if f.arity <= 0
38
+ f.curry
39
+ end),
40
+ curry_n: Rammed.method(:curry_n),
41
+ invoker: Rammed.method(:invoker),
42
+ add: curry_n(2, ->(a, b) { a + b }),
43
+ adjust: Rammed.method(:adjust).curry(3),
44
+ all: Rammed.invoker(1, :all?, 0)
45
+ )
46
+ end
data/rammed.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rammed"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Brandon Keown"]
9
+ spec.email = ["me@brandonkeown.com"]
10
+
11
+ spec.summary = "Ramda for Ruby"
12
+ spec.homepage = "https://www.github.com/theqabalist/rammed"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.10"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rantly"
23
+ spec.add_development_dependency "rspec"
24
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rammed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Keown
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-10 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: rantly
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - me@brandonkeown.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rubocop.yml"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/monad/base.rb
86
+ - lib/monad/either.rb
87
+ - lib/monad/maybe.rb
88
+ - lib/rammed.rb
89
+ - rammed.gemspec
90
+ homepage: https://www.github.com/theqabalist/rammed
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.5.1
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Ramda for Ruby
114
+ test_files: []