functional_support 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a49f378903ee112cae54aa40edb5e125cedf7ee1
4
- data.tar.gz: 26351f601c1dffa159ab714e08f3d426e021a30a
3
+ metadata.gz: 4eb0da5c2b0ec87d19007996eca75e3fdd63d88f
4
+ data.tar.gz: 6101d5b8c88734a7fc3c36f9d48c6b368ee77a52
5
5
  SHA512:
6
- metadata.gz: a382aab74312bfed8de7b3520f7c54176424decaf74f031b2964f820d8217fa86b5021de645b6eb87df843d827a41a967db0a902ce6d756d27ebabd6109c76ae
7
- data.tar.gz: fe6c3d4547779a563db2454b3acdf3cbeb19582dd7beefaa610f03c0b02bb640f34baad36bd7d162a578423fe7fe521f237d05499f3029ab88ab767450ed1bac
6
+ metadata.gz: fcbd724b46936107e8a29362558fa201676528c40e85de964ce9d929459c05bece81a78d381eb0b285df199743a82e929f3dcde9c92711843c42c07e8e3cc8cb
7
+ data.tar.gz: 253bb6f6c4d2210b49445330f148a599ed9c7ec0aa93dd45a3c16f810f6e143946292e653c4febb00fea2d32671be5ca62a923bf726477913ee62ce142cb7efa
@@ -1,4 +1,13 @@
1
1
  class Array
2
+ class ProductWithEmptyArray < StandardError
3
+ end
4
+ # Returns the Cartesian product of two arrays
5
+ def product(xs)
6
+ raise(ProductWithEmptyArray, "can't product #{self} with #{xs}") if count == 0 || xs.count == 0
7
+ return xs.map { |x| [first, x] } if count == 1
8
+ thing = xs.map { |x| [first, x] }
9
+ thing + tail.product(xs)
10
+ end
2
11
 
3
12
  def tail
4
13
  self[1..-1]
@@ -1,3 +1,3 @@
1
1
  module FunctionalSupport
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Array do
4
+ context '#product' do
5
+ subject { ["a", "b", "c"].product [1, 2] }
6
+ let(:expected) { [["a", 1], ["a", 2], ["b", 1], ["b", 2], ["c", 1], ["c", 2]] }
7
+ specify { should eq expected }
8
+ end
9
+ context '#product error' do
10
+ let(:messup) { [].product [1,2] }
11
+ specify { expect { messup }.to raise_error Array::ProductWithEmptyArray }
12
+ end
13
+ end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,2 @@
1
- # TODO: move the specs in also lol
1
+ # TODO: move the specs in also lol
2
+ require File.expand_path("../../lib/functional_support", __FILE__)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: functional_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-26 00:00:00.000000000 Z
11
+ date: 2014-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,6 +89,7 @@ files:
89
89
  - lib/functional_support/core_ext/proc.rb
90
90
  - lib/functional_support/core_ext/string.rb
91
91
  - lib/functional_support/version.rb
92
+ - spec/functional_support/array_spec.rb
92
93
  - spec/spec_helper.rb
93
94
  homepage: ''
94
95
  licenses:
@@ -110,11 +111,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  version: '0'
111
112
  requirements: []
112
113
  rubyforge_project:
113
- rubygems_version: 2.2.1
114
+ rubygems_version: 2.2.2
114
115
  signing_key:
115
116
  specification_version: 4
116
117
  summary: Includes a lot of stuff on higher order functional processing of arrays and
117
118
  hashes
118
119
  test_files:
120
+ - spec/functional_support/array_spec.rb
119
121
  - spec/spec_helper.rb
120
- has_rdoc: