diff options
Diffstat (limited to 'stdlib/source/library/lux/world/file.lux')
-rw-r--r-- | stdlib/source/library/lux/world/file.lux | 210 |
1 files changed, 105 insertions, 105 deletions
diff --git a/stdlib/source/library/lux/world/file.lux b/stdlib/source/library/lux/world/file.lux index d34904eea..f66458f87 100644 --- a/stdlib/source/library/lux/world/file.lux +++ b/stdlib/source/library/lux/world/file.lux @@ -87,7 +87,7 @@ (do maybe.monad [[parent temp] (text.split last_separator path) [_ child] (text.split (text.size /) temp)] - (wrap [parent child]))))) + (in [parent child]))))) (def: #export (parent fs path) (All [!] (-> (System !) Path (Maybe Path))) @@ -234,7 +234,7 @@ (\ ! join)) #.None - (\ io.monad wrap (exception.throw ..cannot_find_directory [path])))))] + (\ io.monad in (exception.except ..cannot_find_directory [path])))))] [directory_files java/io/File::isFile] [sub_directories java/io/File::isDirectory] @@ -263,8 +263,8 @@ bytes_read (java/io/InputStream::read data stream) _ (java/lang/AutoCloseable::close stream)] (if (i.= size bytes_read) - (wrap data) - (\ io.monad wrap (exception.throw ..cannot_read_all_data path))))) + (in data) + (\ io.monad in (exception.except ..cannot_read_all_data path))))) (def: (delete path) (|> path @@ -413,12 +413,12 @@ [?stats (with_async write! (Try Stats) (Fs::stat [path (..value_callback write!)] (..node_fs [])))] - (wrap (case ?stats - (#try.Success stats) - (<method> [] stats) - - (#try.Failure _) - false))))] + (in (case ?stats + (#try.Success stats) + (<method> [] stats) + + (#try.Failure _) + false))))] [file? Stats::isFile] [directory? Stats::isDirectory] @@ -434,7 +434,7 @@ node_fs))] (case outcome (#try.Success _) - (wrap (exception.throw ..cannot_make_directory [path])) + (in (exception.except ..cannot_make_directory [path])) (#try.Failure _) (with_async write! (Try Any) @@ -465,20 +465,20 @@ [stats (with_async write! (Try Stats) (Fs::stat [path (..value_callback write!)] (..node_fs [])))] - (wrap (|> stats - Stats::size - f.nat)))) + (in (|> stats + Stats::size + f.nat)))) (def: (last_modified path) (do (try.with async.monad) [stats (with_async write! (Try Stats) (Fs::stat [path (..value_callback write!)] (..node_fs [])))] - (wrap (|> stats - Stats::mtimeMs - f.int - duration.of_millis - instant.absolute)))) + (in (|> stats + Stats::mtimeMs + f.int + duration.of_millis + instant.absolute)))) (def: (can_execute? path) (let [node_fs (..node_fs [])] @@ -625,7 +625,7 @@ [file (..open [path "rb"]) data (PyFile::read [] file) _ (PyFile::close [] file)] - (wrap data))) + (in data))) (def: (delete path) (do (try.with io.monad) @@ -727,7 +727,7 @@ (list))] (case input #.Nil - (wrap output) + (in output) (#.Cons head tail) (do ! @@ -736,7 +736,7 @@ (#.Cons head output) output))))) _ (RubyDir::close [] self)] - (wrap output)))] + (in output)))] [directory_files RubyFile::file?] [sub_directories RubyFile::directory?] @@ -763,7 +763,7 @@ [file (RubyFile::open [path "rb"]) data (RubyFile::read [] file) _ (RubyFile::close [] file)] - (wrap data))) + (in data))) (def: (delete path) (do (try.with io.monad) @@ -788,7 +788,7 @@ data (RubyFile::write [data] file) _ (RubyFile::flush [] file) _ (RubyFile::close [] file)] - (wrap [])))] + (in [])))] ["wb" write] ["ab" append] @@ -797,7 +797,7 @@ (def: (move destination origin) (do (try.with io.monad) [_ (RubyFileUtils::move [origin destination])] - (wrap []))) + (in []))) ))) ## @.php @@ -849,8 +849,8 @@ ## (do {! (try.with io.monad)} ## [outcome (..file_put_contents [path ("php pack" ..byte_array_format data) <mode>])] ## (if (bit\= false (:as Bit outcome)) - ## (\ io.monad wrap (exception.throw ..cannot_write_to_file [path])) - ## (wrap []))))] + ## (\ io.monad in (exception.except ..cannot_write_to_file [path])) + ## (in []))))] ## [over_write +0] ## [append (..FILE_APPEND)] @@ -860,8 +860,8 @@ ## (do {! (try.with io.monad)} ## [data (..file_get_contents [path])] ## (if (bit\= false (:as Bit data)) - ## (\ io.monad wrap (exception.throw ..cannot_find_file [path])) - ## (wrap (..unpack [..byte_array_format data]))))) + ## (\ io.monad in (exception.except ..cannot_find_file [path])) + ## (in (..unpack [..byte_array_format data]))))) ## (def: path ## path) @@ -871,8 +871,8 @@ ## (do {! (try.with io.monad)} ## [value (<ffi> [path])] ## (if (bit\= false (:as Bit value)) - ## (\ io.monad wrap (exception.throw ..cannot_find_file [path])) - ## (wrap (`` (|> value (~~ (template.spliced <pipeline>))))))))] + ## (\ io.monad in (exception.except ..cannot_find_file [path])) + ## (in (`` (|> value (~~ (template.spliced <pipeline>))))))))] ## [size ..filesize [.nat]] ## [last_modified ..filemtime [(i.* +1,000) duration.of_millis instant.absolute]] @@ -885,22 +885,22 @@ ## (do {! (try.with io.monad)} ## [verdict (..touch [path (|> moment instant.relative duration.to_millis (i./ +1,000))])] ## (if (bit\= false (:as Bit verdict)) - ## (\ io.monad wrap (exception.throw ..cannot_find_file [path])) - ## (wrap [])))) + ## (\ io.monad in (exception.except ..cannot_find_file [path])) + ## (in [])))) ## (def: (move destination) ## (do {! (try.with io.monad)} ## [verdict (..rename [path destination])] ## (if (bit\= false (:as Bit verdict)) - ## (\ io.monad wrap (exception.throw ..cannot_find_file [path])) - ## (wrap (file destination))))) + ## (\ io.monad in (exception.except ..cannot_find_file [path])) + ## (in (file destination))))) ## (def: (delete _) ## (do (try.with io.monad) ## [verdict (..unlink [path])] ## (if (bit\= false (:as Bit verdict)) - ## (\ io.monad wrap (exception.throw ..cannot_find_file [path])) - ## (wrap [])))) + ## (\ io.monad in (exception.except ..cannot_find_file [path])) + ## (in [])))) ## )) ## (`` (implementation: (directory path) @@ -922,7 +922,7 @@ ## (list))] ## (case input ## #.Nil - ## (wrap output) + ## (in output) ## (#.Cons head tail) ## (do ! @@ -939,8 +939,8 @@ ## (do (try.with io.monad) ## [verdict (..rmdir [path])] ## (if (bit\= false (:as Bit verdict)) - ## (\ io.monad wrap (exception.throw ..cannot_find_directory [path])) - ## (wrap [])))) + ## (\ io.monad in (exception.except ..cannot_find_directory [path])) + ## (in [])))) ## )) ## (`` (implementation: #export default @@ -950,10 +950,10 @@ ## [(def: (<name> path) ## (do {! (try.with io.monad)} ## [verdict (<test> path)] - ## (\ io.monad wrap + ## (\ io.monad in ## (if verdict ## (#try.Success (<constructor> path)) - ## (exception.throw <exception> [path])))))] + ## (exception.except <exception> [path])))))] ## [file ..is_file ..file ..cannot_find_file] ## [directory ..is_dir ..directory ..cannot_find_directory] @@ -962,18 +962,18 @@ ## (def: (make_file path) ## (do {! (try.with io.monad)} ## [verdict (..touch [path (|> instant.now io.run instant.relative duration.to_millis (i./ +1,000))])] - ## (\ io.monad wrap + ## (\ io.monad in ## (if verdict ## (#try.Success (..file path)) - ## (exception.throw ..cannot_make_file [path]))))) + ## (exception.except ..cannot_make_file [path]))))) ## (def: (make_directory path) ## (do {! (try.with io.monad)} ## [verdict (..mkdir path)] - ## (\ io.monad wrap + ## (\ io.monad in ## (if verdict ## (#try.Success (..directory path)) - ## (exception.throw ..cannot_make_directory [path]))))) + ## (exception.except ..cannot_make_directory [path]))))) ## (def: separator ## ..default_separator) @@ -987,7 +987,7 @@ (do monad [verdict (\ fs file? path)] (if verdict - (wrap verdict) + (in verdict) (\ fs directory? path)))) (type: Mock_File @@ -1010,7 +1010,7 @@ (#.Cons head tail) (case (dictionary.get head directory) #.None - (exception.throw ..cannot_find_file [path]) + (exception.except ..cannot_find_file [path]) (#.Some node) (case [node tail] @@ -1021,10 +1021,10 @@ (recur sub_directory tail) _ - (exception.throw ..cannot_find_file [path]))) + (exception.except ..cannot_find_file [path]))) #.Nil - (exception.throw ..cannot_find_file [path])))) + (exception.except ..cannot_find_file [path])))) (def: (update_mock_file! / path now content mock) (-> Text Path Instant Binary Mock (Try Mock)) @@ -1043,7 +1043,7 @@ directory)) (#.Cons _) - (exception.throw ..cannot_find_file [path])) + (exception.except ..cannot_find_file [path])) (#.Some node) (case [node tail] @@ -1057,13 +1057,13 @@ [(#.Right sub_directory) (#.Cons _)] (do try.monad [sub_directory (recur sub_directory tail)] - (wrap (dictionary.put head (#.Right sub_directory) directory))) + (in (dictionary.put head (#.Right sub_directory) directory))) _ - (exception.throw ..cannot_find_file [path]))) + (exception.except ..cannot_find_file [path]))) #.Nil - (exception.throw ..cannot_find_file [path])))) + (exception.except ..cannot_find_file [path])))) (def: (mock_delete! / path mock) (-> Text Path Mock (Try Mock)) @@ -1073,7 +1073,7 @@ (#.Cons head tail) (case (dictionary.get head directory) #.None - (exception.throw ..cannot_delete [path]) + (exception.except ..cannot_delete [path]) (#.Some node) (case tail @@ -1085,20 +1085,20 @@ (#.Right sub_directory) (if (dictionary.empty? sub_directory) (#try.Success (dictionary.remove head directory)) - (exception.throw ..cannot_delete [path]))) + (exception.except ..cannot_delete [path]))) (#.Cons _) (case node (#.Left file) - (exception.throw ..cannot_delete [path]) + (exception.except ..cannot_delete [path]) (#.Right sub_directory) (do try.monad [sub_directory' (recur sub_directory tail)] - (wrap (dictionary.put head (#.Right sub_directory') directory)))))) + (in (dictionary.put head (#.Right sub_directory') directory)))))) #.Nil - (exception.throw ..cannot_delete [path])))) + (exception.except ..cannot_delete [path])))) (def: (try_update! transform var) (All [a] (-> (-> a (Try a)) (Var a) (STM (Try Any)))) @@ -1108,10 +1108,10 @@ (#try.Success |var|) (do ! [_ (stm.write |var| var)] - (wrap (#try.Success []))) + (in (#try.Success []))) (#try.Failure error) - (wrap (#try.Failure error))))) + (in (#try.Failure error))))) (def: (make_mock_directory! / path mock) (-> Text Path Mock (Try Mock)) @@ -1126,20 +1126,20 @@ (#try.Success (dictionary.put head (#.Right ..empty_mock) directory)) (#.Cons _) - (exception.throw ..cannot_make_directory [path])) + (exception.except ..cannot_make_directory [path])) (#.Some node) (case [node tail] [(#.Right sub_directory) (#.Cons _)] (do try.monad [sub_directory (recur sub_directory tail)] - (wrap (dictionary.put head (#.Right sub_directory) directory))) + (in (dictionary.put head (#.Right sub_directory) directory))) _ - (exception.throw ..cannot_make_directory [path]))) + (exception.except ..cannot_make_directory [path]))) #.Nil - (exception.throw ..cannot_make_directory [path])))) + (exception.except ..cannot_make_directory [path])))) (def: (retrieve_mock_directory! / path mock) (-> Text Path Mock (Try Mock)) @@ -1152,12 +1152,12 @@ (#.Cons head tail) (case (dictionary.get head directory) #.None - (exception.throw ..cannot_find_directory [path]) + (exception.except ..cannot_find_directory [path]) (#.Some node) (case node (#.Left _) - (exception.throw ..cannot_find_directory [path]) + (exception.except ..cannot_find_directory [path]) (#.Right sub_directory) (case tail @@ -1195,27 +1195,27 @@ (#try.Success |store|) (do ! [_ (stm.write |store| store)] - (wrap (#try.Success []))) + (in (#try.Success []))) (#try.Failure error) - (wrap (#try.Failure error)))))) + (in (#try.Failure error)))))) (~~ (template [<method> <tag>] [(def: (<method> path) (stm.commit (do stm.monad [|store| (stm.read store)] - (wrap (do try.monad - [directory (..retrieve_mock_directory! separator path |store|)] - (wrap (|> directory - dictionary.entries - (list.all (function (_ [node_name node]) - (case node - (<tag> _) - (#.Some (format path separator node_name)) - - _ - #.None))))))))))] + (in (do try.monad + [directory (..retrieve_mock_directory! separator path |store|)] + (in (|> directory + dictionary.entries + (list.all (function (_ [node_name node]) + (case node + (<tag> _) + (#.Some (format path separator node_name)) + + _ + #.None))))))))))] [directory_files #.Left] [sub_directories #.Right] @@ -1225,38 +1225,38 @@ (stm.commit (do stm.monad [|store| (stm.read store)] - (wrap (|> |store| - (..retrieve_mock_file! separator path) - (try\map (|>> product.right - (get@ #mock_content) - binary.size))))))) + (in (|> |store| + (..retrieve_mock_file! separator path) + (try\map (|>> product.right + (get@ #mock_content) + binary.size))))))) (def: (last_modified path) (stm.commit (do stm.monad [|store| (stm.read store)] - (wrap (|> |store| - (..retrieve_mock_file! separator path) - (try\map (|>> product.right - (get@ #mock_last_modified)))))))) + (in (|> |store| + (..retrieve_mock_file! separator path) + (try\map (|>> product.right + (get@ #mock_last_modified)))))))) (def: (can_execute? path) (stm.commit (do stm.monad [|store| (stm.read store)] - (wrap (|> |store| - (..retrieve_mock_file! separator path) - (try\map (|>> product.right - (get@ #mock_can_execute)))))))) + (in (|> |store| + (..retrieve_mock_file! separator path) + (try\map (|>> product.right + (get@ #mock_can_execute)))))))) (def: (read path) (stm.commit (do stm.monad [|store| (stm.read store)] - (wrap (|> |store| - (..retrieve_mock_file! separator path) - (try\map (|>> product.right - (get@ #mock_content)))))))) + (in (|> |store| + (..retrieve_mock_file! separator path) + (try\map (|>> product.right + (get@ #mock_content)))))))) (def: (delete path) (stm.commit @@ -1301,10 +1301,10 @@ (#try.Success |store|) (do ! [_ (stm.write |store| store)] - (wrap (#try.Success []))) + (in (#try.Success []))) (#try.Failure error) - (wrap (#try.Failure error)))))) + (in (#try.Failure error)))))) )))) (def: (check_or_make_directory monad fs path) @@ -1312,7 +1312,7 @@ (do monad [? (\ fs directory? path)] (if ? - (wrap (#try.Success [])) + (in (#try.Success [])) (\ fs make_directory path)))) (def: #export (make_directories monad fs path) @@ -1323,11 +1323,11 @@ (list.drop 1 segments) segments) #.Nil - (\ monad wrap (exception.throw ..cannot_make_directory [path])) + (\ monad in (exception.except ..cannot_make_directory [path])) (#.Cons head tail) (case head - "" (\ monad wrap (exception.throw ..cannot_make_directory [path])) + "" (\ monad in (exception.except ..cannot_make_directory [path])) _ (loop [current (if rooted? (format (\ fs separator) head) head) @@ -1338,19 +1338,19 @@ (#try.Success _) (case next #.Nil - (wrap (#try.Success [])) + (in (#try.Success [])) (#.Cons head tail) (recur (format current (\ fs separator) head) tail)) (#try.Failure error) - (wrap (#try.Failure error))))))))) + (in (#try.Failure error))))))))) (def: #export (make_file monad fs content path) (All [!] (-> (Monad !) (System !) Binary Path (! (Try Any)))) (do monad [? (\ fs file? path)] (if ? - (wrap (exception.throw ..cannot_make_file [path])) + (in (exception.except ..cannot_make_file [path])) (\ fs write content path)))) |