Skip to content

collections

Group IRX-specific collection-oriented AST helpers behind one stable package boundary while re-exporting the current public node names.

Modules:

Classes:

CollectionContains

CollectionContains(base: AST, value: AST)

Bases: DataType

Return whether a list, tuple, or set contains a value, or whether a dictionary contains a key. attributes: base: type: astx.AST value: type: astx.AST type_: type: astx.Boolean

Methods:

Source code in packages/irx/src/irx/astx/collections/common.py
131
132
133
134
135
136
137
138
139
140
141
142
143
def __init__(self, base: astx.AST, value: astx.AST) -> None:
    """
    title: Initialize one collection containment query.
    parameters:
      base:
        type: astx.AST
      value:
        type: astx.AST
    """
    super().__init__()
    self.base = base
    self.value = value
    self.type_ = astx.Boolean()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/collections/common.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    return self._prepare_struct(
        "CollectionContains",
        cast(
            astx.base.ReprStruct,
            {
                "base": self.base.get_struct(simplified),
                "value": self.value.get_struct(simplified),
            },
        ),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

CollectionCount

CollectionCount(base: AST, value: AST)

Bases: DataType

Return how many times a value appears in a list or tuple as an Int32 value. attributes: base: type: astx.AST value: type: astx.AST type_: type: astx.Int32

Methods:

Source code in packages/irx/src/irx/astx/collections/common.py
243
244
245
246
247
248
249
250
251
252
253
254
255
def __init__(self, base: astx.AST, value: astx.AST) -> None:
    """
    title: Initialize one sequence count query.
    parameters:
      base:
        type: astx.AST
      value:
        type: astx.AST
    """
    super().__init__()
    self.base = base
    self.value = value
    self.type_ = astx.Int32()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/collections/common.py
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    return self._prepare_struct(
        "CollectionCount",
        cast(
            astx.base.ReprStruct,
            {
                "base": self.base.get_struct(simplified),
                "value": self.value.get_struct(simplified),
            },
        ),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

CollectionIndex

CollectionIndex(base: AST, value: AST)

Bases: DataType

Return the first zero-based index of a value in a list or tuple. The initial IRx contract returns -1 when the value is not found. attributes: base: type: astx.AST value: type: astx.AST type_: type: astx.Int32

Methods:

Source code in packages/irx/src/irx/astx/collections/common.py
187
188
189
190
191
192
193
194
195
196
197
198
199
def __init__(self, base: astx.AST, value: astx.AST) -> None:
    """
    title: Initialize one sequence index query.
    parameters:
      base:
        type: astx.AST
      value:
        type: astx.AST
    """
    super().__init__()
    self.base = base
    self.value = value
    self.type_ = astx.Int32()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/collections/common.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    return self._prepare_struct(
        "CollectionIndex",
        cast(
            astx.base.ReprStruct,
            {
                "base": self.base.get_struct(simplified),
                "value": self.value.get_struct(simplified),
            },
        ),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

CollectionIsEmpty

CollectionIsEmpty(base: AST)

Bases: DataType

Return whether a list, tuple, set, or dictionary has no logical entries. attributes: base: type: astx.AST type_: type: astx.Boolean

Methods:

Source code in packages/irx/src/irx/astx/collections/common.py
81
82
83
84
85
86
87
88
89
90
def __init__(self, base: astx.AST) -> None:
    """
    title: Initialize one collection emptiness query.
    parameters:
      base:
        type: astx.AST
    """
    super().__init__()
    self.base = base
    self.type_ = astx.Boolean()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/collections/common.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    return self._prepare_struct(
        "CollectionIsEmpty",
        cast(
            astx.base.ReprStruct,
            {"base": self.base.get_struct(simplified)},
        ),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

CollectionLength

CollectionLength(base: AST)

Bases: DataType

Return the logical length of a list, tuple, set, or dictionary as an Int32 value. attributes: base: type: astx.AST type_: type: astx.Int32

Methods:

Source code in packages/irx/src/irx/astx/collections/common.py
35
36
37
38
39
40
41
42
43
44
def __init__(self, base: astx.AST) -> None:
    """
    title: Initialize one collection length query.
    parameters:
      base:
        type: astx.AST
    """
    super().__init__()
    self.base = base
    self.type_ = astx.Int32()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/collections/common.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    return self._prepare_struct(
        "CollectionLength",
        cast(
            astx.base.ReprStruct,
            {"base": self.base.get_struct(simplified)},
        ),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ListAppend

ListAppend(base: AST, value: AST)

Bases: DataType

Append one value to an existing mutable list variable or field. This node models incremental list growth and is not a user-facing collection API by itself. attributes: base: type: astx.AST value: type: astx.AST type_: type: astx.Int32

Methods:

Source code in packages/irx/src/irx/astx/collections/list.py
140
141
142
143
144
145
146
147
148
149
150
151
152
def __init__(self, base: astx.AST, value: astx.AST) -> None:
    """
    title: Initialize one list append node.
    parameters:
      base:
        type: astx.AST
      value:
        type: astx.AST
    """
    super().__init__()
    self.base = base
    self.value = value
    self.type_ = astx.Int32()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/collections/list.py
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    return self._prepare_struct(
        "ListAppend",
        cast(
            astx.base.ReprStruct,
            {
                "base": self.base.get_struct(simplified),
                "value": self.value.get_struct(simplified),
            },
        ),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ListCreate

ListCreate(element_type: DataType)

Bases: DataType

Methods:

Source code in packages/irx/src/irx/astx/collections/list.py
34
35
36
37
38
39
40
41
42
43
def __init__(self, element_type: astx.DataType) -> None:
    """
    title: Initialize one empty-list constructor.
    parameters:
      element_type:
        type: astx.DataType
    """
    super().__init__()
    self.element_type = element_type
    self.type_ = astx.ListType([element_type])

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/collections/list.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    return self._prepare_struct(
        "ListCreate",
        cast(
            astx.base.ReprStruct,
            {"element_type": self.element_type.get_struct(simplified)},
        ),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ListIndex

ListIndex(base: AST, index: AST)

Bases: DataType

Read one element from a list-valued expression using one integer index. attributes: base: type: astx.AST index: type: astx.AST type_: type: astx.DataType

Methods:

Source code in packages/irx/src/irx/astx/collections/list.py
83
84
85
86
87
88
89
90
91
92
93
94
95
def __init__(self, base: astx.AST, index: astx.AST) -> None:
    """
    title: Initialize one list indexing expression.
    parameters:
      base:
        type: astx.AST
      index:
        type: astx.AST
    """
    super().__init__()
    self.base = base
    self.index = index
    self.type_ = AnyType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/collections/list.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    return self._prepare_struct(
        "ListIndex",
        cast(
            astx.base.ReprStruct,
            {
                "base": self.base.get_struct(simplified),
                "index": self.index.get_struct(simplified),
            },
        ),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ListLength

ListLength(base: AST)

Bases: DataType

Return the current logical length of one list-valued expression as an int32 value. The runtime stores list lengths as int64, but the current IRx language-level contract intentionally truncates that representation to Int32. attributes: base: type: astx.AST type_: type: astx.Int32

Methods:

Source code in packages/irx/src/irx/astx/collections/list.py
195
196
197
198
199
200
201
202
203
204
def __init__(self, base: astx.AST) -> None:
    """
    title: Initialize one list length query.
    parameters:
      base:
        type: astx.AST
    """
    super().__init__()
    self.base = base
    self.type_ = astx.Int32()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/collections/list.py
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    return self._prepare_struct(
        "ListLength",
        cast(
            astx.base.ReprStruct,
            {"base": self.base.get_struct(simplified)},
        ),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )