DennisMitchell / jellylanguage

Jelly is a recreational programming language inspired by J.
MIT License
863 stars 45 forks source link

Fixed a bug with œṡ #82

Closed Mr-Xcoder closed 6 years ago

Mr-Xcoder commented 6 years ago

Previously, œṡ had a weird behaviour if y didn't occur in x. That is, it discarded the last element and wrapped the result in a list along with an empty list at the end (i.e. [x[:-1], []]). Now, it just returns [x], which seems more intuitive. Let me know if this causes any issues / the old behaviour is intended.

DennisMitchell commented 6 years ago

That will raise a TypeError if array isn't iterable.

To fix that and avoid going twice through the array, the function could simply do this:

def split_once(array, needle):
    array = iterable(array, make_digits = True)
    index = index_of(array, needle)
    return [array[0 : index - 1], array[index :]] if index else [array]