00:00
ih8u has quit [Ping timeout: 268 seconds]
00:27
hwpplayer1 has joined #ruby
00:54
o0x1eef has quit [Ping timeout: 272 seconds]
01:03
o0x1eef has joined #ruby
01:24
hwpplayer1 has quit [Remote host closed the connection]
02:21
pages has joined #ruby
02:40
CRISPR has joined #ruby
02:44
cappy has joined #ruby
02:50
jmcantrell has quit [Quit: WeeChat 4.6.0]
03:07
levitating has joined #ruby
03:18
CRISPR has quit [Ping timeout: 272 seconds]
04:03
levitating has quit [Remote host closed the connection]
04:17
cappy has quit [Quit: Leaving]
04:47
gemmaro_ has quit [Ping timeout: 260 seconds]
04:51
gemmaro has joined #ruby
05:21
jmcgnh has quit [Remote host closed the connection]
05:26
jmcgnh has joined #ruby
05:27
grenierm has joined #ruby
07:21
STASIdownunder has quit [Ping timeout: 265 seconds]
07:52
andy-turner has joined #ruby
08:06
rvalue has quit [Read error: Connection reset by peer]
08:06
rvalue has joined #ruby
08:08
STASIdownunder has joined #ruby
08:15
STASIdownunder has quit [Read error: Connection reset by peer]
08:29
STASIdownunder has joined #ruby
09:03
Quiet-Oil9262 has joined #ruby
09:35
STASIdownunder has quit [Read error: Connection reset by peer]
09:42
STASIdownunder has joined #ruby
09:53
STASIdownunder has quit [Read error: Connection reset by peer]
09:59
STASIdownunder has joined #ruby
10:11
STASIdownunder has quit [Read error: Connection reset by peer]
10:17
STASIdownunder has joined #ruby
10:20
STASIdownunder has quit [Read error: Connection reset by peer]
10:26
STASIdownunder has joined #ruby
10:32
STASIdownunder has quit [Read error: Connection reset by peer]
10:37
Quiet-Oil9262 has joined #ruby
10:38
STASIdownunder has joined #ruby
10:50
STASIdownunder has quit [Read error: Connection reset by peer]
10:51
grenierm has quit [Ping timeout: 240 seconds]
10:54
STASIdownunder has joined #ruby
11:00
STASIdownunder has quit [Read error: Connection reset by peer]
11:05
STASIdownunder has joined #ruby
11:14
Milos has joined #ruby
11:28
STASIdownunder has quit [Read error: Connection reset by peer]
11:36
STASIdownunder has joined #ruby
11:47
cappy has joined #ruby
12:18
<
depesz >
hi. having hash: {"key" => [1, 2,3,4], "other" => [5,6,7,8]} - is there any transformation that I could do to change it into: {"1" => "key", "2" => "key", …, "8" => "other"} ?
12:18
lutherann has quit [Ping timeout: 246 seconds]
12:19
lutherann has joined #ruby
12:23
user71 has joined #ruby
12:30
STASIdownunder has quit [Read error: Connection reset by peer]
13:01
GreenResponse has joined #ruby
13:19
cappy has quit [Quit: Leaving]
13:40
<
leftylink >
if you asked me to do this, I would flat_map then to_h the result
14:30
manny2 has joined #ruby
14:38
pages has quit [Remote host closed the connection]
14:40
pages has joined #ruby
14:40
hwpplayer1 has joined #ruby
14:45
manny2 has quit [Quit: Client closed]
14:46
manny81 has joined #ruby
14:49
STASIdownunder has joined #ruby
14:53
STASIdownunder has quit [Read error: Connection reset by peer]
14:54
user71 has quit [Quit: Leaving]
14:55
<
gr33n7007h >
depesz: h.each_with_object({}) { |(k, v), h| h[v.shift] = k until v.empty? }
14:56
<
havenwood >
Or the way leftylink mentioned usually pairs with an internal simple #map, but you can alternatively #zip.
14:56
<
havenwood >
h.flat_map { _2.zip([_1].cycle) }.to_h
14:57
<
gr33n7007h >
just about to note it'll mutate the original hash
14:59
<
havenwood >
h.flat_map { |key, values| values.map { |value| [value, key] } }.to_h
14:59
<
havenwood >
^ what I presumed with the original suggestion. Seems reasonable. :)
14:59
jmcantrell has joined #ruby
15:00
<
havenwood >
gr33n7007h: I'd probably just modify yours to iterate over values rather than shifting them.
15:01
<
havenwood >
h.each_with_object({}) { |(key, values), result| values.each { |value| result[value] = key } }
15:01
<
gr33n7007h >
havenwood: me too come to think of it =)
15:15
STASIdownunder has joined #ruby
15:29
STASIdownunder has quit [Read error: Connection reset by peer]
15:34
STASIdownunder has joined #ruby
15:36
user71 has joined #ruby
15:53
<
nakilon >
.flat_map{ |*k,v| k.product(v).map(&:reverse) }.to_h
15:54
<
nakilon >
.flat_map{ |*k,v| v.product k }.to_h
16:10
hwpplayer1 has quit [Quit: talk to you later Take care]
16:13
brokkoli_origin has quit [Remote host closed the connection]
16:17
brokkoli_origin has joined #ruby
16:18
<
depesz >
gr33n7007h: thanks.
16:18
<
depesz >
and leftylink , and havenwood :)
16:18
<
depesz >
and nakilon :)
16:31
graywolf has joined #ruby
16:47
hwpplayer1 has joined #ruby
16:55
TomyWork has joined #ruby
16:56
o0x1eef has quit [Ping timeout: 252 seconds]
16:59
o0x1eef has joined #ruby
16:59
wbooze has quit [Quit: Leaving]
17:09
graywolf has quit [Quit: WeeChat 4.6.0]
17:13
dstein64- has joined #ruby
17:15
dstein64 has quit [Ping timeout: 244 seconds]
17:15
dstein64- is now known as dstein64
17:16
fantazo has joined #ruby
17:28
weaksauce has quit [Ping timeout: 260 seconds]
17:29
manny81 has quit [Ping timeout: 240 seconds]
17:40
manny69 has joined #ruby
17:43
___nick___ has joined #ruby
17:52
weaksauce has joined #ruby
17:53
hwpplayer1 has quit [Quit: I gotta go]
18:01
___nick___ has quit [Ping timeout: 252 seconds]
18:13
___nick___ has joined #ruby
18:52
<
havenwood >
nakilon: I too often forget #product exists. That's nice.
18:52
<
havenwood >
h.flat_map{ _2.product([_1]) }.to_h
18:54
<
havenwood >
I don't mind positional arguments here since what's a key becomes a value, diluting any meaning.
18:57
<
havenwood >
Salves a method call from: h.flat_map { _2.zip([_1].cycle) }.to_h
18:57
<
havenwood >
And a bit of reduced cognitive overhead is nice.
19:43
Milos has quit [Ping timeout: 260 seconds]
20:04
___nick___ has quit [Ping timeout: 260 seconds]
20:12
Rounin has quit [Quit: Rounin]
20:16
user71 has quit [Quit: Leaving]
20:34
Rounin has joined #ruby
20:34
Rounin has quit [Changing host]
20:34
Rounin has joined #ruby
20:37
graywolf has joined #ruby
20:37
graywolf has quit [Client Quit]
21:00
jmcgnh has quit [Excess Flood]
21:08
jmcgnh has joined #ruby
21:16
Milos has joined #ruby
21:16
fantazo has quit [Quit: Lost terminal]
21:36
andy-turner has quit [Quit: Leaving]
22:00
ruby[bot] has quit [Remote host closed the connection]
22:00
ruby[bot] has joined #ruby
22:01
GreenResponse has quit [Quit: Leaving]
22:02
wbooze has joined #ruby
22:11
STASIdownunder has quit [Ping timeout: 252 seconds]
22:20
manny69 has quit [Ping timeout: 240 seconds]
22:41
hwpplayer1 has joined #ruby
22:53
hwpplayer1 has quit [Remote host closed the connection]
23:02
Guest53 has joined #ruby
23:07
Guest53 has quit [Quit: Client closed]
23:24
eddof13 has joined #ruby
23:40
smp has quit [Ping timeout: 260 seconds]
23:40
Pixi` has joined #ruby
23:42
smp has joined #ruby
23:43
Pixi has quit [Ping timeout: 244 seconds]
23:47
eddof13 has quit [Quit: eddof13]
23:50
eddof13 has joined #ruby
23:54
eddof13 has quit [Client Quit]