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
Copy file name to clipboardExpand all lines: README.md
+20-2Lines changed: 20 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,11 +19,11 @@ You can use `maz` to compose function calls such that they call one another in a
19
19
```
20
20
21
21
##### Partial function
22
-
When you want to fix a parameter in a function, you could just use the `functools.partial`. However, that doesn't support fixing a positional argument on a specific index, which are quite common later on when you want to build complex compositions. Here you can use the `maz.pospartial` instead
22
+
When you want to fix a parameter in a function, you could just use the `functools.partial`. However, that doesn't support fixing a positional argument on a specific index, which are quite common later on when you want to build complex compositions. Here you can use the `maz.partialpos` instead
23
23
```python
24
24
>>>import maz
25
25
>>>defadd(x,y): return x+y
26
-
>>> add_two = maz.pospartial(add, [(1,2)])#meaning fix argument on index 1 with the value 2
26
+
>>> add_two = maz.partialpos(add, {1:2})#fixing argument for index 1 to 2 (y=2)
27
27
>>> add_two(3)
28
28
>>>5
29
29
```
@@ -33,6 +33,7 @@ To support more complex compositions we've added some special functions such as
33
33
```python
34
34
import maz
35
35
import operator
36
+
import itertools
36
37
37
38
# "indexing" function - since only way to index a list in python is to do lst[x]
38
39
lst = [2,1,3]
@@ -63,4 +64,21 @@ fn = maz.ifttt(
63
64
fn(3) # >>> 4
64
65
fn(4) # >>> 3
65
66
67
+
# "starfilter" just as itertools.starmap but a filter instead
68
+
# Example, filter tuples who's sum is greater than 4
69
+
next(
70
+
maz.starfilter(
71
+
maz.compose(
72
+
lambdai: i >4,
73
+
add
74
+
),
75
+
itertools.product(range(3), range(3,6))
76
+
)
77
+
) # >>> (0,5)
78
+
79
+
# "constant" returns a function which, no matter the argument, returns a constant value.
0 commit comments