-- srt fn xs: sort xs by the key returned by `fn`.
-- The 2-arg form pipes each element through `fn` and sorts by that key.
-- Signature: srt fn:F a k xs:L a > L a
-- Key: absolute value, so [-3,1,-2] sorts to [1,-2,-3].
absv n:n>n;?<n 0 (-0 n) n
by-abs xs:L n>L n;srt absv xs
-- Key: string length, shortest first.
slen s:t>n;len s
by-len ws:L t>L t;srt slen ws
-- engine-skip: jit
-- run: by-abs [-3,1,-2,4,-1]
-- out: [1, -1, -2, -3, 4]
-- run: by-len ["banana","fig","apple"]
-- out: [fig, apple, banana]