diff options
author | Eduardo Julian | 2018-12-26 17:39:20 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-12-26 17:39:20 -0400 |
commit | 7a69373e2dc7343145f815c8dc1081a1bfc233bb (patch) | |
tree | 2bdcb142d8862e01b567ebaa32c60c20a2dc6962 /stdlib | |
parent | 5c270277bde8ee70e065173ebb6b95aab5223de8 (diff) |
Utility functions for getting files and directories.
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/source/lux/world/file.lux | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/stdlib/source/lux/world/file.lux b/stdlib/source/lux/world/file.lux index f959e1af3..f0269e52c 100644 --- a/stdlib/source/lux/world/file.lux +++ b/stdlib/source/lux/world/file.lux @@ -339,6 +339,24 @@ )) })) +(do-template [<get> <signature> <create> <find> <exception>] + [(def: #export (<get> Monad<!> System<!> path) + (All [!] (-> (Monad !) (System !) Path (! (Error (<signature> !))))) + (do Monad<!> + [outcome (:: System<!> <create> path)] + (case outcome + (#error.Success file) + (wrap (#error.Success file)) + + (#error.Failure error) + (if (ex.match? <exception> error) + (:: System<!> <find> path) + (wrap (#error.Failure error))))))] + + [get-file File create-file file ..cannot-create-file] + [get-directory Directory create-directory directory ..cannot-create-directory] + ) + (def: #export (exists? Monad<!> System<!> path) (All [!] (-> (Monad !) (System !) Path (! Bit))) (do Monad<!> |