Human_G33k has quit [Read error: Connection reset by peer]
HumanG33k has joined #crystal-lang
renich has joined #crystal-lang
<oprypin>
@throwaway4rust: nothing happening
renich has quit [Quit: Leaving.]
renich has joined #crystal-lang
renich has quit [Ping timeout: 258 seconds]
Stephie- is now known as Stephie
renich has joined #crystal-lang
renich has quit [Ping timeout: 260 seconds]
renich has joined #crystal-lang
<FromGitter>
<error256> Hello. Is this a bug or how do I use `cons_pair`? ⏎ ⏎ ```[1, 2, 3].each.cons_pair.each{ |x, y| x + y }``` ⏎ ⏎ `Error: no overload matches 'Int32#+' with type (Int32 | Iterator::Stop)` [https://gitter.im/crystal-lang/crystal?at=5f763a8efcce3e6c18e7a8dd]
<FromGitter>
<error256> I want to get an Iterator, it's just a minimum example with `each`. It could as well be ⏎ ⏎ ```[1, 2, 3].each.cons_pair.to_a``` ⏎ ⏎ `Error: no overload matches 'Array(Tuple(Int32, Int32))#<<' with type Tuple(Int32 | Iterator::Stop, Int32 | Iterator::Stop)` [https://gitter.im/crystal-lang/crystal?at=5f763b25daf8227643af3893]
<FromGitter>
<Blacksmoke16> i think the problem is `x` or `y` can be `Iterator::Stop` that means there are no more values
<FromGitter>
<Blacksmoke16> hence the error in the first example
<FromGitter>
<error256> I understand this, but I think `Iterator::Stop` isn't supposed to be inside the tuple? When the source iterator ends, the result ends too.
<FromGitter>
<error256> If `Iterator::Stop` in the tuple is normal, in what case can it happen?
<FromGitter>
<Blacksmoke16> i wouldnt think it would be an actual value, but the var that gets yielded is typed as either `Int32` or that
<FromGitter>
<Blacksmoke16> so id imagine thats the problem
<FromGitter>
<Blacksmoke16> maybe worth a forum post?
<FromGitter>
<Blacksmoke16> actually
<FromGitter>
<error256> I'd say it's worth a GitHub issue because the type clearly isn't what it should be. I'm just not exactly sure where the bug is... `cons_pair` is declared as `def cons_pair : Iterator({T, T})`, so at this point `T` already is `Int32 | Iterator::Stop`. Is it `each`?...
<FromGitter>
<Blacksmoke16> my guess is that since the value is a tuple its getting past the check that should break and prevent the stop value from being yielded
alexherbo2 has quit [Ping timeout: 265 seconds]
alexherbo29 is now known as alexherbo2
<FromGitter>
<Daniel-Worrall> It's an `Iterator(Tuple(T, T))`, yes, but that Iterator can return `Tuple(T, T) | Iterator::Stop::INSTANCE` on `#next`
<FromGitter>
<Daniel-Worrall> which is what `#each` and therefore `#to_a` use
<FromGitter>
<Blacksmoke16> yup
<raz>
yup
<raz>
i would assume #each_cons_pair exists exactly because of that oddity
<FromGitter>
<Blacksmoke16> i tend to agree, whats the point of using an iterator in this context?
<FromGitter>
<Blacksmoke16> but still not ideal
<raz>
iterating over pairs can be useful sometimes.
<FromGitter>
<Blacksmoke16> sure, but based on the examples provided so far its not giving any benefit
<raz>
well, i imagine he simplified them for the sake of irc ;)
<FromGitter>
<Blacksmoke16> `arr.each.each_cons.each do |a, b|` isnt any better than `arr.each_cons_pair do |a, b`
<FromGitter>
<Blacksmoke16> probably :p
<raz>
but yup agree. the two methods seem to do the exact same. having to remember to use the right one depending on the input isn't nice, but doesn't seem too terrible to me
<FromGitter>
<Blacksmoke16> normally the convention is there is a non block overload that returns the iterator
<FromGitter>
<Blacksmoke16> wonder why this one is diff (of if there even is a reason)
<raz>
well, tuples are always weird
<raz>
tuples and symbols
<FromGitter>
<Blacksmoke16> boo symbols
<raz>
i have a theory tho! <einstein-face>
<raz>
so, Iterator::Stop seems to leak into both sides of the tuple: Tuple(Int32 | Iterator::Stop, Int32 | Iterator::Stop)
<raz>
i suspect, it might be using *two* each'es under the hood. kinda like the double slit experiment.