-
-
Save swlaschin/4e4d1b3323d120983299d21c6203e2dc to your computer and use it in GitHub Desktop.
Utility.fs
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
namespace global // note use of GLOBAL namespace | |
type NonEmptyList<'a> = { | |
First:'a | |
Rest: 'a list | |
} | |
module NonEmptyList = | |
// aList:'a list -> NonEmptyList<'a> option | |
let ofList aList = | |
match aList with | |
| [] -> None | |
| head::tail -> Some {First=head; Rest=tail} | |
// aNonEmptyList:NonEmptyList<'a> -> 'a list | |
let toList aNonEmptyList = | |
aNonEmptyList.First :: aNonEmptyList.Rest | |
let length aNonEmptyList = | |
aNonEmptyList.Rest.Length + 1 | |
let map f aNonEmptyList = { | |
First = f aNonEmptyList.First | |
Rest = List.map f aNonEmptyList.Rest | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment