aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2018-12-26 17:39:20 -0400
committerEduardo Julian2018-12-26 17:39:20 -0400
commit7a69373e2dc7343145f815c8dc1081a1bfc233bb (patch)
tree2bdcb142d8862e01b567ebaa32c60c20a2dc6962
parent5c270277bde8ee70e065173ebb6b95aab5223de8 (diff)
Utility functions for getting files and directories.
-rw-r--r--stdlib/source/lux/world/file.lux18
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<!>