Last active
July 12, 2019 06:52
-
-
Save CoditCompany/22392b51127b7ee1d945bb2847dbf5f8 to your computer and use it in GitHub Desktop.
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
// 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