In F#, comparison operations such as sorting expects the generic IComparable interface and not IComparable<T>. To sort by SemVer in F# you'd have to do something like this:
Wrap Version in a thing implementing IComparable:
[<CustomEquality;CustomComparison>]
type ComparableVersion =
{ Version : Version }
static member create version =
{ Version = version }
override x.Equals(yObj) =
match yObj with
| :? ComparableVersion as y -> x.Version.Equals(y.Version)
| _ -> invalidArg "yObj" "Type must be a ComparableVersion"
override x.GetHashCode() = x.Version.GetHashCode()
interface System.IComparable with
member x.CompareTo yObj =
match yObj with
| :? ComparableVersion as y -> x.Version.CompareTo(y.Version)
| _ -> invalidArg "yObj" "Type must be a ComparableVersion"
Then you can sortBy like this:
|> Seq.sortBy (fun v -> Version(Path.GetFileNameWithoutExtension f) |> ComparableVersion.create)
In F#, comparison operations such as sorting expects the generic
IComparable
interface and notIComparable<T>
. To sort by SemVer in F# you'd have to do something like this:Wrap Version in a thing implementing IComparable:
Then you can sortBy like this: