diff options
author | Eduardo Julian | 2018-10-13 13:39:49 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-10-13 13:39:49 -0400 |
commit | a53cb0cece97a8b2c88c1205fee16b36e1e7e6c2 (patch) | |
tree | 6708a4f01f8ac9b47bf0e0a5d88047c7cecfcaba /stdlib/source | |
parent | b041cf72679f1d562086394048a03a82f1a00a99 (diff) |
Turned the Archive into an abstract type for greater safety when operating on it (cannot skip the abstraction by directly using the dictionary functions).
Diffstat (limited to 'stdlib/source')
-rw-r--r-- | stdlib/source/lux/compiler/meta/archive.lux | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/stdlib/source/lux/compiler/meta/archive.lux b/stdlib/source/lux/compiler/meta/archive.lux index 1e9240f7b..457e3b874 100644 --- a/stdlib/source/lux/compiler/meta/archive.lux +++ b/stdlib/source/lux/compiler/meta/archive.lux @@ -98,26 +98,32 @@ ["Old document's key" (describe (..signature (get@ #key old)))] ["New document's key" (describe (..signature (get@ #key new)))])) -(type: #export Archive - (Dictionary Text (Ex [d] (Document d)))) - -(def: #export empty Archive (dict.new text.Hash<Text>)) - -(def: #export (add name document archive) - (-> Text (Ex [d] (Document d)) Archive (Error Archive)) - (case (dict.get name archive) - (#.Some existing) - (if (is? document existing) - (#error.Success archive) - (ex.throw cannot-replace-document-in-archive [name existing document])) - - #.None - (#error.Success (dict.put name document archive)))) - -(def: #export (merge additions archive) - (-> Archive Archive (Error Archive)) - (monad.fold error.Monad<Error> - (function (_ [name' document'] archive') - (..add name' document' archive')) - archive - (dict.entries additions))) +(abstract: #export Archive + {} + + (Dictionary Text (Ex [d] (Document d))) + + (def: #export empty + Archive + (:abstraction (dict.new text.Hash<Text>))) + + (def: #export (add name document archive) + (-> Text (Ex [d] (Document d)) Archive (Error Archive)) + (case (dict.get name (:representation archive)) + (#.Some existing) + (if (is? document existing) + (#error.Success archive) + (ex.throw cannot-replace-document-in-archive [name existing document])) + + #.None + (#error.Success (:abstraction (dict.put name document + (:representation archive)))))) + + (def: #export (merge additions archive) + (-> Archive Archive (Error Archive)) + (monad.fold error.Monad<Error> + (function (_ [name' document'] archive') + (..add name' document' archive')) + archive + (dict.entries (:representation additions)))) + ) |