orionis 0.712.0__py3-none-any.whl → 0.713.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- orionis/metadata/framework.py +1 -1
- orionis/support/collections/__init__.py +0 -0
- orionis/support/collections/collection.py +1381 -0
- orionis/support/collections/contracts/__init__.py +0 -0
- orionis/support/collections/contracts/collection.py +766 -0
- {orionis-0.712.0.dist-info → orionis-0.713.0.dist-info}/METADATA +1 -1
- {orionis-0.712.0.dist-info → orionis-0.713.0.dist-info}/RECORD +10 -6
- {orionis-0.712.0.dist-info → orionis-0.713.0.dist-info}/WHEEL +0 -0
- {orionis-0.712.0.dist-info → orionis-0.713.0.dist-info}/licenses/LICENCE +0 -0
- {orionis-0.712.0.dist-info → orionis-0.713.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,766 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Any, Callable, Dict, List, Optional, Union
|
|
3
|
+
|
|
4
|
+
class ICollection(ABC):
|
|
5
|
+
|
|
6
|
+
@abstractmethod
|
|
7
|
+
def take(self, number: int) -> 'ICollection':
|
|
8
|
+
"""Take a specific number of results from the items.
|
|
9
|
+
|
|
10
|
+
Parameters
|
|
11
|
+
----------
|
|
12
|
+
number : int
|
|
13
|
+
The number of results to take. If negative, takes from the end.
|
|
14
|
+
|
|
15
|
+
Returns
|
|
16
|
+
-------
|
|
17
|
+
Collection
|
|
18
|
+
A new collection with the specified number of items.
|
|
19
|
+
"""
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def first(self, callback: Optional[Callable] = None) -> Any:
|
|
24
|
+
"""Get the first result in the items.
|
|
25
|
+
|
|
26
|
+
Parameters
|
|
27
|
+
----------
|
|
28
|
+
callback : callable, optional
|
|
29
|
+
Filter function to apply before returning the first item, by default None
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
mixed
|
|
34
|
+
The first item in the collection, or None if empty.
|
|
35
|
+
"""
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
@abstractmethod
|
|
39
|
+
def last(self, callback: Optional[Callable] = None) -> Any:
|
|
40
|
+
"""Get the last result in the items.
|
|
41
|
+
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
callback : callable, optional
|
|
45
|
+
Filter function to apply before returning the last item, by default None
|
|
46
|
+
|
|
47
|
+
Returns
|
|
48
|
+
-------
|
|
49
|
+
mixed
|
|
50
|
+
The last item in the collection.
|
|
51
|
+
"""
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
@abstractmethod
|
|
55
|
+
def all(self) -> List[Any]:
|
|
56
|
+
"""Get all items in the collection.
|
|
57
|
+
|
|
58
|
+
Returns
|
|
59
|
+
-------
|
|
60
|
+
list
|
|
61
|
+
All items in the collection.
|
|
62
|
+
"""
|
|
63
|
+
pass
|
|
64
|
+
|
|
65
|
+
@abstractmethod
|
|
66
|
+
def avg(self, key: Optional[str] = None) -> float:
|
|
67
|
+
"""Calculate the average of the items.
|
|
68
|
+
|
|
69
|
+
Parameters
|
|
70
|
+
----------
|
|
71
|
+
key : str, optional
|
|
72
|
+
The key to use for calculating the average of values, by default None
|
|
73
|
+
|
|
74
|
+
Returns
|
|
75
|
+
-------
|
|
76
|
+
float
|
|
77
|
+
The average value.
|
|
78
|
+
"""
|
|
79
|
+
pass
|
|
80
|
+
|
|
81
|
+
@abstractmethod
|
|
82
|
+
def max(self, key: Optional[str] = None) -> Any:
|
|
83
|
+
"""Get the maximum value from the items.
|
|
84
|
+
|
|
85
|
+
Parameters
|
|
86
|
+
----------
|
|
87
|
+
key : str, optional
|
|
88
|
+
The key to use for finding the maximum value, by default None
|
|
89
|
+
|
|
90
|
+
Returns
|
|
91
|
+
-------
|
|
92
|
+
mixed
|
|
93
|
+
The maximum value.
|
|
94
|
+
"""
|
|
95
|
+
pass
|
|
96
|
+
|
|
97
|
+
@abstractmethod
|
|
98
|
+
def min(self, key: Optional[str] = None) -> Any:
|
|
99
|
+
"""Get the minimum value from the items.
|
|
100
|
+
|
|
101
|
+
Parameters
|
|
102
|
+
----------
|
|
103
|
+
key : str, optional
|
|
104
|
+
The key to use for finding the minimum value, by default None
|
|
105
|
+
|
|
106
|
+
Returns
|
|
107
|
+
-------
|
|
108
|
+
mixed
|
|
109
|
+
The minimum value.
|
|
110
|
+
"""
|
|
111
|
+
pass
|
|
112
|
+
|
|
113
|
+
@abstractmethod
|
|
114
|
+
def chunk(self, size: int) -> 'ICollection':
|
|
115
|
+
"""Break the collection into multiple smaller collections of a given size.
|
|
116
|
+
|
|
117
|
+
Parameters
|
|
118
|
+
----------
|
|
119
|
+
size : int
|
|
120
|
+
The number of values in each chunk.
|
|
121
|
+
|
|
122
|
+
Returns
|
|
123
|
+
-------
|
|
124
|
+
Collection
|
|
125
|
+
A new collection containing the chunks.
|
|
126
|
+
"""
|
|
127
|
+
pass
|
|
128
|
+
|
|
129
|
+
@abstractmethod
|
|
130
|
+
def collapse(self) -> 'ICollection':
|
|
131
|
+
"""Collapse the collection of arrays into a single, flat collection.
|
|
132
|
+
|
|
133
|
+
Returns
|
|
134
|
+
-------
|
|
135
|
+
Collection
|
|
136
|
+
A new flattened collection.
|
|
137
|
+
"""
|
|
138
|
+
pass
|
|
139
|
+
|
|
140
|
+
@abstractmethod
|
|
141
|
+
def contains(self, key: Union[str, Callable], value: Any = None) -> bool:
|
|
142
|
+
"""Determine if the collection contains a given item.
|
|
143
|
+
|
|
144
|
+
Parameters
|
|
145
|
+
----------
|
|
146
|
+
key : mixed
|
|
147
|
+
The key or callback function to check for
|
|
148
|
+
value : mixed, optional
|
|
149
|
+
The value to match when key is a string, by default None
|
|
150
|
+
|
|
151
|
+
Returns
|
|
152
|
+
-------
|
|
153
|
+
bool
|
|
154
|
+
True if the item is found, False otherwise.
|
|
155
|
+
"""
|
|
156
|
+
pass
|
|
157
|
+
|
|
158
|
+
@abstractmethod
|
|
159
|
+
def count(self) -> int:
|
|
160
|
+
"""Get the number of items in the collection.
|
|
161
|
+
|
|
162
|
+
Returns
|
|
163
|
+
-------
|
|
164
|
+
int
|
|
165
|
+
The number of items.
|
|
166
|
+
"""
|
|
167
|
+
pass
|
|
168
|
+
|
|
169
|
+
@abstractmethod
|
|
170
|
+
def diff(self, items: Union[List[Any], 'ICollection']) -> 'ICollection':
|
|
171
|
+
"""Get the items that are not present in the given collection.
|
|
172
|
+
|
|
173
|
+
Parameters
|
|
174
|
+
----------
|
|
175
|
+
items : mixed
|
|
176
|
+
The items to diff against
|
|
177
|
+
|
|
178
|
+
Returns
|
|
179
|
+
-------
|
|
180
|
+
Collection
|
|
181
|
+
A new collection with the difference.
|
|
182
|
+
"""
|
|
183
|
+
pass
|
|
184
|
+
|
|
185
|
+
@abstractmethod
|
|
186
|
+
def each(self, callback: Callable) -> 'ICollection':
|
|
187
|
+
"""Iterate over the items in the collection and pass each item to the given callback.
|
|
188
|
+
|
|
189
|
+
Parameters
|
|
190
|
+
----------
|
|
191
|
+
callback : callable
|
|
192
|
+
The callback function to apply to each item
|
|
193
|
+
|
|
194
|
+
Returns
|
|
195
|
+
-------
|
|
196
|
+
Collection
|
|
197
|
+
The current collection instance.
|
|
198
|
+
"""
|
|
199
|
+
pass
|
|
200
|
+
|
|
201
|
+
@abstractmethod
|
|
202
|
+
def every(self, callback: Callable) -> bool:
|
|
203
|
+
"""Determine if all items pass the given callback test.
|
|
204
|
+
|
|
205
|
+
Parameters
|
|
206
|
+
----------
|
|
207
|
+
callback : callable
|
|
208
|
+
The callback function to test each item
|
|
209
|
+
|
|
210
|
+
Returns
|
|
211
|
+
-------
|
|
212
|
+
bool
|
|
213
|
+
True if all items pass the test, False otherwise.
|
|
214
|
+
"""
|
|
215
|
+
pass
|
|
216
|
+
|
|
217
|
+
@abstractmethod
|
|
218
|
+
def filter(self, callback: Callable) -> 'ICollection':
|
|
219
|
+
"""Filter the collection using the given callback.
|
|
220
|
+
|
|
221
|
+
Parameters
|
|
222
|
+
----------
|
|
223
|
+
callback : callable
|
|
224
|
+
The callback function to filter items
|
|
225
|
+
|
|
226
|
+
Returns
|
|
227
|
+
-------
|
|
228
|
+
Collection
|
|
229
|
+
A new filtered collection.
|
|
230
|
+
"""
|
|
231
|
+
pass
|
|
232
|
+
|
|
233
|
+
@abstractmethod
|
|
234
|
+
def flatten(self) -> 'ICollection':
|
|
235
|
+
"""Flatten a multi-dimensional collection into a single dimension.
|
|
236
|
+
|
|
237
|
+
Returns
|
|
238
|
+
-------
|
|
239
|
+
Collection
|
|
240
|
+
A new flattened collection.
|
|
241
|
+
"""
|
|
242
|
+
pass
|
|
243
|
+
|
|
244
|
+
@abstractmethod
|
|
245
|
+
def forget(self, *keys: Any) -> 'ICollection':
|
|
246
|
+
"""Remove an item from the collection by key.
|
|
247
|
+
|
|
248
|
+
Parameters
|
|
249
|
+
----------
|
|
250
|
+
*keys : mixed
|
|
251
|
+
The keys to remove from the collection
|
|
252
|
+
|
|
253
|
+
Returns
|
|
254
|
+
-------
|
|
255
|
+
Collection
|
|
256
|
+
The current collection instance.
|
|
257
|
+
"""
|
|
258
|
+
pass
|
|
259
|
+
|
|
260
|
+
@abstractmethod
|
|
261
|
+
def forPage(self, page: int, number: int) -> 'ICollection':
|
|
262
|
+
"""Slice the underlying collection array for pagination.
|
|
263
|
+
|
|
264
|
+
Parameters
|
|
265
|
+
----------
|
|
266
|
+
page : int
|
|
267
|
+
The page number
|
|
268
|
+
number : int
|
|
269
|
+
Number of items per page
|
|
270
|
+
|
|
271
|
+
Returns
|
|
272
|
+
-------
|
|
273
|
+
Collection
|
|
274
|
+
A new collection with the paginated items.
|
|
275
|
+
"""
|
|
276
|
+
pass
|
|
277
|
+
|
|
278
|
+
@abstractmethod
|
|
279
|
+
def get(self, key: Any, default: Any = None) -> Any:
|
|
280
|
+
"""Get an item from the collection by key.
|
|
281
|
+
|
|
282
|
+
Parameters
|
|
283
|
+
----------
|
|
284
|
+
key : mixed
|
|
285
|
+
The key to retrieve
|
|
286
|
+
default : mixed, optional
|
|
287
|
+
The default value to return if key not found, by default None
|
|
288
|
+
|
|
289
|
+
Returns
|
|
290
|
+
-------
|
|
291
|
+
mixed
|
|
292
|
+
The item at the specified key or default value.
|
|
293
|
+
"""
|
|
294
|
+
pass
|
|
295
|
+
|
|
296
|
+
@abstractmethod
|
|
297
|
+
def implode(self, glue: str = ",", key: Optional[str] = None) -> str:
|
|
298
|
+
"""Join all items from the collection using a string.
|
|
299
|
+
|
|
300
|
+
Parameters
|
|
301
|
+
----------
|
|
302
|
+
glue : str, optional
|
|
303
|
+
The string to use for joining, by default ","
|
|
304
|
+
key : str, optional
|
|
305
|
+
The key to pluck from items before joining, by default None
|
|
306
|
+
|
|
307
|
+
Returns
|
|
308
|
+
-------
|
|
309
|
+
str
|
|
310
|
+
The joined string.
|
|
311
|
+
"""
|
|
312
|
+
pass
|
|
313
|
+
|
|
314
|
+
@abstractmethod
|
|
315
|
+
def isEmpty(self) -> bool:
|
|
316
|
+
"""Determine if the collection is empty.
|
|
317
|
+
|
|
318
|
+
Returns
|
|
319
|
+
-------
|
|
320
|
+
bool
|
|
321
|
+
True if the collection is empty, False otherwise.
|
|
322
|
+
"""
|
|
323
|
+
pass
|
|
324
|
+
|
|
325
|
+
@abstractmethod
|
|
326
|
+
def map(self, callback: Callable) -> 'ICollection':
|
|
327
|
+
"""Run a map over each of the items.
|
|
328
|
+
|
|
329
|
+
Parameters
|
|
330
|
+
----------
|
|
331
|
+
callback : callable
|
|
332
|
+
The callback function to apply to each item
|
|
333
|
+
|
|
334
|
+
Returns
|
|
335
|
+
-------
|
|
336
|
+
Collection
|
|
337
|
+
A new collection with the mapped items.
|
|
338
|
+
"""
|
|
339
|
+
pass
|
|
340
|
+
|
|
341
|
+
@abstractmethod
|
|
342
|
+
def mapInto(self, cls: type, method: Optional[str] = None, **kwargs: Any) -> 'ICollection':
|
|
343
|
+
"""Map items into instances of the given class.
|
|
344
|
+
|
|
345
|
+
Parameters
|
|
346
|
+
----------
|
|
347
|
+
cls : class
|
|
348
|
+
The class to map items into
|
|
349
|
+
method : str, optional
|
|
350
|
+
The method to call on the class, by default None
|
|
351
|
+
**kwargs : dict
|
|
352
|
+
Additional keyword arguments to pass to the constructor or method
|
|
353
|
+
|
|
354
|
+
Returns
|
|
355
|
+
-------
|
|
356
|
+
Collection
|
|
357
|
+
A new collection with the mapped instances.
|
|
358
|
+
"""
|
|
359
|
+
pass
|
|
360
|
+
|
|
361
|
+
@abstractmethod
|
|
362
|
+
def merge(self, items: Union[List[Any], 'ICollection']) -> 'ICollection':
|
|
363
|
+
"""Merge the collection with the given items.
|
|
364
|
+
|
|
365
|
+
Parameters
|
|
366
|
+
----------
|
|
367
|
+
items : list or Collection
|
|
368
|
+
The items to merge into the collection
|
|
369
|
+
|
|
370
|
+
Returns
|
|
371
|
+
-------
|
|
372
|
+
Collection
|
|
373
|
+
The current collection instance.
|
|
374
|
+
|
|
375
|
+
Raises
|
|
376
|
+
------
|
|
377
|
+
ValueError
|
|
378
|
+
If items cannot be merged due to incompatible types.
|
|
379
|
+
"""
|
|
380
|
+
pass
|
|
381
|
+
|
|
382
|
+
@abstractmethod
|
|
383
|
+
def pluck(self, value: str, key: Optional[str] = None) -> 'ICollection':
|
|
384
|
+
"""Get the values of a given key from all items.
|
|
385
|
+
|
|
386
|
+
Parameters
|
|
387
|
+
----------
|
|
388
|
+
value : str
|
|
389
|
+
The key to pluck from each item
|
|
390
|
+
key : str, optional
|
|
391
|
+
The key to use as the result key, by default None
|
|
392
|
+
|
|
393
|
+
Returns
|
|
394
|
+
-------
|
|
395
|
+
Collection
|
|
396
|
+
A new collection with the plucked values.
|
|
397
|
+
"""
|
|
398
|
+
pass
|
|
399
|
+
|
|
400
|
+
@abstractmethod
|
|
401
|
+
def pop(self) -> Any:
|
|
402
|
+
"""Remove and return the last item from the collection.
|
|
403
|
+
|
|
404
|
+
Returns
|
|
405
|
+
-------
|
|
406
|
+
mixed
|
|
407
|
+
The last item from the collection.
|
|
408
|
+
"""
|
|
409
|
+
pass
|
|
410
|
+
|
|
411
|
+
@abstractmethod
|
|
412
|
+
def prepend(self, value: Any) -> 'ICollection':
|
|
413
|
+
"""Add an item to the beginning of the collection.
|
|
414
|
+
|
|
415
|
+
Parameters
|
|
416
|
+
----------
|
|
417
|
+
value : mixed
|
|
418
|
+
The value to prepend
|
|
419
|
+
|
|
420
|
+
Returns
|
|
421
|
+
-------
|
|
422
|
+
Collection
|
|
423
|
+
The current collection instance.
|
|
424
|
+
"""
|
|
425
|
+
pass
|
|
426
|
+
|
|
427
|
+
@abstractmethod
|
|
428
|
+
def pull(self, key: Any) -> Any:
|
|
429
|
+
"""Remove an item from the collection and return it.
|
|
430
|
+
|
|
431
|
+
Parameters
|
|
432
|
+
----------
|
|
433
|
+
key : mixed
|
|
434
|
+
The key of the item to remove
|
|
435
|
+
|
|
436
|
+
Returns
|
|
437
|
+
-------
|
|
438
|
+
mixed
|
|
439
|
+
The removed item.
|
|
440
|
+
"""
|
|
441
|
+
pass
|
|
442
|
+
|
|
443
|
+
@abstractmethod
|
|
444
|
+
def push(self, value: Any) -> 'ICollection':
|
|
445
|
+
"""Add an item to the end of the collection.
|
|
446
|
+
|
|
447
|
+
Parameters
|
|
448
|
+
----------
|
|
449
|
+
value : mixed
|
|
450
|
+
The value to add
|
|
451
|
+
|
|
452
|
+
Returns
|
|
453
|
+
-------
|
|
454
|
+
Collection
|
|
455
|
+
The current collection instance.
|
|
456
|
+
"""
|
|
457
|
+
pass
|
|
458
|
+
|
|
459
|
+
@abstractmethod
|
|
460
|
+
def put(self, key: Any, value: Any) -> 'ICollection':
|
|
461
|
+
"""Put an item in the collection by key.
|
|
462
|
+
|
|
463
|
+
Parameters
|
|
464
|
+
----------
|
|
465
|
+
key : mixed
|
|
466
|
+
The key to set
|
|
467
|
+
value : mixed
|
|
468
|
+
The value to set
|
|
469
|
+
|
|
470
|
+
Returns
|
|
471
|
+
-------
|
|
472
|
+
Collection
|
|
473
|
+
The current collection instance.
|
|
474
|
+
"""
|
|
475
|
+
pass
|
|
476
|
+
|
|
477
|
+
@abstractmethod
|
|
478
|
+
def random(self, count: Optional[int] = None) -> Union[Any, 'ICollection', None]:
|
|
479
|
+
"""Get one or more random items from the collection.
|
|
480
|
+
|
|
481
|
+
Parameters
|
|
482
|
+
----------
|
|
483
|
+
count : int, optional
|
|
484
|
+
The number of items to return, by default None
|
|
485
|
+
|
|
486
|
+
Returns
|
|
487
|
+
-------
|
|
488
|
+
mixed or Collection
|
|
489
|
+
A single random item if count is None, otherwise a Collection.
|
|
490
|
+
|
|
491
|
+
Raises
|
|
492
|
+
------
|
|
493
|
+
ValueError
|
|
494
|
+
If count is greater than collection length.
|
|
495
|
+
"""
|
|
496
|
+
pass
|
|
497
|
+
|
|
498
|
+
@abstractmethod
|
|
499
|
+
def reduce(self, callback: Callable, initial: Any = 0) -> Any:
|
|
500
|
+
"""Reduce the collection to a single value.
|
|
501
|
+
|
|
502
|
+
Parameters
|
|
503
|
+
----------
|
|
504
|
+
callback : callable
|
|
505
|
+
The callback function for reduction
|
|
506
|
+
initial : mixed, optional
|
|
507
|
+
The initial value, by default 0
|
|
508
|
+
|
|
509
|
+
Returns
|
|
510
|
+
-------
|
|
511
|
+
mixed
|
|
512
|
+
The reduced value.
|
|
513
|
+
"""
|
|
514
|
+
pass
|
|
515
|
+
|
|
516
|
+
@abstractmethod
|
|
517
|
+
def reject(self, callback: Callable) -> 'ICollection':
|
|
518
|
+
"""Filter items that do not pass a given truth test.
|
|
519
|
+
|
|
520
|
+
Parameters
|
|
521
|
+
----------
|
|
522
|
+
callback : callable
|
|
523
|
+
The callback function to test items
|
|
524
|
+
|
|
525
|
+
Returns
|
|
526
|
+
-------
|
|
527
|
+
Collection
|
|
528
|
+
The current collection instance.
|
|
529
|
+
"""
|
|
530
|
+
pass
|
|
531
|
+
|
|
532
|
+
@abstractmethod
|
|
533
|
+
def reverse(self) -> 'ICollection':
|
|
534
|
+
"""Reverse items order in the collection.
|
|
535
|
+
|
|
536
|
+
Returns
|
|
537
|
+
-------
|
|
538
|
+
Collection
|
|
539
|
+
The current collection instance.
|
|
540
|
+
"""
|
|
541
|
+
pass
|
|
542
|
+
|
|
543
|
+
@abstractmethod
|
|
544
|
+
def serialize(self) -> List[Any]:
|
|
545
|
+
"""Get the collection items as a serialized array.
|
|
546
|
+
|
|
547
|
+
Returns
|
|
548
|
+
-------
|
|
549
|
+
list
|
|
550
|
+
The serialized items.
|
|
551
|
+
"""
|
|
552
|
+
pass
|
|
553
|
+
|
|
554
|
+
@abstractmethod
|
|
555
|
+
def addRelation(self, result: Optional[Dict[str, Any]] = None) -> 'ICollection':
|
|
556
|
+
"""Add relation data to all models in the collection.
|
|
557
|
+
|
|
558
|
+
Parameters
|
|
559
|
+
----------
|
|
560
|
+
result : dict, optional
|
|
561
|
+
The relation data to add, by default None
|
|
562
|
+
|
|
563
|
+
Returns
|
|
564
|
+
-------
|
|
565
|
+
Collection
|
|
566
|
+
The current collection instance.
|
|
567
|
+
"""
|
|
568
|
+
pass
|
|
569
|
+
|
|
570
|
+
@abstractmethod
|
|
571
|
+
def shift(self) -> Any:
|
|
572
|
+
"""Remove and return the first item from the collection.
|
|
573
|
+
|
|
574
|
+
Returns
|
|
575
|
+
-------
|
|
576
|
+
mixed
|
|
577
|
+
The first item from the collection.
|
|
578
|
+
"""
|
|
579
|
+
pass
|
|
580
|
+
|
|
581
|
+
@abstractmethod
|
|
582
|
+
def sort(self, key: Optional[str] = None) -> 'ICollection':
|
|
583
|
+
"""Sort through each item with a callback.
|
|
584
|
+
|
|
585
|
+
Parameters
|
|
586
|
+
----------
|
|
587
|
+
key : str, optional
|
|
588
|
+
The key to sort by, by default None
|
|
589
|
+
|
|
590
|
+
Returns
|
|
591
|
+
-------
|
|
592
|
+
Collection
|
|
593
|
+
The current collection instance.
|
|
594
|
+
"""
|
|
595
|
+
pass
|
|
596
|
+
|
|
597
|
+
@abstractmethod
|
|
598
|
+
def sum(self, key: Optional[str] = None) -> float:
|
|
599
|
+
"""Get the sum of the given values.
|
|
600
|
+
|
|
601
|
+
Parameters
|
|
602
|
+
----------
|
|
603
|
+
key : str, optional
|
|
604
|
+
The key to sum by, by default None
|
|
605
|
+
|
|
606
|
+
Returns
|
|
607
|
+
-------
|
|
608
|
+
float
|
|
609
|
+
The sum of the values.
|
|
610
|
+
"""
|
|
611
|
+
pass
|
|
612
|
+
|
|
613
|
+
@abstractmethod
|
|
614
|
+
def toJson(self, **kwargs: Any) -> str:
|
|
615
|
+
"""Get the collection items as JSON.
|
|
616
|
+
|
|
617
|
+
Parameters
|
|
618
|
+
----------
|
|
619
|
+
**kwargs : dict
|
|
620
|
+
Additional arguments to pass to json.dumps
|
|
621
|
+
|
|
622
|
+
Returns
|
|
623
|
+
-------
|
|
624
|
+
str
|
|
625
|
+
The JSON representation of the collection.
|
|
626
|
+
"""
|
|
627
|
+
pass
|
|
628
|
+
|
|
629
|
+
@abstractmethod
|
|
630
|
+
def groupBy(self, key: str) -> 'ICollection':
|
|
631
|
+
"""Group the collection items by a given key.
|
|
632
|
+
|
|
633
|
+
Parameters
|
|
634
|
+
----------
|
|
635
|
+
key : str
|
|
636
|
+
The key to group by
|
|
637
|
+
|
|
638
|
+
Returns
|
|
639
|
+
-------
|
|
640
|
+
Collection
|
|
641
|
+
A new collection with grouped items.
|
|
642
|
+
"""
|
|
643
|
+
pass
|
|
644
|
+
|
|
645
|
+
@abstractmethod
|
|
646
|
+
def transform(self, callback: Callable) -> 'ICollection':
|
|
647
|
+
"""Transform each item in the collection using a callback.
|
|
648
|
+
|
|
649
|
+
Parameters
|
|
650
|
+
----------
|
|
651
|
+
callback : callable
|
|
652
|
+
The callback function to transform items
|
|
653
|
+
|
|
654
|
+
Returns
|
|
655
|
+
-------
|
|
656
|
+
Collection
|
|
657
|
+
The current collection instance.
|
|
658
|
+
"""
|
|
659
|
+
pass
|
|
660
|
+
|
|
661
|
+
@abstractmethod
|
|
662
|
+
def unique(self, key: Optional[str] = None) -> 'ICollection':
|
|
663
|
+
"""Return only unique items from the collection array.
|
|
664
|
+
|
|
665
|
+
Parameters
|
|
666
|
+
----------
|
|
667
|
+
key : str, optional
|
|
668
|
+
The key to use for uniqueness comparison, by default None
|
|
669
|
+
|
|
670
|
+
Returns
|
|
671
|
+
-------
|
|
672
|
+
Collection
|
|
673
|
+
A new collection with unique items.
|
|
674
|
+
"""
|
|
675
|
+
pass
|
|
676
|
+
|
|
677
|
+
@abstractmethod
|
|
678
|
+
def where(self, key: str, *args: Any) -> 'ICollection':
|
|
679
|
+
"""Filter items by a given key value pair.
|
|
680
|
+
|
|
681
|
+
Parameters
|
|
682
|
+
----------
|
|
683
|
+
key : str
|
|
684
|
+
The key to filter by
|
|
685
|
+
*args : mixed
|
|
686
|
+
The operator and value, or just the value
|
|
687
|
+
|
|
688
|
+
Returns
|
|
689
|
+
-------
|
|
690
|
+
Collection
|
|
691
|
+
A new collection with filtered items.
|
|
692
|
+
"""
|
|
693
|
+
pass
|
|
694
|
+
|
|
695
|
+
@abstractmethod
|
|
696
|
+
def whereIn(self, key: str, values: Union[List[Any], 'ICollection']) -> 'ICollection':
|
|
697
|
+
"""Filter items where a given key's value is in a list of values.
|
|
698
|
+
|
|
699
|
+
Parameters
|
|
700
|
+
----------
|
|
701
|
+
key : str
|
|
702
|
+
The key to filter by
|
|
703
|
+
values : list or Collection
|
|
704
|
+
The list of values to check against
|
|
705
|
+
|
|
706
|
+
Returns
|
|
707
|
+
-------
|
|
708
|
+
Collection
|
|
709
|
+
A new collection with filtered items.
|
|
710
|
+
"""
|
|
711
|
+
pass
|
|
712
|
+
|
|
713
|
+
@abstractmethod
|
|
714
|
+
def whereNotIn(self, key: str, values: Union[List[Any], 'ICollection']) -> 'ICollection':
|
|
715
|
+
"""Filter items where a given key's value is not in a list of values.
|
|
716
|
+
|
|
717
|
+
Parameters
|
|
718
|
+
----------
|
|
719
|
+
key : str
|
|
720
|
+
The key to filter by
|
|
721
|
+
values : list or Collection
|
|
722
|
+
The list of values to check against
|
|
723
|
+
|
|
724
|
+
Returns
|
|
725
|
+
-------
|
|
726
|
+
Collection
|
|
727
|
+
A new collection with filtered items.
|
|
728
|
+
"""
|
|
729
|
+
pass
|
|
730
|
+
|
|
731
|
+
@abstractmethod
|
|
732
|
+
def zip(self, items: Union[List[Any], 'ICollection']) -> 'ICollection':
|
|
733
|
+
"""Merge the collection with the given items by index.
|
|
734
|
+
|
|
735
|
+
Parameters
|
|
736
|
+
----------
|
|
737
|
+
items : list or Collection
|
|
738
|
+
The items to zip with
|
|
739
|
+
|
|
740
|
+
Returns
|
|
741
|
+
-------
|
|
742
|
+
Collection
|
|
743
|
+
A new collection with zipped items.
|
|
744
|
+
|
|
745
|
+
Raises
|
|
746
|
+
------
|
|
747
|
+
ValueError
|
|
748
|
+
If items parameter is not a list or Collection.
|
|
749
|
+
"""
|
|
750
|
+
pass
|
|
751
|
+
|
|
752
|
+
@abstractmethod
|
|
753
|
+
def setAppends(self, appends: List[str]) -> 'ICollection':
|
|
754
|
+
"""Set the attributes that should be appended to the Collection.
|
|
755
|
+
|
|
756
|
+
Parameters
|
|
757
|
+
----------
|
|
758
|
+
appends : list
|
|
759
|
+
The attributes to append
|
|
760
|
+
|
|
761
|
+
Returns
|
|
762
|
+
-------
|
|
763
|
+
Collection
|
|
764
|
+
The current collection instance.
|
|
765
|
+
"""
|
|
766
|
+
pass
|