You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
@@ -12,34 +12,162 @@ into one unit. Each element in a collection is a
12
12
13
13
##Introduction
14
14
15
-
Collections are**immutable**. They cannot be modified. Operations on
16
-
collections produce new collections.
15
+
Collections are**immutable**: they cannot be modified in place.
16
+
Operations oncollections produce new collections.
17
17
18
-
There are several types of collections in the Compute Engine:
19
-
-**Lists**: ordered collections of elements, which are also used to represent
20
-
**vectors** and**matrices**. Elements in a list are accessed by their
21
-
index, which starts at 1.
22
-
-**Sets**: unordered collections of unique elements. The elements in a set are
23
-
not accessed by index, they are enumerated. A set can contain an infinite number
24
-
of elements.
25
-
-**Tuples**: ordered collections of elements, but with a fixed number of elements that have a specific type and an optional name.
26
-
-**Records**: unordered collections of key-value pairs.
27
-
-**Ranges** and**Linear Spaces (linspaces)**: ordered sequences of numbers (integers and reals, respectively) with a specified start, end and step size.
18
+
The most common collection types are:
19
+
-[**List**](#list): ordered collection of elements (duplicates allowed)
20
+
-[**Set**](#set): unordered collection of unique elements
21
+
-[**Tuple**](#tuple): ordered, fixed-size collection with optional names
22
+
-[**Dictionary**](#dictionary): unordered key-value pairs with string keys
23
+
-[**Record**](#record): structured data with a fixed set of known string keys
28
24
25
+
You can use collections to represent mathematical vectors, matrices, sequences, mappings, or records — in both finite and infinite forms.
See also the**Linear Algebra** section for operations on vectors, matrices andtensors.<Iconname="chevron-right-bold" />
28
+
See also the**Linear Algebra** section for operations on vectors, matrices,tensors which are a special kind of collection.<Iconname="chevron-right-bold" />
32
29
</ReadMore>
33
30
34
31
35
-
###Operations on Collections
36
32
37
-
Operations creating new collections:
38
-
-[**List**](#list),[**Range**](#range),[**Linspace**](#linspace),[**Set**](#set): create a new collection from some values.
39
-
-[**Fill**](#fill),[**Repeat**](#repeat),[**Cycle**](#cycle),[**Iterate**](#iterate): create a new collection from a function or a value.
33
+
###Core Properties of Collections
34
+
35
+
All collections share these basic properties:
36
+
- Their elements can be**enumerated**
37
+
- They can check whether an element is a**member** of the collection
38
+
- The number of elements can be**counted**
39
+
40
+
**Note:** Depending on the type of collection, counting and membership checking can be an expensive operation, for example, for lazy infinite collections.
41
+
42
+
43
+
###Finite and Infinite Collections
44
+
45
+
Collections may be:
46
+
-**Finite**: containing a definite number of elements.
47
+
-**Infinite**: continuing indefinitely (for example, a sequence of all natural numbers).
48
+
49
+
Compute Engine supports**lazy evaluation** to make working with infinite collections possible.
50
+
51
+
52
+
###Lazy and Strict Collections
53
+
54
+
Collections can be:
55
+
-**Strict**: elements are fully evaluated when the collection is created.
56
+
-**Lazy**: elements are evaluated only as they are accessed.
57
+
58
+
Lazy collections are useful when working with infinite sequences or with expensive computations.
59
+
60
+
You can convert a lazy collection to a strict collection using`ListFrom` or`SetFrom`.
61
+
These functions enumerate all elements (if finite) and produce a strict result.
62
+
63
+
```json example
64
+
["ListFrom", ["Range",1,10]]
65
+
// ➔ ["List", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
66
+
```
67
+
68
+
###Why Lazy Infinite Collections?
69
+
70
+
Lazy infinite collections provide a natural way to model mathematical sequences, iterative processes, or cyclic patterns — with minimal memory use.
Collections like`Range`,`Cycle`,`Iterate`,`Repeat` create**lazy collections** that behave like infinite Lists, unless a strict conversion or truncation (e.g. with`Take()`) is used.
107
+
108
+
---
109
+
110
+
111
+
###Ordered Collections
112
+
113
+
The elements of some collections can be accessed by their**index**, a
114
+
number that indicates the position of the element in the collection.
115
+
116
+
Collections that can be accessed by index are called**ordered collections**.
117
+
118
+
The first element has index`1`, the second element has index`2`, and so on. The last
119
+
element has index equal to the length of the collection.
120
+
121
+
Negative indexes can also be used to access elements from the end of the
122
+
collection.
123
+
124
+
The last element has index`-1`, the second to last element has index`-2`,
125
+
and so on. This is useful for accessing elements without knowing the length of the
126
+
collection.
127
+
128
+
```json example
129
+
["At", ["List",2,5,7,11],3]
130
+
// ➔ 7
131
+
132
+
["At", ["List",2,5,7,11],-3]
133
+
// ➔ 5
134
+
```
135
+
136
+
137
+
138
+
Some of the collections in the Compute Engine include:
139
+
-[**List**](#list): ordered collections of elements, which are also used to represent
140
+
**vectors** and**matrices**. Elements in a list are accessed by their
141
+
index, which starts at 1. Type:`list<T>` where`T` is the type of the elements.
142
+
-[**Set**](#set): unordered collections of unique elements. The elements in a set are
143
+
not accessed by index, they are enumerated. A set can contain an infinite number
144
+
of elements. Type :`set<T>` where`T` is the type of the elements.
145
+
-[**Tuple**](#tuple): ordered collections of elements, but with a fixed number
146
+
of elements that have a specific type and an optional name. Type :`tuple<T1, T2, ..., Tn>` where`T1`,`T2`, ...,`Tn` are the types of the elements.
147
+
-[**Dictionary**](#dictionary): unordered collections of key-value pairs,
148
+
where each key is unique. Type:`dictionary<V>` where`V` is the type of the values, the keys are strings.
149
+
-[**Record**](#record): unordered collections of key-value pairs. Unlike dictionaries, records are used to represent structured data with a fixed set of keys, and the keys are known at compile time.
150
+
Type:`record<K1: T1, K2: T2, ..., Kn: Tn>` where`K1`,`K2`, ...,`Kn` are the keys and`T1`,`T2`, ...,`Tn` are the types of the values.
151
+
152
+
Some functions evaluate to a lazy collection. This is useful for creating
153
+
infinite collections or for collections that are expensive to compute. Examples of lazy collections include:
154
+
155
+
-[**Range**](#range) and[**Linspace**](#linspace): ordered sequences of numbers (integers and reals, respectively) with a specified start, end and step size.
156
+
-[**Cycle**](#cycle): infinite collections that repeat a finite collection.
157
+
-[**Iterate**](#iterate): infinite collections that apply a function to an initial value repeatedly.
158
+
-[**Repeat**](#repeat): infinite collections that repeat a single value.
159
+
-[**Fill**](#fill): collections of a specified size, where each element is computed by a function or set to a specific value.
160
+
161
+
The type`collection` is used to represent any collection, whether it is ordered or unordered, finite or infinite.
162
+
The type`ordered collection` is used to represent collections that can be accessed by index, such as`List`,`Tuple`, and`Dictionary`.
163
+
164
+
165
+
166
+
###Operations on Collections
40
167
41
168
Operations on ordered and unordered collections:
42
-
-[**Length**](#length),[**IsEmpty**](#isempty): check the size of a collection.
169
+
-[**Filter**](#filter),[**Map**](#map), and[**Reduce**](#reduce): operations that create new collections by applying a function to each element of an existing collection.
170
+
-[**Length**](#length),[**IsEmpty**](#isempty): check the number of elements of a collection.
43
171
-[**Filter**](#filter),[**Map**](#map),[**Reduce**](#reduce): apply a function to each element of a collection.
44
172
-[**Join**](#join),[**Zip**](#zip): combine multiple collections into one.
45
173
-[**Tally**](#tally): count the number of occurrences of each element in a collection.
@@ -54,26 +182,16 @@ Operations on ordered collections:
54
182
-[**Unique**](#unique): remove duplicates from a collection.
55
183
-[**RotateLeft**](#rotateleft),[**RotateRight**](#rotateright): rotate a collection to the left or right.
See also the**Linear Algebra** section for operations on vectors, matrices, tensors which are a special kind of collection.<Iconname="chevron-right-bold" />
187
+
</ReadMore>
57
188
58
-
###Indexing Collections
59
-
60
-
Ordered collections (lists, tuples, ranges and linspaces) are indexed starting from 1. Negative indexes count from the end of
61
-
the collection. For example,`-1` is the last element,`-2` is the second to last
62
-
element, etc.
63
-
64
-
```json example
65
-
["At", ["List",2,5,7,11],-2]
66
-
// ➔ 7
67
-
68
-
["At", ["Range",2,10],-1]
69
-
// ➔ ["List", 10]
70
-
```
71
189
72
190
73
191
74
192
##Creating Collections
75
193
76
-
This section contains functions that create new collections from somevalues.
194
+
This section contains functions that create new collections from someelements.
77
195
78
196
<divstyle={{visibility:"hidden"}}>
79
197
###List
@@ -83,7 +201,7 @@ This section contains functions that create new collections from some values.