-
Notifications
You must be signed in to change notification settings - Fork 0
/
Common.fs
26 lines (20 loc) · 928 Bytes
/
Common.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
namespace FSharpCards.Common
module Random =
open System
///<summary>Return a randomly reordered version of the input sequence</summary>
let shuffler (r: Random) xs =
let nextRandom _ = r.Next()
xs |> Seq.sortBy nextRandom
module Reflection =
open Microsoft.FSharp.Reflection
/// <summary>
/// Return all values of a discriminated union as a sequence.
/// Original source: http://fssnip.net/7VM/title/Getting-a-sequence-of-all-union-cases-in-discriminated-union
/// </summary>
let getAllUnionCases<'T>() =
FSharpType.GetUnionCases(typeof<'T>)
|> Seq.map (fun x -> FSharpValue.MakeUnion(x, Array.zeroCreate(x.GetFields().Length)) :?> 'T)
module Collections =
///<summary>Sort by descending using the supplied function and take the first result</summary>
let sortDescendingTakeFirst fn =
List.sortByDescending fn >> List.truncate 1