Foldable
Foldable
Bases: Protocol
A foldable can be reduced to a value.
Source code in funclift/foldable.py
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 |
|
fold_left(f)
Reduces a foldable in a left-associative manner.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
A foldable structure that contains values of type A. |
required | |
f |
Callable[[B, A], B]
|
A function to be used while folding the |
required |
Returns:
Name | Type | Description |
---|---|---|
B |
B
|
The value the structure reduces to. |
Source code in funclift/foldable.py
32 33 34 35 36 37 38 39 40 41 42 43 |
|
fold_map(f)
summary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
Callable[[A], M]
|
description |
required |
Returns:
Name | Type | Description |
---|---|---|
M |
M
|
description |
Source code in funclift/foldable.py
45 46 47 48 49 50 51 52 53 54 |
|
fold_right(f)
Reduces a foldable in a right-associative manner.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
self |
A foldable structure that contains values of type A. |
required | |
f |
Callable[[A, B], B]
|
A function to be used while folding the |
required |
Returns:
Name | Type | Description |
---|---|---|
B |
B
|
The value the structure reduces to. |
Source code in funclift/foldable.py
19 20 21 22 23 24 25 26 27 28 29 30 |
|
ListFoldable
Implements Foldable for lists.
Source code in funclift/foldable.py
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 |
|