QList
Bases: list
QList is a python list extension that adds several chainable, lazy
evaluated methods to the standard list.
Found in qwlist.QList
Source code in src\qwlist\qwlist.py
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 | |
cycle()
Returns a Lazy[T] that cycles through the elements of the QList that means on achieving the last element the iteration starts from the beginning. The returned lazy object has no end (infinite iterator) unless the QList is empty in which case cycle returns an empty Lazy object.
Returns: Lazy[T]
Examples:
>>> QList([1, 2, 3]).cycle().take(7).collect()
[1, 2, 3, 1, 2, 3, 1]
Source code in src\qwlist\qwlist.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | |
eager()
Changes QList into EagerQList.
Returns: EagerQList[T]
Source code in src\qwlist\qwlist.py
294 295 296 297 298 299 300 301 | |
filter(pred)
Returns a Lazy object containing all values from the QList for which
the predicate holds true.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pred |
Callable[[T], bool]
|
|
required |
Returns: Lazy[T]
Examples:
>>> QList([1, 2, 3, 4]).filter(lambda x: x < 3).collect()
[1, 2]
Source code in src\qwlist\qwlist.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
flatmap(mapper)
Applies the mapper function to each element of the QList and flattens the results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapper |
Callable[[T], Iterable[K]]
|
|
required |
Returns: Lazy[K]
Examples:
>>> QList([1, 2]).flatmap(lambda x: [x, x]).qlist()
[1, 1, 2, 2]
Source code in src\qwlist\qwlist.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
flatten()
If self is a QList of Iterable[T] flatten concatenates all iterables into a single list and returns a Lazy[T] object Returns: Lazy[T]
Source code in src\qwlist\qwlist.py
493 494 495 496 497 498 499 500 501 502 | |
fold(operation, init)
Given the combination operator reduces the QList by processing
its values, building up the final value.
Other names: fold_left, reduce, accumulate, aggregate
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operation |
Callable[[K, T], K]
|
|
required |
init |
K
|
initial value for the combination operator. |
required |
Returns: K
Examples:
>>> QList([1, 2, 3]).fold(lambda acc, x: acc + x, 0)
6
Source code in src\qwlist\qwlist.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
fold_right(operation, init)
Given the combination operator reduces the QList by processing
its values, building up the final value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operation |
Callable[[K, T], K]
|
|
required |
init |
K
|
initial value for the combination operator. |
required |
Returns: K
Examples:
>>> QList([1, 2, 3]).fold_right(lambda acc, x: acc + x, 0)
6
Source code in src\qwlist\qwlist.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | |
foreach(action)
Applies the given function to each of the QList elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action |
Callable[[T], None]
|
|
required |
Returns: None
Source code in src\qwlist\qwlist.py
338 339 340 341 342 343 344 345 346 347 348 | |
len()
Returns the len of the QList
(time complexity: O(1))
Returns: int
Source code in src\qwlist\qwlist.py
398 399 400 401 402 403 404 405 406 | |
list()
Changes QList into list.
Returns: list[T]
Source code in src\qwlist\qwlist.py
286 287 288 289 290 291 292 | |
map(mapper)
Returns a Lazy object containing all values from QList with
the mapping function applied on them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapper |
Callable[[T], K]
|
|
required |
Returns: Lazy[K]
Source code in src\qwlist\qwlist.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
skip(n)
Skips n first elements of the QList.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n |
int
|
numbers of elements to skip. Should be non-negative |
required |
Returns: Lazy[T]
Example
QList(range(10)).skip(2).collect() [2, 3, 4, 5, 6, 7, 8, 9]
Source code in src\qwlist\qwlist.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | |
slice(s)
Calling this method with s equal to slice(3) works similarly to
list[:3] but is lazy evaluated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s |
slice
|
slice object |
required |
Returns: Lazy[T]
Source code in src\qwlist\qwlist.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
sorted(key=None, reverse=False)
Returns a new QList containing all items from the original list in ascending order.
A custom key function can be supplied to customize the sort order, and the reverse flag can be set to request the result in descending order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key |
Callable[[T], SupportsLessThan]
|
|
None
|
reverse |
bool
|
if set to |
False
|
Returns: QList[T]
Source code in src\qwlist\qwlist.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
take(n)
Takes n first elements of the QList.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n |
int
|
int - numbers of elements to take. Should be non-negative |
required |
Returns: Lazy[T]
Examples:
>>> QList(range(10)).take(2).collect()
[0, 1]
Source code in src\qwlist\qwlist.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | |
zip(other)
Combines this QList with the given Iterable elementwise as tuples.
The returned Lazy objects yields at most the number of elements of
the shorter sequence (self or Iterable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other |
Iterable[K]
|
iterable to zip with this |
required |
Returns: Lazy[tuple[T, K]]
Source code in src\qwlist\qwlist.py
426 427 428 429 430 431 432 433 434 435 436 437 | |