-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata-list.red
More file actions
1604 lines (1458 loc) · 35.9 KB
/
data-list.red
File metadata and controls
1604 lines (1458 loc) · 35.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Red [
Title: "Data.List"
Author: "unchartedworks"
File: %data-list.red
Tabs: 4
Rights: "unchartedworks. All rights reserved."
License: "MIT"
]
;;++
plus-block: function [
xs [block! string!]
ys [block! string!]
][
append copy reduce xs reduce ys
]
reduce-deep: function [
xs'
] [
xs: reduce xs'
case [
(not block? xs) xs
(all [block? xs empty? xs]) xs
(all [block? xs not empty? xs]) map :reduce-deep xs
]
]
++: make op! :plus-block
head': :first
last': :last
rest: function [
"Extract the elements after the head of a list, which must be non-empty."
xs [series!]
][
copy next xs
]
tail': :rest
init: function [
"Return all the elements of a list except the last one. The list must be non-empty."
xs [series!]
][
either 1 == length? xs [
either string? xs [copy ""][copy []]
][
copy/part xs ((length? xs) - 1)
]
]
most: :init
uncons: function [
"Decompose a list into its first and rest. If the list is empty, returns Nothing. If the list is non-empty, returns Just (x, xs), where x is the head of the list and xs its tail."
xs [series!]
][
either empty? xs [
none
][
reduce [first xs (rest xs)]
]
]
length: function [
"Returns the size/length of a finite structure as an Int. The default implementation is optimized for structures that are similar to cons-lists, because there is no general way to do better."
xs [series!]
][
length? xs
]
map: function [
"applying f to each element of xs"
f [any-function!]
xs [series!]
][
yss: copy []
g: function [ys x] [ys ++ (reduce [f x])]
zss: foldl :g yss xs
should-concat: and' [(string? xs) and' (map :char? zss)]
either should-concat [
accum: func[y x][y ++ (to-string x)]
foldl :accum "" zss
][
zss
]
]
reverse': function [
"returns the elements of xs in reverse order."
xs [series!]
][
reverse copy xs
]
intersperse: function [
"taking an element and a list and `intersperses' that element between the elements of the list."
y
xs [series!]
][
either 1 >= length? xs [xs][intersperse* y xs]
]
intersperse*: function [
y
xs [series!]
][
r: either string? xs [copy ""][copy []]
f: func [ys x][ys ++ (reduce [x y])]
ys: foldl :f r (most reduce xs)
zs: reduce [last reduce xs]
ys ++ zs
]
transpose: function [
"transposing the rows and columns of its argument."
xss [series!]
][
case [
(not transposable? xss) none
empty? xss [copy []]
(empty? first xss) (copy [])
true (append (copy reduce [map :first xss]) (transpose map :rest xss))
]
]
transposable?: function [
xss [series!]
][
case [
(xss == []) true
true == (all (map func [x][all [block? x empty? x]] xss)) true
none == (all (map :block? xss)) false
(transposable?* xss) true
true false
]
]
transposable?*: function [
xss [series!]
][
general-length?: func [x][either (series? x) [length? x][none]]
length-equal?: func [x][(general-length? x) == (general-length? first :xss)]
none <> all [
(block? xss)
all (map :block? xss)
all (map :length-equal? xss)
]
]
subsequences: function [
"returns the list of all subsequences of the argument"
xs [series!]
][
case [
(not series? xs) none
(empty? xs) (reduce [xs])
(block? xs) (block-subsequences xs)
(string? xs) ([""] ++ (string-subsequences xs))
]
]
block-subsequences: function [
xs
][
either (empty? xs) [
copy [[]]
][
append (copy [[]]) non-empty-block-subsequences xs
]
]
non-empty-block-subsequences: function [
xs
][
either empty? xs [copy []][non-empty-block-subsequences* xs]
]
non-empty-block-subsequences*: function [
xs
][
g: function [ys r][
m1: reduce [ys]
m2: reduce [(reduce [first xs]) ++ ys]
m3: r
(m1 ++ m2) ++ m3
]
r0: (reduce [reduce [first xs]])
r1: foldr :g [] (non-empty-block-subsequences (rest xs))
r0 ++ r1
]
string-subsequences: function [
xs [string!]
][
either (empty? xs) [
copy [""]
][
non-empty-string-subsequences xs
]
]
non-empty-string-subsequences: function [
xs [string!]
][
either empty? xs [copy []][non-empty-string-subsequences* xs]
]
non-empty-string-subsequences*: function [
xs [string!]
][
g: function [ys r][
m1: reduce [ys]
m2: reduce [(to-string first xs) ++ ys]
m3: r
(m1 ++ m2) ++ m3
]
r0: (reduce [to-string first xs])
r1: foldr :g [] (non-empty-string-subsequences (rest xs))
r0 ++ r1
]
permutations: function [
"returns the list of all permutations of the argument."
xs [series!]
][
case [
(not series? xs) none
(empty? xs) (reduce [xs])
(block? xs) (block-permutations xs)
(string? xs) (string-permutations xs)
]
]
block-permutations: function [
xs [series!]
][
either empty? xs [
copy [[]] ; Don't use []
][
ys: block-permutations (rest xs)
f: func [zs][block-between (first xs) zs]
g: func [zs x][zs ++ x]
foldl :g [] (map :f ys)
]
]
block-between: function [
x
ys [series!]
][
either (empty? ys) [reduce [reduce [x]]][block-between* x ys]
]
block-between*: function [
x
ys [series!]
][
m1: (reduce [(reduce [x]) ++ ys])
f: func [y][reduce [first ys] ++ y]
zs: block-between x (rest ys)
m2: map :f zs
m1 ++ m2
]
string-permutations: function [
xs [string!]
][
either empty? xs [
copy [""] ; Don't use []
][
ys: string-permutations (rest xs)
f: func [zs][string-between (first xs) zs]
g: func [zs x][zs ++ x]
foldl :g [] (map :f ys)
]
]
string-between: function [
x [char!]
ys [string!]
][
either (empty? ys) [reduce [to-string x]][string-between* x ys]
]
string-between*: function [
x [char!]
ys [string!]
][
m1: (reduce [(to-string x) ++ ys])
f: func [y][(to-string (first ys)) ++ y]
zs: string-between x (rest ys)
m2: map :f zs
m1 ++ m2
]
foldl: function [
"reduces the list using the binary operator, from left to right"
f [any-function!]
y
xs [series!]
][
either empty? xs [
y
][
r: y
foreach x xs [r: f r x]
r
]
]
"(a -> a -> a) -> [a] -> a"
foldl1: function [
"A variant of foldl that has no base case, and thus may only be applied to non-empty structures."
f [any-function!]
xs [series!]
][
either empty? xs [none][foldl :f (first xs) (rest xs)]
]
foldr: function [
"reduces the list using the binary operator, from right to left"
g [any-function!]
y
xs [series!]
][
either empty? xs [
y
][
r: y
foreach x (reverse xs) [r: g x r]
r
]
]
;"(a -> a -> a) -> [a] -> a"
foldr1: function [
"A variant of foldr that has no base case, and thus may only be applied to non-empty structures."
f [any-function!]
xs [series!]
][
either empty? xs [none][foldr :f (last xs) (most xs)]
]
concat: function [
"The concatenation of all the elements of a container of lists."
xs [series!]
][
case [
([] == xs) (copy [])
(all (map :string? xs)) (string-concat xs)
(all (map :block? xs)) (block-concat xs)
true none
]
]
block-concat: function [
xs [series!]
][
f: func [y x][y ++ x]
foldl :f [] xs
]
string-concat: function [
xs
][
f: func [y x][y ++ x]
foldl1 :f xs
]
concatMap: function [
"Map a function over all the elements of a container and concatenate the resulting lists."
f [any-function!]
xs [series!]
][
either (string? xs) [
string-concatMap :f xs
][
block-concatMap :f xs
]
]
string-concatMap: function [
f [any-function!]
xs [string!]
][
ys: (map :f xs)
either (string? ys) [ys][concat ys]
]
block-concatMap: function [
f [any-function!]
xs [series!]
][
concat (map :f xs)
]
and': function [
"returns the conjunction of a container of Bools."
xs' [series!]
][
xs: copy xs'
either empty? xs [true][none <> (all xs)]
]
or': function [
"returns the disjunction of a container of Bools."
xs' [series!]
][
xs: copy xs'
either empty? xs [false][none <> (any xs)]
]
any': function [
"Determines whether any element of the structure satisfies the predicate."
f [any-function!]
xs' [series!]
][
xs: copy xs'
r: false
i: 1
while [i <= (length? xs)][
if (f xs/:i) [
r: true
break
]
i: i + 1
]
return r
]
all': function [
"Determines whether any element of the structure satisfies the predicate."
f [any-function!]
xs' [series!]
][
xs: copy xs'
r: true
i: 1
while [i <= (length? xs)][
if (true <> (f xs/:i)) [
r: false
break
]
i: i + 1
]
return r
]
sum: function [
"computes the sum of the numbers of a structure."
xs [series!]
][
case [
[] == (xs) 0
(all [block? xs (map :number? xs)]) (foldl1 func [y x][x + y] xs)
true none]
]
product: function [
"computes the product of the numbers of a structure."
xs [series!]
][
case [
[] == (xs) 1
(all [block? xs (map :number? xs)]) (foldl1 func [y x][x * y] xs)
true none]
]
maximum: function [
"The largest element of a non-empty structure."
xs [series!]
][
case [
[] == (xs) none
(all [(series? xs) (all (map :number? xs))]) (foldl1 func[y x][either y > x [y][x]] xs)
true none]
]
minimum: function [
"The largest element of a non-empty structure."
xs [series!]
][
case [
[] == (xs) none
(all [(series? xs) (all (map :number? xs))]) (foldl1 func[y x][either y < x [y][x]] xs)
true none]
]
scanl: function [
"scanl is similar to foldl, but returns a list of successive reduced values from the left"
f [any-function!]
y
xs [series!]
][
either series? xs [scanl* :f y xs][none]
]
scanl*: function [
"scanl is similar to foldl, but returns a list of successive reduced values from the left"
f [any-function!]
y
xs [series!]
][
either empty? xs [reduce [y]][
ys: [y]
r: y
foreach x xs [
r: f r x
ys: ys ++ (either (char? r) [to-string r][reduce [r]])
]
return ys
]
]
scanl1: function [
"a variant of scanl that has no starting value argument"
f [any-function!]
xs [series!]
][
either (all [(series? xs) (0 < length? xs)]) [scanl* :f (first xs) (rest xs)][none]
]
scanr: function [
"scanr is similar to foldr, but returns a list of successive reduced values from the left"
f' [any-function!]
y
xs [series!]
][
f: func [x' y'][f' y' x']
reverse (scanl :f y (reverse xs))
]
scanr1: function [
"a variant of scanr that has no starting value argument"
f' [any-function!]
xs [series!]
][
f: func [y' x'][f' x' y']
either (all [(series? xs) (0 < (length? xs))]) [
reverse (scanl1 :f reverse xs)
][
none
]
]
replicate: function [
"replicate n x is a list of length n with x the value of every element."
n [integer!]
x
][
xs: either (char? x) [""][copy []]
ys: either (char? x) [to-string x][reduce [x]]
i: 1
while [i <= n][
xs: xs ++ ys
i: i + 1
]
xs
]
take': func [
"applied to a list xs, returns the prefix of xs of length n, or xs itself if n > length? xs"
n [integer!]
xs [series!]
][
case [
(n > (length? xs)) xs
(n <= 0) (either (string? xs) [""][[]])
(n <= (length? xs)) (take* n xs)
]
]
take*: function [
n [integer!]
xs [series!]
][
ys: either (string? xs) [""][copy []]
i: 1
while [
i <= n
][
ys: ys ++ (either (string? xs) [to-string (xs/:i)][reduce [xs/:i]])
i: i + 1]
ys
]
drop: function [
"returns the suffix of xs after the first n elements, or [] if n > length? xs"
n [integer!]
xs [series!]
][
case [
(n <= 0) xs
(n >= (length? xs)) (either (string? xs) [""][[]])
true (drop* n xs)
]
]
drop*: function [
n [integer!]
xs [series!]
][
ys: either (string? xs) [""][copy []]
i: n + 1
while [
i <= (length? xs)
][
ys: ys ++ (either (string? xs) [to-string (xs/:i)][reduce [xs/:i]])
i: i + 1]
ys
]
splitAt: function [
"returns a tuple where first element is xs prefix of length n and second element is the remainder of the list"
n [integer!]
xs [series!]
][
reduce [(take' n xs) (drop n xs)]
]
takeWhile: function [
" applied to a predicate p and a list xs, returns the longest prefix (possibly empty) of xs of elements that satisfy p"
p [any-function!]
xs [series!]
][
either (empty? xs) [xs][takeWhile* :p xs]
]
takeWhile*: function [
p [any-function!]
xs [series!]
][
ys: either (string? xs) [""][copy []]
len: length? xs
i: 1
while [
all [(i <= len) (p (xs/:i))]
][
x: xs/:i
ys: ys ++ (either (char? x) [to-string x][reduce [x]])
i: i + 1
]
return ys
]
dropWhile: function [
"returns the suffix remaining after takeWhile p xs"
p [any-function!]
xs [series!]
][
n: length? (takeWhile :p xs)
drop n xs
]
dropWhileEnd: function [
"returns the suffix remaining after takeWhile p xs"
p [any-function!]
xs [series!]
][
reverse' (dropWhile :p (reverse' xs))
]
span: function [
" applied to a predicate p and a list xs, returns a tuple where first element is longest prefix (possibly empty) of xs of elements that satisfy p and second element is the remainder of the list"
p [any-function!]
xs [series!]
][
reduce [(takeWhile :p xs) (dropWhile :p xs)]
]
break': function [
"applied to a predicate p and a list xs, returns a tuple where first element is longest prefix (possibly empty) of xs of elements that do not satisfy p and second element is the remainder of the list"
p [any-function!]
xs [series!]
][
span func [x][not p x] xs
]
stripPrefix: function [
"drops the given prefix from a list. It returns Nothing if the list did not start with the prefix given, or Just the list after the prefix, if it does."
xs [series!]
ys [series!]
][
either empty? xs [ys][stripPrefix* xs ys]
]
stripPrefix*: function [
xs [series!]
ys [series!]
][
n: length? xs
either xs == (take' n ys) [drop n ys][none]
]
group: function [
"takes a list and returns a list of lists such that the concatenation of the result is equal to the argument. Moreover, each sublist in the result contains only equal elements."
xs [series!]
][
groupBy func [y x][y == x] xs
]
inits: function [
"returns all initial segments of the argument, shortest first."
xs [series!]
][
xss: either string? xs [[""]][[[]]]
to-series: func [x][either (char? x) [to-string x][reduce [x]]]
f: func [yss x][yss: yss ++ [(last yss) ++ (to-series x)]]
foldl :f xss xs
]
tails: function [
"returns all final segments of the argument, longest first."
xs [series!]
][
reverse' (map :reverse' (inits (reverse xs)))
]
isPrefixOf: function [
" takes two lists and returns True iff the first list is a prefix of the second."
xs [series!]
ys [series!]
][
n: length? xs
xs == (take' n ys)
]
isSuffixOf: function [
"takes two lists and returns True iff the first list is a suffix of the second."
xs [series!]
ys [series!]
][
n: length? xs
(reverse' xs) == (take' n (reverse' ys))
]
isInfixOf: function [
"takes two lists and returns True iff the first list is contained, wholly and intact, anywhere within the second."
xs [series!]
ys [series!]
][
case [
(empty? xs) true
(none == (find ys xs)) false
true true
]
]
isSubsequenceOf: function [
"takes two lists and returns True if all the elements of the first list occur, in order, in the second. The elements do not have to occur consecutively."
xs [series!]
ys [series!]
][
either (empty? xs) [true][isSubsequenceOf* xs ys]
]
isSubsequenceOf*: function [
xs [series!]
ys [series!]
][
either (empty? xs) [
return true
][
zs: find ys (first xs)
either zs == none [false][isSubsequenceOf* (rest xs) zs]
]
]
;; Searching lists
;; Searching by equality
elem: function [
"Does the element occur in the structure?"
x
xs [series!]
][
none <> (find xs x)
]
notElem: function [
"notElem is the negation of elem."
x
xs [series!]
][
none == (find xs x)
]
lookup: function [
"looks up a key in a association list (map)"
key
m [map!]
][
get 'm/:key
]
;;Searching with a predicate
find': function [
"takes a predicate and a structure and returns the leftmost element of the structure matching the predicate, or Nothing if there is no such element."
predicate-f [any-function!]
xs [series!]
][
either empty? xs [none][find'* :predicate-f xs]
]
find'*: function [
predicate-f [any-function!]
xs' [series!]
][
xs: copy xs'
found: false
while [all [(not found) (not tail? xs)]][
x: first xs
found: predicate-f x
xs: next xs
]
either found [x][none]
]
filter: function [
"applying a predicate f to xs"
f [any-function!]
xs [series!]
][
yss: either string? xs [copy ""][copy []]
g: func [ys x][either f x [append ys reduce [x]][ys]]
zss: foldl :g yss xs
]
partition: function [
"takes a predicate and a structure and returns the leftmost element of the structure matching the predicate, or Nothing if there is no such element."
f [any-function!]
xs [series!]
][
reduce [(filter :f xs) (filter func[x][not f x] xs)]
]
;;Indexing lists
list-index*: function [
"List index (subscript) operator, starting from 0."
xs [series!]
i [integer!]
][
xs/(i + 1)
]
!!: make op! :list-index*
elemIndex: function [
"returns the index of the first element in the given list which is equal (by ==) to the query element, or Nothing if there is no such element."
x
xs [series!]
][
ys: find/case xs x
either (ys == none) [none][offset? xs ys]
]
elemIndices: function [
"returning the indices of all elements equal to the query element, in ascending order."
x
xs [series!]
][
ys: copy []
len: length? xs
i: 1
while [i <= len][
ys: either (x == xs/:i)[ys ++ (reduce [(i - 1)])][ys]
i: i + 1
]
return ys
]
findIndex: function [
"takes a predicate and a list and returns the index of the first element in the list satisfying the predicate, or Nothing if there is no such element."
f [any-function!]
xs [series!]
][
len: length? xs
i: 1
r: none
while [i <= len][
either (f xs/:i) == true [
(r: (i - 1))
break
][
i: i + 1
]
]
return r
]
findIndices: function [
"extends findIndex, by returning the indices of all elements satisfying the predicate, in ascending order."
f [any-function!]
xs [series!]
][
len: length? xs
i: 1
rs: []
while [i <= len][
rs: either (f xs/:i) == true [rs ++ (reduce [i - 1])][rs]
i: i + 1
]
return rs
]
;;Zipping and unzipping lists
zip: function [
"takes two lists and returns a list of corresponding pairs. If one input list is short, excess elements of the longer list are discarded."
xs [series!]
ys [series!]
][
zss: copy []
len: min (length? xs) (length? ys)
repeat i :len [
xy: reduce [xs/:i ys/:i]
zss: zss ++ (reduce [xy])
]
return zss
]
zip3: function [
"takes three lists and returns a list of triples, analogous to zip."
xs [series!]
ys [series!]
zs [series!]
][
zss: copy []
len: minimum (reduce (map :length? reduce [xs ys zs]))
repeat i :len [
xyz: reduce [xs/:i ys/:i zs/:i]
zss: zss ++ (reduce [xyz])
]
return zss
]
zip4: function [
"takes four lists and returns a list of quadruples, analogous to zip."
xs [series!]
ys [series!]
zs [series!]
us [series!]
][
zss: copy []
len: minimum (reduce (map :length? reduce [xs ys zs us]))
repeat i :len [
xyzu: reduce [xs/:i ys/:i zs/:i us/:i]
zss: zss ++ (reduce [xyzu])
]
return zss
]
zip5: function [
"takes four lists and returns a list of five-tuples, analogous to zip."
xs [series!]
ys [series!]
zs [series!]
us [series!]
vs [series!]
][
zss: copy []
len: minimum (reduce (map :length? reduce [xs ys zs us vs]))
repeat i :len [
xyzuv: reduce [xs/:i ys/:i zs/:i us/:i vs/:i]
zss: zss ++ (reduce [xyzuv])
]
return zss
]
zip6: function [
"takes four lists and returns a list of six-tuples, analogous to zip."
xs [series!]
ys [series!]
zs [series!]
us [series!]
vs [series!]
ws [series!]
][
zss: copy []
len: minimum (reduce (map :length? reduce [xs ys zs us vs ws]))
repeat i :len [
xyzuvw: reduce [xs/:i ys/:i zs/:i us/:i vs/:i ws/:i]
zss: zss ++ (reduce [xyzuvw])
]
return zss
]
zip7: function [
"takes four lists and returns a list of seven-tuples, analogous to zip."
xs [series!]
ys [series!]
zs [series!]
us [series!]
vs [series!]
ws [series!]
ts [series!]