From f4c5f6ec0ad286f55a4c9e36677c321e99eefcbe Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 4 Dec 2017 20:47:29 -0400 Subject: - lux/world/file now works with Process, instead of Task. --- stdlib/source/lux/world/file.lux | 80 ++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 41 deletions(-) (limited to 'stdlib/source') diff --git a/stdlib/source/lux/world/file.lux b/stdlib/source/lux/world/file.lux index 5fa4e1661..b33cf9540 100644 --- a/stdlib/source/lux/world/file.lux +++ b/stdlib/source/lux/world/file.lux @@ -2,14 +2,12 @@ lux (lux (control [monad #+ do] ["ex" exception #+ exception:]) - (concurrency ["P" promise] - ["T" task]) (data ["E" error] (coll [array])) (time ["i" instant] ["d" duration]) (world [blob #+ Blob]) - [io] + [io #+ Process] [host])) (exception: Could-Not-Read-All-Data) @@ -51,47 +49,47 @@ (do-template [ ] [(def: #export ( data file) - (-> Blob File (T.Task Unit)) - (P.future (do (E.ErrorT io.Monad) - [stream (FileOutputStream::new [(java/io/File::new file) ]) - _ (OutputStream::write [data] stream) - _ (OutputStream::flush [] stream)] - (AutoCloseable::close [] stream))))] + (-> Blob File (Process Unit)) + (do (E.ErrorT io.Monad) + [stream (FileOutputStream::new [(java/io/File::new file) ]) + _ (OutputStream::write [data] stream) + _ (OutputStream::flush [] stream)] + (AutoCloseable::close [] stream)))] [append true] [write false] ) (def: #export (read file) - (-> File (T.Task Blob)) - (P.future (do (E.ErrorT io.Monad) - [#let [file' (java/io/File::new file)] - size (java/io/File::length [] file') - #let [data (blob.create (int-to-nat size))] - stream (FileInputStream::new [file']) - bytes-read (InputStream::read [data] stream) - _ (AutoCloseable::close [] stream)] - (if (i/= size bytes-read) - (wrap data) - (io.io (ex.throw Could-Not-Read-All-Data file)))))) + (-> File (Process Blob)) + (do (E.ErrorT io.Monad) + [#let [file' (java/io/File::new file)] + size (java/io/File::length [] file') + #let [data (blob.create (int-to-nat size))] + stream (FileInputStream::new [file']) + bytes-read (InputStream::read [data] stream) + _ (AutoCloseable::close [] stream)] + (if (i/= size bytes-read) + (wrap data) + (io.io (ex.throw Could-Not-Read-All-Data file))))) (def: #export (size file) - (-> File (T.Task Nat)) - (P.future (do (E.ErrorT io.Monad) - [size (java/io/File::length [] (java/io/File::new file))] - (wrap (int-to-nat size))))) + (-> File (Process Nat)) + (do (E.ErrorT io.Monad) + [size (java/io/File::length [] (java/io/File::new file))] + (wrap (int-to-nat size)))) (def: #export (files dir) - (-> File (T.Task (List File))) - (P.future (do (E.ErrorT io.Monad) - [files (java/io/File::listFiles [] (java/io/File::new dir))] - (monad.map @ (java/io/File::getAbsolutePath []) - (array.to-list files))))) + (-> File (Process (List File))) + (do (E.ErrorT io.Monad) + [files (java/io/File::listFiles [] (java/io/File::new dir))] + (monad.map @ (java/io/File::getAbsolutePath []) + (array.to-list files)))) (do-template [ ] [(def: #export ( file) - (-> File (T.Task Bool)) - (P.future ( [] (java/io/File::new file))))] + (-> File (Process Bool)) + ( [] (java/io/File::new file)))] [exists? java/io/File::exists] [make-dir java/io/File::mkdir] @@ -104,17 +102,17 @@ ) (def: #export (move target source) - (-> File File (T.Task Bool)) - (P.future (java/io/File::renameTo [(java/io/File::new target)] - (java/io/File::new source)))) + (-> File File (Process Bool)) + (java/io/File::renameTo [(java/io/File::new target)] + (java/io/File::new source))) (def: #export (get-last-modified file) - (-> File (T.Task i.Instant)) - (P.future (do (E.ErrorT io.Monad) - [millis (java/io/File::lastModified [] (java/io/File::new file))] - (wrap (|> millis d.from-millis i.absolute))))) + (-> File (Process i.Instant)) + (do (E.ErrorT io.Monad) + [millis (java/io/File::lastModified [] (java/io/File::new file))] + (wrap (|> millis d.from-millis i.absolute)))) (def: #export (set-last-modified time file) - (-> i.Instant File (T.Task Bool)) - (P.future (java/io/File::setLastModified [(|> time i.relative d.to-millis)] - (java/io/File::new file)))) + (-> i.Instant File (Process Bool)) + (java/io/File::setLastModified [(|> time i.relative d.to-millis)] + (java/io/File::new file))) -- cgit v1.2.3