johnny101 has quit [Read error: Connection reset by peer]
_ht has joined #crystal-lang
<FromGitter>
<HertzDevil> is there a reason `while` expressions don't return the value in a `break`
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Client Quit]
alexherbo2 has joined #crystal-lang
hendursaga has joined #crystal-lang
hendursa1 has quit [Ping timeout: 268 seconds]
DTZUZU has quit [Read error: Connection reset by peer]
DTZUZU has joined #crystal-lang
<FromGitter>
<naqvis> I believe that's intentional and reference doc states the same ⏎ ⏎ > A while's type is always Nil. ⏎ ⏎ Crystal isn't the only one, Scala `while` expression also always return `Unit` [https://gitter.im/crystal-lang/crystal?at=6034d28f9ba13e72e44a1449]
<FromGitter>
<naqvis> if one need to return value from looping expression then `loop` construct is the choice
<FromGitter>
<HertzDevil> that's different
<FromGitter>
<HertzDevil> `loop` opens a new scope and `while` doesn't
<FromGitter>
<naqvis> true, as `loop` is just a stdlib method a wrapper against `while` which invokes the block provided
<FromGitter>
<Blacksmoke16> does `STDIN.blocking = false` do anything?
<straight-shoota>
if that call blocks, stdin is open and waiting for input
<straight-shoota>
you can't know if it has any content unless it's closed
<straight-shoota>
for example, when stdin is a tty and you run your program, the shell will forward everything you write to the program
<straight-shoota>
you can write something directly or after three hours
<straight-shoota>
the program trying to read from stdin will block until you write something
<straight-shoota>
or close the stream
<FromGitter>
<asterite> @HertzDevil I didn't know in `while` the `break` gave the value to it, that's why it doesn't behave like in Ruby. But it could/should
<FromGitter>
<HertzDevil> okay
<FromGitter>
<asterite> I actually think `break` with a value is very useful, to avoid having a separate boolean like "found" that you initialize to `false` and then set in the middle of the loop just before a `break`
<FromGitter>
<HertzDevil> that's what i was thinking, but also if the whole `while` is in a condition (e.g. from a macro) then perhaps we could do flow typing with it
<FromGitter>
<HertzDevil> actually when i did the `TypeFilters` thing i thought of extending it to arbitrary nested `if`s
<FromGitter>
<asterite> That snippet doesn't work already?
<FromGitter>
<RespiteSage> So the perceived benefits of `break` taking a value and using it as the return type of the loop is 1) to be more like Ruby, and 2) to type less?
<FromGitter>
<naqvis> I would say its 1), as Rubyism takes all precedence :P. Though I still can't get my head off around returning a value from a while loop. As after having this feature implemented while will always return a Union of `Type | Nil`
<straight-shoota>
Yeah but this is just like `each |i| break i if ... end`
<straight-shoota>
the return type is also `typeof(i) | Nil`
<straight-shoota>
It would only make sense that `break` can receive arguments just like `next` or `return`. They're all similar concepts
<straight-shoota>
and it already works in blocks, so why not with `while`
<FromGitter>
<asterite> Also `while` without `break`, or with `break` without a value will still have the `Nil` type. It's just when you break with a value that it will be different
<straight-shoota>
exactly
<straight-shoota>
it's just concistent with all existing behaviour
dostoyevsky has quit [Ping timeout: 246 seconds]
dostoyevsky has joined #crystal-lang
tskalyo has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
hpyc9 has quit [Quit: 420]
hpyc9 has joined #crystal-lang
hendursaga has quit [Ping timeout: 268 seconds]
_ht has quit [Remote host closed the connection]
hendursaga has joined #crystal-lang
r0bby has quit [Ping timeout: 265 seconds]
sz0 has quit [Ping timeout: 264 seconds]
r0bby has joined #crystal-lang
sz0 has joined #crystal-lang
<FromGitter>
<jrei:matrix.org> strange question: where are the spec method in the API docs?
<FromGitter>
<jrei:matrix.org> I mean, `it`, `describe`