Skip to content

Commit d2fc434

Browse files
author
czheo
committed
2 parents 70b458c + a4144f8 commit d2fc434

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,36 @@ pipe(['google', 'twitter', 'yahoo', 'facebook', 'github'])
7676
# equivalent to `isinstance(1, int)`
7777

7878
1 /to/ 10
79-
# equivalent to `range(1, 11)`
79+
# similar to `range(1, 11)`, but this is an iterator.
8080
# Python's nasty range() is right-exclusive. This is right-inclusive.
8181

8282
'0' /to/ '9'
83+
# similar to '0123456789', but this is an iterator.
8384
# we can also have a range of characters :)
84-
# '0123456789'
85+
```
86+
87+
`/to/` has some advanced features
88+
89+
- lazy evaluation.
90+
- support infinity.
91+
- support product operation.
92+
93+
``` python
94+
# CAUTION: this will infinitely print numbers
95+
for i in 1 /to/ INF:
96+
print(i)
8597

86-
# make your own infix functions
98+
print(1 /to/ INF /take/ 5)
99+
# there is a `take` funciton which is similar to itertools.islice
100+
# return [1, 2, 3, 4, 5]
101+
102+
# print all combinations of [1..3] * [4..6]
103+
print([(x, y) for x, y in (1 /to/ 3) * (4 /to/ 6)])
104+
# return [(1, 4), (1, 5), (1, 6), (2, 4), (2, 5), (2, 6), (3, 4), (3, 5), (3, 6)]
105+
```
106+
107+
Make your own infix function, so you can append multiple items to a list in one line.
108+
``` python
87109
@infix
88110
def push(lst, x):
89111
lst.append(x)

0 commit comments

Comments
 (0)