aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/data/collection/sequence.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/data/collection/sequence.lux')
-rw-r--r--stdlib/source/library/lux/data/collection/sequence.lux97
1 files changed, 65 insertions, 32 deletions
diff --git a/stdlib/source/library/lux/data/collection/sequence.lux b/stdlib/source/library/lux/data/collection/sequence.lux
index 4a2beb94f..07ebeba76 100644
--- a/stdlib/source/library/lux/data/collection/sequence.lux
+++ b/stdlib/source/library/lux/data/collection/sequence.lux
@@ -2,35 +2,35 @@
... https://hypirion.com/musings/understanding-persistent-vector-pt-2
... https://hypirion.com/musings/understanding-persistent-vector-pt-3
(.using
- [library
- [lux {"-" list}
- ["@" target]
- [abstract
- [functor {"+" Functor}]
- [apply {"+" Apply}]
- [monad {"+" Monad do}]
- [equivalence {"+" Equivalence}]
- [monoid {"+" Monoid}]
- [mix {"+" Mix}]
- [predicate {"+" Predicate}]]
- [control
- ["[0]" maybe]
- ["[0]" try {"+" Try}]
- ["[0]" exception {"+" exception:}]
- ["<>" parser
- ["<[0]>" code {"+" Parser}]]]
- [data
- ["[0]" product]
- [collection
- ["[0]" list ("[1]#[0]" mix functor monoid)]
- ["[0]" array {"+" Array} ("[1]#[0]" functor mix)]]]
- [macro
- [syntax {"+" syntax:}]
- ["[0]" code]]
- [math
- [number
- ["n" nat]
- ["[0]" i64]]]]])
+ [library
+ [lux {"-" list}
+ ["@" target]
+ [abstract
+ [functor {"+" Functor}]
+ [apply {"+" Apply}]
+ [monad {"+" Monad do}]
+ [equivalence {"+" Equivalence}]
+ [monoid {"+" Monoid}]
+ [mix {"+" Mix}]
+ [predicate {"+" Predicate}]]
+ [control
+ ["[0]" maybe]
+ ["[0]" try {"+" Try}]
+ ["[0]" exception {"+" exception:}]
+ ["<>" parser
+ ["<[0]>" code {"+" Parser}]]]
+ [data
+ ["[0]" product]
+ [collection
+ ["[0]" list ("[1]#[0]" mix functor monoid)]
+ ["[0]" array {"+" Array} ("[1]#[0]" functor mix)]]]
+ [macro
+ [syntax {"+" syntax:}]
+ ["[0]" code]]
+ [math
+ [number
+ ["n" nat]
+ ["[0]" i64]]]]])
(type: (Node a)
(Variant
@@ -300,11 +300,11 @@
sequence))}
(exception.except ..index_out_of_bounds [sequence idx]))))
-(def: .public (revised idx f sequence)
+(def: .public (revised idx revision it)
(All (_ a) (-> Nat (-> a a) (Sequence a) (Try (Sequence a))))
(do try.monad
- [val (..item idx sequence)]
- (..has idx (f val) sequence)))
+ [val (..item idx it)]
+ (..has idx (revision val) it)))
(def: .public (prefix sequence)
(All (_ a) (-> (Sequence a) (Sequence a)))
@@ -498,3 +498,36 @@
[every? array.every? #1 and]
[any? array.any? #0 or]
)
+
+(def: .public (only when items)
+ (All (_ a) (-> (-> a Bit) (Sequence a) (Sequence a)))
+ (..mix (function (_ item output)
+ (if (when item)
+ (..suffix item output)
+ output))
+ ..empty
+ items))
+
+(def: (one|node check items)
+ (All (_ a b)
+ (-> (-> a (Maybe b)) (Node a) (Maybe b)))
+ (case items
+ {#Base items}
+ (array.one check items)
+
+ {#Hierarchy items}
+ (array.one (one|node check) items)))
+
+(def: .public (one check items)
+ (All (_ a b)
+ (-> (-> a (Maybe b)) (Sequence a) (Maybe b)))
+ (case (|> items
+ (value@ #root)
+ (array.one (one|node check)))
+ {.#None}
+ (|> items
+ (value@ #tail)
+ (array.one check))
+
+ output
+ output))