szczupac 0.2.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: 2db8dc8a82521e4b88b0352477bd074d880c463bda3e79c0a1835fec4fc3222d
4
- data.tar.gz: 1d69e30683fd4d886b3bab28f0d7ee876f5126130b7f4a320e1c40d68409c7f6
3
+ metadata.gz: 225c244bf3dbd3d7776978d61ac21989095f83421916b86c5942e37512809fec
4
+ data.tar.gz: cbf4f2f48fee666b10e61df3569130348d10ba6354bd3ba8aa5d595ab3097a06
5
5
  SHA512:
6
- metadata.gz: '07329b9602ad86c81cb4945d6c62eac9063328a822c36edcb163de28242323e637582e4992ca60e2caddfbdc14a71c59ff353d8c58a6740394c78df2cdcec656'
7
- data.tar.gz: 6ecb7c2d154d19705de108ed4c03dea326c5554cbb139ed28ba7de1ddd6128466ddfe3ae4528a1911f9bb1c085a2f9db1187750118a51b78e86fd7bc318af45b
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.2.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/szczupac.rb CHANGED
@@ -5,20 +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) }
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 }
20
37
  end
21
38
  .uniq
22
39
  end
40
+
41
+ def call(**named_lanes)
42
+ generate(*named_lanes.map { |name, values| axis(name, values) })
43
+ end
23
44
  alias [] call
24
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.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paweł Pacana