Last active
August 24, 2016 07:29
-
-
Save bzar/13c0bef5d65f42cc874269b4117db4d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{reverse, sum, empty, all, fold, concat-map, flatten, span, Obj, sort-by, head} = require 'prelude-ls' | |
# [[String]] -> Bool | |
in-order = (xss) -> all (-> it.length == 1), xss | |
# [[String] -> Data -> [[String]]] -> Data -> [String] -> [[String]] | |
order-by-one = (fs, d, xs) --> | |
| xs.length < 2 => [xs] | |
| otherwise => | |
fold ((ys, f) -> if ys.length == 1 then f(ys[0], d) else ys), [xs], fs | |
# [[String] -> Data -> [[String]]] -> [[String]] -> Data -> [[String]] | |
order-by-many = (fs, xss, d) -> | |
let yss = concat-map order-by-one(fs, d), xss | |
switch | |
| yss.length == xss.length => flatten yss | |
| in-order yss => flatten yss | |
| otherwise => order-by-many fs, yss, d | |
# [[String] -> Data -> [[String]]] -> [String] -> Data -> [String] | |
multisort = (fs, xs, d) -> order-by-many fs, [xs], d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment