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.lux42
1 files changed, 21 insertions, 21 deletions
diff --git a/stdlib/source/library/lux/data/collection/sequence.lux b/stdlib/source/library/lux/data/collection/sequence.lux
index 5decabfde..f26f57d97 100644
--- a/stdlib/source/library/lux/data/collection/sequence.lux
+++ b/stdlib/source/library/lux/data/collection/sequence.lux
@@ -8,7 +8,7 @@
["//" continuation (#+ Cont)]
["<>" parser
["<.>" code (#+ Parser)]]]
- [macro (#+ with_gensyms)
+ [macro (#+ with_identifiers)
[syntax (#+ syntax:)]
["." code]]
[data
@@ -36,8 +36,8 @@
(//.pending [x (repeated x)]))
(def: .public (cycle [start next])
- {#.doc (doc "Go over the elements of a list forever."
- "The list should not be empty.")}
+ {#.doc (example "Go over the elements of a list forever."
+ "The list should not be empty.")}
(All [a]
(-> [a (List a)] (Sequence a)))
(loop [head start
@@ -52,7 +52,7 @@
(template [<name> <return>]
[(def: .public (<name> sequence)
(All [a] (-> (Sequence a) <return>))
- (let [[head tail] (//.run sequence)]
+ (let [[head tail] (//.result sequence)]
<name>))]
[head a]
@@ -61,7 +61,7 @@
(def: .public (item idx sequence)
(All [a] (-> Nat (Sequence a) a))
- (let [[head tail] (//.run sequence)]
+ (let [[head tail] (//.result sequence)]
(case idx
0 head
_ (item (dec idx) tail))))
@@ -70,7 +70,7 @@
[(def: .public (<taker> pred xs)
(All [a]
(-> <pred_type> (Sequence a) (List a)))
- (let [[x xs'] (//.run xs)]
+ (let [[x xs'] (//.result xs)]
(if <pred_test>
(list& x (<taker> <pred_step> xs'))
(list))))
@@ -78,7 +78,7 @@
(def: .public (<dropper> pred xs)
(All [a]
(-> <pred_type> (Sequence a) (Sequence a)))
- (let [[x xs'] (//.run xs)]
+ (let [[x xs'] (//.result xs)]
(if <pred_test>
(<dropper> <pred_step> xs')
xs)))
@@ -86,7 +86,7 @@
(def: .public (<splitter> pred xs)
(All [a]
(-> <pred_type> (Sequence a) [(List a) (Sequence a)]))
- (let [[x xs'] (//.run xs)]
+ (let [[x xs'] (//.result xs)]
(if <pred_test>
(let [[tail next] (<splitter> <pred_step> xs')]
[(#.Item [x tail]) next])
@@ -104,17 +104,17 @@
(//.pending [x (unfold step next)])))
(def: .public (only predicate sequence)
- {#.doc (doc "A new sequence only with items that satisfy the predicate.")}
+ {#.doc (example "A new sequence only with items that satisfy the predicate.")}
(All [a] (-> (-> a Bit) (Sequence a) (Sequence a)))
- (let [[head tail] (//.run sequence)]
+ (let [[head tail] (//.result sequence)]
(if (predicate head)
(//.pending [head (only predicate tail)])
(only predicate tail))))
(def: .public (partition left? xs)
- {#.doc (doc "Split a sequence in two based on a predicate."
- "The left side contains all entries for which the predicate is #1."
- "The right side contains all entries for which the predicate is #0.")}
+ {#.doc (example "Split a sequence in two based on a predicate."
+ "The left side contains all entries for which the predicate is #1."
+ "The right side contains all entries for which the predicate is #0.")}
(All [a] (-> (-> a Bit) (Sequence a) [(Sequence a) (Sequence a)]))
[(..only left? xs)
(..only (bit.complement left?) xs)])
@@ -123,7 +123,7 @@
(Functor Sequence)
(def: (map f fa)
- (let [[head tail] (//.run fa)]
+ (let [[head tail] (//.result fa)]
(//.pending [(f head) (map f tail)]))))
(implementation: .public comonad
@@ -134,20 +134,20 @@
(def: out head)
(def: (split wa)
- (let [[head tail] (//.run wa)]
+ (let [[head tail] (//.result wa)]
(//.pending [wa (split tail)]))))
(syntax: .public (^sequence& {patterns (<code>.form (<>.many <code>.any))}
body
{branches (<>.some <code>.any)})
- {#.doc (doc "Allows destructuring of sequences in pattern-matching expressions."
- "Caveat emptor: Only use it for destructuring, and not for testing values within the sequences."
- (let [(^sequence& x y z _tail) (some_sequence_func +1 +2 +3)]
- (func x y z)))}
- (with_gensyms [g!sequence]
+ {#.doc (example "Allows destructuring of sequences in pattern-matching expressions."
+ "Caveat emptor: Only use it for destructuring, and not for testing values within the sequences."
+ (let [(^sequence& x y z _tail) (some_sequence_func +1 +2 +3)]
+ (func x y z)))}
+ (with_identifiers [g!sequence]
(let [body+ (` (let [(~+ (list\join (list\map (function (_ pattern)
(list (` [(~ pattern) (~ g!sequence)])
- (` ((~! //.run) (~ g!sequence)))))
+ (` ((~! //.result) (~ g!sequence)))))
patterns)))]
(~ body)))]
(in (list& g!sequence body+ branches)))))