Created
November 2, 2011 15:22
-
-
Save einblicker/1333909 to your computer and use it in GitHub Desktop.
mixed sort
This file contains hidden or 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
import scalaz.Scalaz._ | |
import scalaz.Order._ | |
import util.control.Exception.allCatch | |
val RE = """(\d+)|([^\d]+)""".r | |
def s2i(s: String): Iterable[Either[String, Int]] = | |
RE.findAllIn(s).map{ s => | |
allCatch.either(s.toInt).left.map(_ => s) | |
}.++(Iterator(Left("dummy"))).toIterable | |
def mixedSort(xs: Seq[String]) = | |
xs.sorted(OrderOrdering(order(s2i(_:String) ?|? s2i(_:String)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment