Skip to content

Instantly share code, notes, and snippets.

@CoditCompany
Created July 12, 2019 06:34
Show Gist options
  • Save CoditCompany/b4f1f49c1bcbfed11145bd4d3462ee1c to your computer and use it in GitHub Desktop.
Save CoditCompany/b4f1f49c1bcbfed11145bd4d3462ee1c to your computer and use it in GitHub Desktop.
open FPrimitive
/// Composible specifications for your domain types:
type NonEmptyString =
private NonEmptyString of string with
static member create x =
Spec.def<string>
|> Spec.notNull "should not be null"
|> Spec.notEmpty "should not be empty"
|> Spec.createModel NonEmptyString x
/// ...also available as computation expression.
type NonEmptyList<'a> =
private NonEmptyList of 'a list with
static member create xs =
specModel NonEmptyList xs {
nonEmpty "list should not be empty"
lengthBetween 1 10 "list length should be between 1-10" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment