-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: test-matrix: natural sort by job description
Small thing, but sorts jdk8 before jdk11 which makes github actions workflow job listing easier to follow.
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
;; Thanks to https://gist.github.com/wilkerlucio/db54dc83a9664124f3febf6356f04509 | ||
(ns helper.natural-sort | ||
(:refer-clojure :exclude [sort sort-by]) | ||
(:require [clojure.string])) | ||
|
||
(defn vector-compare [[value1 & rest1] [value2 & rest2]] | ||
(let [result (compare value1 value2)] | ||
(cond | ||
(not (zero? result)) result | ||
(nil? value1) 0 | ||
:else (recur rest1 rest2)))) | ||
|
||
(defn prepare-string [s] | ||
(let [s (or s "") | ||
parts (vec (clojure.string/split s #"\d+")) | ||
numbers (->> (re-seq #"\d+" s) | ||
(map parse-long) | ||
(vec))] | ||
(vec (interleave (conj parts "") (conj numbers -1))))) | ||
|
||
(defn natural-compare [a b] | ||
(vector-compare (prepare-string a) | ||
(prepare-string b))) | ||
|
||
(defn sort [coll] (clojure.core/sort natural-compare coll)) | ||
|
||
(defn sort-by [keyfn coll] | ||
(clojure.core/sort-by keyfn natural-compare coll)) |
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