Ad
  • Custom User Avatar

    Yes, that's correct and certainly a bug. In extreme cases it might even turn a terminating computation into non-terminating. Annoying n-plus-a-half loop strikes again. Easy to fix, but turns the code into a mess anyway. :)

  • Custom User Avatar

    Great solution!

    But I think, it has one sneaky problem.
    Your takeS will actually compute one more element than needed. This might be a problem, i.e. if the stream is exausted.