diff options
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<!> |