sortBy package:streamly-core

Sort the input stream using a supplied comparison function. Sorting can be achieved by simply:
>>> sortBy cmp = StreamK.mergeMapWith (StreamK.mergeBy cmp) StreamK.fromPure
However, this combinator uses a parser to first split the input stream into down and up sorted segments and then merges them to optimize sorting when pre-sorted sequences exist in the input stream. O(n) space