havenwood changed the topic of #ruby to: Ruby 3.3.6 (3.4.0-rc1) https://www.ruby-lang.org | Log https://libera.irclog.whitequark.org/ruby
jmcantrell has joined #ruby
jmcantrell is now known as Guest9888
Guest9888 has quit [Killed (osmium.libera.chat (Nickname regained by services))]
jmcantrell_ has joined #ruby
Linux_Kerio has quit [Ping timeout: 248 seconds]
jmcantrell has quit [Ping timeout: 248 seconds]
jmcantrell_ is now known as jmcantrell
cappy has joined #ruby
whysthatso125070 has quit [Read error: Connection reset by peer]
whysthatso125070 has joined #ruby
konsolebox has joined #ruby
konsolebox has quit [Ping timeout: 250 seconds]
rvalue has joined #ruby
konsolebox has joined #ruby
__jmcantrell__ has joined #ruby
jmcantrell is now known as Guest4832
Guest4832 has quit [Killed (molybdenum.libera.chat (Nickname regained by services))]
__jmcantrell__ is now known as jmcantrell
jmcantrell_ has joined #ruby
snoojin has joined #ruby
jhass has quit [Remote host closed the connection]
jhass has joined #ruby
konsolebox has quit [Quit: .]
cappy has quit [Quit: Leaving]
konsolebox has joined #ruby
ih8u2 has quit [Remote host closed the connection]
ih8u2 has joined #ruby
Fridtjof has quit [Quit: ZNC - http://znc.in]
zayd is now known as Guest6873
Fridtjof has joined #ruby
konsolebox has quit [Ping timeout: 250 seconds]
snoojin has quit [Quit: Connection closed for inactivity]
R2robot has quit [Quit: Pull the lever, Kronk. Wrong leverrrrrrr!]
grenierm has joined #ruby
R2robot has joined #ruby
konsolebox has joined #ruby
<leftylink> so if you `break` in the middle of e.g. a `map`, you don't get a result. is there a way to `break` but still get the results that had been up to that point?
<leftylink> pandabot: rb [1, 2, 3, 4, 5].map { |x| x == 4 ? break : x } == [1, 2, 3]
<pandabot> false - https://carc.in/#/r/higs
<leftylink> it would be great if I could get that to work
<leftylink> I... I *guess* take_while is acceptable?????????
<leftylink> pandabot: rb [1, 2, 3, 4, 5].take_while { _1 < 4 }.map(&:itself)
<pandabot> [1, 2, 3] - https://carc.in/#/r/higt
<leftylink> sure
___nick___ has joined #ruby
___nick___ has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
<o0x1eef> Or use 'next' instead of 'break'. 'next' will return 'nil' in its place, then you could filter those results with .compact or filter_map.
___nick___ has joined #ruby
___nick___ has quit [Client Quit]
___nick___ has joined #ruby
user71 has joined #ruby
Linux_Kerio has joined #ruby
sarna has quit [Remote host closed the connection]
sarna has joined #ruby
<gr33n7007h> >> [1, 2, 3, 4, 5].slice_before { |x| x == 4 }.first
<ruby[bot]> gr33n7007h: # => [1, 2, 3] (https://carc.in/#/r/higu)
ih8u3 has joined #ruby
ih8u2 has quit [Ping timeout: 260 seconds]
ih8u3 is now known as ih8u2
<gr33n7007h> whack on a lazy too if the collection is rather large, so it isn't iterating the entire array.
<havenwood> leftylink: You can drop the: .map(&:itself)
konsolebox has quit [Quit: .]
<havenwood> I admit, I like the 3.4 `it` when a single letter variable or `_1` would be used otherwise. 😊
<havenwood> (1..).take_while { it < 4 }
<gr33n7007h> havenwood: kokubun was relentless in making sure `it` made it in 3.4 :P
<gr33n7007h> i admit, i do prefer it to _1
jmcantrell has quit [Ping timeout: 276 seconds]
jmcantrell_ is now known as jmcantrell
grenierm has quit [Ping timeout: 240 seconds]
MyNetAz has quit [Remote host closed the connection]
MyNetAz has joined #ruby
konsolebox has joined #ruby
___nick___ has quit [Ping timeout: 252 seconds]
___nick___ has joined #ruby
MsInput has quit [Quit: WeeChat 4.4.4]
konsolebox has quit [Ping timeout: 276 seconds]
___nick___ has quit [Ping timeout: 248 seconds]
___nick___ has joined #ruby
konsolebox has joined #ruby
user71 has quit [Quit: Leaving]
donofrio has joined #ruby
donofrio has quit [Ping timeout: 244 seconds]
JulioPapel has joined #ruby
JulioPapel has quit [Client Quit]
konsolebox has quit [Quit: .]
rvalue has quit [Read error: Connection reset by peer]
rvalue has joined #ruby
Tempesta has quit [Quit: See ya!]
user71 has joined #ruby
___nick___ has quit [Ping timeout: 244 seconds]
___nick___ has joined #ruby
<o0x1eef> >> [1, 2,3 4,5
<ruby[bot]> o0x1eef: # => (https://carc.in/#/r/hihi)
<o0x1eef> >> [1, 2,3 4, 5].filter_map { x == 4 ? next : x }
<ruby[bot]> o0x1eef: # => (https://carc.in/#/r/hihj)
<o0x1eef> >> [1, 2,3, 4, 5].filter_map { |x| x < 4 ? x : next }
<ruby[bot]> o0x1eef: # => [1, 2, 3] (https://carc.in/#/r/hihk)
<o0x1eef> >> [1, 2, 3, 4, 5].filter_map { |x| x < 4 }
<ruby[bot]> o0x1eef: # => [true, true, true] (https://carc.in/#/r/hihl)
<o0x1eef> Yeah, I prefer the other alternatives :)
<o0x1eef> If I had to use filter_map I'd replace 'next' with 'nil'
<o0x1eef> I guess the most old school way to express that is: [1,2,3,4,5].select { |x| x < 4 }
Tempesta has joined #ruby
___nick___ has quit [Ping timeout: 244 seconds]
___nick___ has joined #ruby
jardsonto has quit [Ping timeout: 248 seconds]
cappy has joined #ruby
johnjaye has quit [Ping timeout: 244 seconds]
jardsonto has joined #ruby
cappy has quit [Ping timeout: 246 seconds]
___nick___ has quit [Ping timeout: 252 seconds]
___nick___ has joined #ruby
MyNetAz has quit [Read error: Connection reset by peer]
MyNetAz has joined #ruby
___nick___ has quit [Ping timeout: 248 seconds]
r3m has quit [Quit: WeeChat 4.5.0-dev]
r3m has joined #ruby
donofrio has joined #ruby
c10l has joined #ruby
donofrio has quit [Ping timeout: 248 seconds]
Linux_Kerio has quit [Ping timeout: 260 seconds]
hansolo has quit [Ping timeout: 244 seconds]
SaveFerris has quit [Quit: The Lounge - https://thelounge.chat]
SaveFerris has joined #ruby
jmcantrell has joined #ruby
jmcantrell has quit [Killed (tantalum.libera.chat (Nickname regained by services))]
jmcantrell_ has joined #ruby
hansolo has joined #ruby
user71 has quit [Quit: Leaving]
smp_ has joined #ruby
smp has quit [Ping timeout: 276 seconds]
smp_ is now known as smp
Starfoxxes has joined #ruby
snoojin has joined #ruby
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
cappy has joined #ruby
<gr33n7007h> o0x1eef: why spoil a good method by telling the truth?
<o0x1eef> :))