#72Array methods

  • avatar~lino-levancommented · 2 years ago
    Author

    Now that arrays have been added, making them useful via array methods would be great.

    First pass:

    • truncate(length)
    • insert(index, item)
    • remove(index)
    • push(item)
    • pop(item)
    • append(list) - maybe, let's think if we want this to be an operation like this or if we want a concat operator
    • clear()
    • len()
    • is_empty()
    • flatten()
    • swap(a,b)
    • reverse()

    Second pass:

    • first() - Returns Option
    • last() - Returns Option
    • get(index) - Returns Option

    Under consideration (we basically need the concept of "slices"):

    • split_off(index) - split array into two arrays at index
    • split_first() - Option<(first, rest of array)>
    • split_last()
    • All the weird chunk methods

    Up for debate:

    • splice - not sure what semantics would be. if we have ranges, we should follow rust conventions
    • sort - not sure what semantics would be, probably different than js sort though

    Milestone: later.

  • avatar~lino-levan changed the status to Todo · 2 years ago
  • avatar~clovercommented · 2 years ago
    Owner

    i think all of these methods are reasonable. implementing these is 99% an organization task; it would be smarter to wait until a trait system is implemented. Then the methods can be added there (under something like [](infer Item)). I have not really thought about how the trait system will work, especially considering incremental.

    stuff like sort should think about Array.prototype.sort and ensuring that the interface that it provides maps well. that doesn't mean the interface has to be the same.

  • avatar~lino-levancommented · 2 years ago
    Author

    stuff like sort should think about Array.prototype.sort and ensuring that the interface that it provides maps well. that doesn't mean the interface has to be the same.

    Agreed, it should sort of map over. That being said, WL .sort should work on numerical arrays the way you expect