Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Iterator#uniq with block #3808

Merged
merged 1 commit into from Dec 30, 2016
Merged

Conversation

maiha
Copy link
Contributor

@maiha maiha commented Dec 30, 2016

Current implementation works only with block : T -> T, otherwise it breaks.

master : Crystal 0.20.3+40 [a62dff3] (2016-12-30)

(1..3).each.uniq(&.+ 1).next   # => 1
(1..3).each.uniq(&.even?).next
instantiating 'Iterator::Uniq(Range::ItemIterator(Int32, Int32), Int32, Bool)#next()'
in /home/maiha/git/maiha/crystal/src/iterator.cr:1025: no overload matches 'Hash(Int32, Bool)#[]=' with types Bool, Bool
Overloads are:
 - Hash(K, V)#[]=(key : K, value : V)

          @hash[transformed] = true

This PR : Crystal 0.20.3+41 [d9fca7b] (2016-12-30)

  • Fixed code to keep flags with U
  • Fixed spec to use block T -> U rather than T -> T
(1..3).each.uniq(&.+ 1).next   # => 1
(1..3).each.uniq(&.even?).next # => 1

Thanks.

@asterite
Copy link
Member

Good catch, thank you! ❤️

@asterite asterite merged commit cbaccf8 into crystal-lang:master Dec 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants