[Haskell-cafe] version sorting?
javran.c at gmail.com
Sat Dec 8 01:47:44 UTC 2018
I'm wondering if there's any existing packages that do "version sorting":
as an example, for a list like:
["foo-10.20", "foo-1.2", "foo-2.100", "foo-1.12"]
I'd like the result to be:
["foo-1.2", "foo-1.12", "foo-2.100", "foo-10.20"]
I could think of an implementation that turns String elements of a list into
[Either Int String] by grouping consecutive chunks using span and isDigit
and then do a sortOn:
versionSort :: [String] -> [String]
versionSort = sortOn brkND
tr f g (x,y) = f x : g y
-- ND for non-digits
brkND = tr Right brkD . span (not . isDigit)
brkD = tr (Left . read @Int) brkND . span isDigit
(side question: does the helper function tr I defined above have a commonly
just wondering if there are more sophisticated solutions available.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe