From 2b909032e7a0bd10cd7db52067d2fb701bfa95e5 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 6 Jul 2021 21:34:21 -0400 Subject: Simplified the API for file-system operations. --- stdlib/source/program/compositor/import.lux | 50 ++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'stdlib/source/program/compositor/import.lux') diff --git a/stdlib/source/program/compositor/import.lux b/stdlib/source/program/compositor/import.lux index 19a2d7607..f91ad03e7 100644 --- a/stdlib/source/program/compositor/import.lux +++ b/stdlib/source/program/compositor/import.lux @@ -8,7 +8,7 @@ [concurrency ["." promise (#+ Promise) ("#\." monad)]] ["<>" parser - ["" binary]]] + ["<.>" binary]]] [data [binary (#+ Binary)] ["." text @@ -24,7 +24,7 @@ [archive [descriptor (#+ Module)]]]]] [world - ["." file (#+ Path File)]]] + ["." file]]] [// [cli (#+ Library)]]) @@ -39,32 +39,32 @@ ["Library" (%.text library)])) (type: #export Import - (Dictionary Path Binary)) + (Dictionary file.Path Binary)) (def: (import_library system library import) (-> (file.System Promise) Library Import (Action Import)) - (do (try.with promise.monad) - [file (: (Action (File Promise)) - (\ system file library)) - binary (\ file content [])] - (promise\wrap - (do {! try.monad} - [tar (.run tar.parser binary)] - (monad.fold ! (function (_ entry import) - (case entry - (#tar.Normal [path instant mode ownership content]) - (let [path (tar.from_path path)] - (case (dictionary.try_put path (tar.data content) import) - (#try.Success import) - (wrap import) - - (#try.Failure error) - (exception.throw ..duplicate [library path]))) - - _ - (exception.throw ..useless_tar_entry []))) - import - (row.to_list tar)))))) + (let [! promise.monad] + (|> library + (\ system read) + (\ ! map (let [! try.monad] + (|>> (\ ! map (.run tar.parser)) + (\ ! join) + (\ ! map (|>> row.to_list + (monad.fold ! (function (_ entry import) + (case entry + (#tar.Normal [path instant mode ownership content]) + (let [path (tar.from_path path)] + (case (dictionary.try_put path (tar.data content) import) + (#try.Failure error) + (exception.throw ..duplicate [library path]) + + import' + import')) + + _ + (exception.throw ..useless_tar_entry []))) + import))) + (\ ! join))))))) (def: #export (import system libraries) (-> (file.System Promise) (List Library) (Action Import)) -- cgit v1.2.3