janet-lang / spork

Various Janet utility modules - the official "Contrib" library.
MIT License
117 stars 35 forks source link

Add `merge-sorted`, `merge-sorted-by` #149

Closed primo-ppcg closed 1 year ago

primo-ppcg commented 1 year ago

Related: #147

Adds misc/merge-sorted and misc/merge-sorted-by to merge two arrays which are known to be in sorted order.

This is more convenient, and also faster than either:

sogaiu commented 1 year ago

The associated tests seem to work here (Linux) :+1:


I guess until https://github.com/janet-lang/spork/pull/148 is merged we will be seeing an unrelated failure during testing.

primo-ppcg commented 1 year ago

A side note: the parameter order for merge-sorted-by is consistent with insert-sorted-by. However, both are inconsistent with the core function sorted-by (or every -by function for that matter, the first parameter is always f).

It's probably better for parameter order to be consistent within a module, but perhaps both should be updated.