szczupac 0.3.0 → 0.4.0

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
  SHA256:
3
- metadata.gz: e2d747def49ff2b27088286fa6c5f388868b50bf5a91bc558ce6eabe606b70c1
4
- data.tar.gz: 5aa49ae7455586547c1ad07d8fe16a0efe220b54187c99949c1aa9cddeaeb94b
3
+ metadata.gz: 225c244bf3dbd3d7776978d61ac21989095f83421916b86c5942e37512809fec
4
+ data.tar.gz: cbf4f2f48fee666b10e61df3569130348d10ba6354bd3ba8aa5d595ab3097a06
5
5
  SHA512:
6
- metadata.gz: 8fe7a1cf269fb19966378ac0febab1322639fc0720d217ed6071378f9e7d0a3086ad51684b12734c8b864489fbe5129d38b8e55e86f9e78f50cbebeaeaa1d62e
7
- data.tar.gz: 7e3a3f13966678dc9ed56f9282890036497d7b7ef8e977432eb7399044142df764c344eb26e5570e7d7118af88f63e8949952eb8b69aaebd5fea3809101caed6
6
+ metadata.gz: a076ef2747de634e25eb55e71b7f8c78b5a5f7aed47e74764c323c7874dc3da5ce3debae3b1ff09c001fd56f765516dafac5a365aa09a6a113e79e043267ec02
7
+ data.tar.gz: 27e60b2d99adf4367c143f8e0cdfbe01887295a659dfc810f6131c0edc3bfb58fc4113f6ebb99f9302952c6f2bfb37d51c4b863155a8babfce89982b6f22396f
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Szczupac
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/szczupac.rb CHANGED
@@ -5,21 +5,41 @@ require_relative "szczupac/version"
5
5
  module Szczupac
6
6
  extend self
7
7
 
8
- def call(**named_lanes)
9
- named_lanes
10
- .flat_map do |name, values|
11
- first_from_rest =
12
- named_lanes
13
- .reject { |n, _| n == name }
14
- .map { |n, v| { n => v.first } }
15
- .reduce(&:merge)
16
- values
17
- .map { |v| { name => v } }
18
- .product([first_from_rest])
19
- .map { |v| v.reduce(&:merge) }
20
- .map { |v| v.sort_by { |k, _| named_lanes.keys.index(k) }.to_h }
8
+ def axis(name, values)
9
+ values.map { |v| { name => v } }
10
+ end
11
+
12
+ def generate(*axes)
13
+ order = axes.flat_map { |a| a.flat_map(&:keys) }.uniq
14
+
15
+ axes
16
+ .flat_map do |axis|
17
+ rest = axes - [axis]
18
+ first_options = rest.map(&:first)
19
+ axis
20
+ .product([first_options.reduce(&:merge)])
21
+ .map { |product| product.reduce(&:merge) }
22
+ .map { |product| product.sort_by { |k, _| order.index(k) }.to_h }
23
+ end
24
+ .uniq
25
+ end
26
+
27
+ def permutation(*axes)
28
+ order = axes.flat_map { |a| a.map(&:keys) }.uniq
29
+
30
+ axes
31
+ .flat_map do |axis|
32
+ rest = axes - [axis]
33
+ axis
34
+ .product(*rest)
35
+ .map { |product| product.reduce(&:merge) }
36
+ .map { |product| product.sort_by { |k, _| order.index(k) }.to_h }
21
37
  end
22
38
  .uniq
23
39
  end
40
+
41
+ def call(**named_lanes)
42
+ generate(*named_lanes.map { |name, values| axis(name, values) })
43
+ end
24
44
  alias [] call
25
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: szczupac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paweł Pacana