aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/data/collection/sequence.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/library/lux/data/collection/sequence.lux23
1 files changed, 14 insertions, 9 deletions
diff --git a/stdlib/source/library/lux/data/collection/sequence.lux b/stdlib/source/library/lux/data/collection/sequence.lux
index c8049c3b3..6264d6083 100644
--- a/stdlib/source/library/lux/data/collection/sequence.lux
+++ b/stdlib/source/library/lux/data/collection/sequence.lux
@@ -66,12 +66,12 @@
0 head
_ (item (dec idx) tail))))
-(template [<taker> <dropper> <splitter> <pred_type> <pred_test> <pred_step>]
+(template [<taker> <dropper> <pred_type> <pred_test> <pred_step> <post_test>]
[(def: .public (<taker> pred xs)
(All [a]
(-> <pred_type> (Sequence a) (List a)))
(let [[x xs'] (//.result xs)]
- (if <pred_test>
+ (if (<post_test> <pred_test>)
(list& x (<taker> <pred_step> xs'))
(list))))
@@ -79,21 +79,26 @@
(All [a]
(-> <pred_type> (Sequence a) (Sequence a)))
(let [[x xs'] (//.result xs)]
- (if <pred_test>
+ (if (<post_test> <pred_test>)
(<dropper> <pred_step> xs')
- xs)))
+ xs)))]
+
+ [while until (-> a Bit) (pred x) pred |>]
+ [take drop Nat (n.= 0 pred) (dec pred) not]
+ )
- (def: .public (<splitter> pred xs)
+(template [<splitter> <pred_type> <pred_test> <pred_step>]
+ [(def: .public (<splitter> pred xs)
(All [a]
(-> <pred_type> (Sequence a) [(List a) (Sequence a)]))
(let [[x xs'] (//.result xs)]
(if <pred_test>
+ [(list) xs]
(let [[tail next] (<splitter> <pred_step> xs')]
- [(#.Item [x tail]) next])
- [(list) xs])))]
+ [(#.Item [x tail]) next]))))]
- [take_while drop_while split_while (-> a Bit) (pred x) pred]
- [take drop split Nat (n.> 0 pred) (dec pred)]
+ [split_when (-> a Bit) (pred x) pred]
+ [split Nat (n.= 0 pred) (dec pred)]
)
(def: .public (unfold step init)