Skip to content

Instantly share code, notes, and snippets.

@CoditCompany
Last active July 12, 2019 06:52
Show Gist options
  • Save CoditCompany/22392b51127b7ee1d945bb2847dbf5f8 to your computer and use it in GitHub Desktop.
Save CoditCompany/22392b51127b7ee1d945bb2847dbf5f8 to your computer and use it in GitHub Desktop.
// Specification that the input parameter of the access-controlled function should satisfy
let spec =
Spec.def<string>
|> Spec.notEmpty "should not be empty string"
// The function (fun x -> Some x) is now 'access-controlled' with a specifiation for non-empty strings,
// can be revoked anytime the 'Access.revoke acc' is called, and can only be accessed three times.
let acc =
Access.func (fun x -> Some x)
|> Access.satisfy spec
|> Access.revokable
|> Access.times 3
// Revoke the function
Access.revoke acc
// Only files from within the '/bin' directory and file extension '.txt' are allowed to pass
let acc = access {
onlyFilesFrom (DirectoryInfo "/bin")
fileExtension ".txt" }
// Evalute 'access-controlled' function with file '/bin/image.jpg'
let (result : Result<FileInfo, string list>) = Access.eval (FileInfo "/bin/image.jpg") acc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment