havenwood changed the topic of #ruby to: Ruby 3.4.2, 3.3.7 https://www.ruby-lang.org | Log https://libera.irclog.whitequark.org/ruby
ih8u has quit [Ping timeout: 268 seconds]
hwpplayer1 has joined #ruby
o0x1eef has quit [Ping timeout: 272 seconds]
o0x1eef has joined #ruby
hwpplayer1 has quit [Remote host closed the connection]
pages has joined #ruby
CRISPR has joined #ruby
cappy has joined #ruby
jmcantrell has quit [Quit: WeeChat 4.6.0]
levitating has joined #ruby
CRISPR has quit [Ping timeout: 272 seconds]
levitating has quit [Remote host closed the connection]
cappy has quit [Quit: Leaving]
gemmaro_ has quit [Ping timeout: 260 seconds]
gemmaro has joined #ruby
jmcgnh has quit [Remote host closed the connection]
jmcgnh has joined #ruby
grenierm has joined #ruby
STASIdownunder has quit [Ping timeout: 265 seconds]
andy-turner has joined #ruby
rvalue has quit [Read error: Connection reset by peer]
rvalue has joined #ruby
STASIdownunder has joined #ruby
STASIdownunder has quit [Read error: Connection reset by peer]
STASIdownunder has joined #ruby
Quiet-Oil9262 has quit [Quit: The Lounge - https://thelounge.chat]
Quiet-Oil9262 has joined #ruby
STASIdownunder has quit [Read error: Connection reset by peer]
STASIdownunder has joined #ruby
STASIdownunder has quit [Read error: Connection reset by peer]
STASIdownunder has joined #ruby
STASIdownunder has quit [Read error: Connection reset by peer]
STASIdownunder has joined #ruby
STASIdownunder has quit [Read error: Connection reset by peer]
STASIdownunder has joined #ruby
STASIdownunder has quit [Read error: Connection reset by peer]
Quiet-Oil9262 has quit [Quit: The Lounge - https://thelounge.chat]
Quiet-Oil9262 has joined #ruby
STASIdownunder has joined #ruby
STASIdownunder has quit [Read error: Connection reset by peer]
grenierm has quit [Ping timeout: 240 seconds]
STASIdownunder has joined #ruby
STASIdownunder has quit [Read error: Connection reset by peer]
Milos has quit [Quit: ZNC 1.9.1 - https://znc.in]
STASIdownunder has joined #ruby
Milos has joined #ruby
STASIdownunder has quit [Read error: Connection reset by peer]
STASIdownunder has joined #ruby
cappy has joined #ruby
<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"} ?
lutherann has quit [Ping timeout: 246 seconds]
lutherann has joined #ruby
user71 has joined #ruby
STASIdownunder has quit [Read error: Connection reset by peer]
GreenResponse has joined #ruby
cappy has quit [Quit: Leaving]
<leftylink> if you asked me to do this, I would flat_map then to_h the result
manny2 has joined #ruby
pages has quit [Remote host closed the connection]
pages has joined #ruby
hwpplayer1 has joined #ruby
manny2 has quit [Quit: Client closed]
manny81 has joined #ruby
STASIdownunder has joined #ruby
STASIdownunder has quit [Read error: Connection reset by peer]
user71 has quit [Quit: Leaving]
<gr33n7007h> depesz: h.each_with_object({}) { |(k, v), h| h[v.shift] = k until v.empty? }
<havenwood> Or the way leftylink mentioned usually pairs with an internal simple #map, but you can alternatively #zip.
<havenwood> h.flat_map { _2.zip([_1].cycle) }.to_h
<gr33n7007h> just about to note it'll mutate the original hash
<havenwood> h.flat_map { |key, values| values.map { |value| [value, key] } }.to_h
<havenwood> ^ what I presumed with the original suggestion. Seems reasonable. :)
jmcantrell has joined #ruby
<havenwood> gr33n7007h: I'd probably just modify yours to iterate over values rather than shifting them.
<havenwood> h.each_with_object({}) { |(key, values), result| values.each { |value| result[value] = key } }
<gr33n7007h> havenwood: me too come to think of it =)
STASIdownunder has joined #ruby
STASIdownunder has quit [Read error: Connection reset by peer]
STASIdownunder has joined #ruby
user71 has joined #ruby
<nakilon> .flat_map{ |*k,v| k.product(v).map(&:reverse) }.to_h
<nakilon> oh wait
<nakilon> .flat_map{ |*k,v| v.product k }.to_h
hwpplayer1 has quit [Quit: talk to you later Take care]
brokkoli_origin has quit [Remote host closed the connection]
brokkoli_origin has joined #ruby
<depesz> gr33n7007h: thanks.
<depesz> and leftylink , and havenwood :)
<depesz> and nakilon :)
graywolf has joined #ruby
hwpplayer1 has joined #ruby
TomyWork has joined #ruby
o0x1eef has quit [Ping timeout: 252 seconds]
o0x1eef has joined #ruby
wbooze has quit [Quit: Leaving]
graywolf has quit [Quit: WeeChat 4.6.0]
dstein64- has joined #ruby
dstein64 has quit [Ping timeout: 244 seconds]
dstein64- is now known as dstein64
fantazo has joined #ruby
weaksauce has quit [Ping timeout: 260 seconds]
manny81 has quit [Ping timeout: 240 seconds]
manny69 has joined #ruby
___nick___ has joined #ruby
weaksauce has joined #ruby
hwpplayer1 has quit [Quit: I gotta go]
___nick___ has quit [Ping timeout: 252 seconds]
___nick___ has joined #ruby
<havenwood> nakilon: I too often forget #product exists. That's nice.
<havenwood> h.flat_map{ _2.product([_1]) }.to_h
<havenwood> I don't mind positional arguments here since what's a key becomes a value, diluting any meaning.
<havenwood> Salves a method call from: h.flat_map { _2.zip([_1].cycle) }.to_h
<havenwood> And a bit of reduced cognitive overhead is nice.
Milos has quit [Ping timeout: 260 seconds]
___nick___ has quit [Ping timeout: 260 seconds]
Rounin has quit [Quit: Rounin]
user71 has quit [Quit: Leaving]
Rounin has joined #ruby
Rounin has quit [Changing host]
Rounin has joined #ruby
graywolf has joined #ruby
graywolf has quit [Client Quit]
jmcgnh has quit [Excess Flood]
jmcgnh has joined #ruby
Milos has joined #ruby
fantazo has quit [Quit: Lost terminal]
andy-turner has quit [Quit: Leaving]
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
GreenResponse has quit [Quit: Leaving]
wbooze has joined #ruby
STASIdownunder has quit [Ping timeout: 252 seconds]
manny69 has quit [Ping timeout: 240 seconds]
hwpplayer1 has joined #ruby
hwpplayer1 has quit [Remote host closed the connection]
Guest53 has joined #ruby
Guest53 has quit [Quit: Client closed]
eddof13 has joined #ruby
smp has quit [Ping timeout: 260 seconds]
Pixi` has joined #ruby
smp has joined #ruby
Pixi has quit [Ping timeout: 244 seconds]
eddof13 has quit [Quit: eddof13]
eddof13 has joined #ruby
eddof13 has quit [Client Quit]