5 kyu

Iterators

Description
Loading description...
Algorithms
Data Structures
  • Please sign in or sign up to leave a comment.
  • RockfordWei Avatar

    this part looks confusing, as my code already passed most other tests: "Map([10, 11, 12, 13, 14, 15], multiply_by_2)[next_0] after the underlying forward-iterator was advanced twice: 20 should equal 24" please give the example in detail. thanks.

  • ieio Avatar

    Attempt fails with: 3_should_map_lazily "Infinite loop triggered by eager evaluation"

    Can you give me some hints? Thanx.

  • nomennescio Avatar

    Shouldn't the test not allocate a buffer away from the stack? If the user messes up, he now also gets messed up error reporting. That should not happen.

  • nomennescio Avatar

    What's the size of the integers in enumerate? It's not specced, but they should be 'tightly packed'.

  • nomennescio Avatar

    Issue in the test; reported Zip([1, 2, 3, 4], Zip(Zip([10, 20, 30, 40], [100, 200, 300, 400]), [1000, 2000, 3000, 4000]))[next_0]: ....... should equal [1000, 10, 100, 1000] Shouldn't that be [1,10,100,1000]?

  • nomennescio Avatar

    And why do you need to allocate a buffer for MapFunction, if iterate_next already gives you a pointer to an output buffer? I think that's unclear from the description.

  • nomennescio Avatar

    If MapFunction writes to an output buffer, without having the size of the output buffer as argument (hence the size is internal to the function), what's the use of the third argument to iterator_map? Note that the pseudocode for map is not helpful at all, first because it does not use an iterator as first argument, and second because it does NOT use the size argument at all.

  • donaldsebleung Avatar

    Not sure if it's too late for this Kata (but then, there are only 18 completions at the time of writing), but IMO it could be made even better if the iterator could be initialized as an infinite sequence of successive natural numbers (modulo ULLONG_MAX + 1?). Because then, one can construct arbitrary infinite sequences by combining said infinite sequence with a MapFunction. After all, a major advantage of iterators is their ability to model infinite sequences due to their lazy evaluation.

  • donaldsebleung Avatar

    A well-written and enjoyable Kata, thank you!

  • kazah96 Avatar

    Yes, this is average 5kuy kata, no less)

  • hobovsky Avatar

    Issue similar to the one below, but related to zip and enumerate: it's not explained how "composite return values" should be returned via the output void* pointer. It's not clear what caller expects the underlying buffer to look like: should items be just memcpy'ed one immediately after another, or maybe the buffer provides some guarantees on alignment, or maybe it points to some kind of structure?

    The note already explains this in the specific context of MapFunction and FilterFunction so it's probably reasonable to expect next to behave in similar way for zip and enumerate, but I think it would be useful to mention this explicitly.

  • Unnamed Avatar

    Alignment requirements for the arguments of MapFunction and FilterFunction and alignment guarantees for the argument of iterator_next aren't clear. In particular, the sample tests suggest that it isn't safe to pass output pointers from iterator_next unaligned pointers to map/filter functions, which isn't mentioned in the description.

  • Unnamed Avatar

    typedef int (*FilterFunction)(const void *);

    Why not _Bool aka bool in 2021?

  • ZED.CWT Avatar
    t6_should_allow_arbitrary_iterator_nesting
    Test Passed
    Arbitrarily-nested iterator: 144 should equal 303
    

    This message does not help for debugging

  • dfhwze Avatar

    Are we supposed to add fields and derive types from this?

    typedef struct iterator Iterator;
  • user9644768 Avatar

    Can you give example in the description on how the iterator would differ from simple returning the pointer?

    By looking at this example:

    Forward([1, 2, 3, 4])  ->  [1, 2, 3, 4]
    

    It seems to me that there is no difference, as all I've to do is simply return the array.


    Edit: The analogy with python without giving concrete example won't work, because for instance in python map object is returned instead of the array.