Skip to content

Commit a2aaabc

Browse files
author
Zheyuan Chen
authored
Merge pull request #8 from terciodemelo/adds-after-range-op
Adds /drop/ syntax
2 parents 4a68353 + 87b35af commit a2aaabc

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,17 @@ for i in 1 /to/ INF:
110110
print(i)
111111

112112
print(1 /to/ INF /take/ 5)
113-
# there is a `take` funciton which is similar to itertools.islice
113+
# there is a `take` functon which is similar to itertools.islice
114114
# return [1, 2, 3, 4, 5]
115115

116116
print(0 /to/ NEGINF /by/ 2 /take/ 5)
117117
# also works with negative infinity.
118118
# return [0, -2, -4, -6, -8]
119119

120+
print(1 /to/ 10 /after/ 5)
121+
# there is a `after` functon which adds an offset to the range beginning
122+
# return [6, 7, 8, 9, 10]
123+
120124
# print all combinations of [1..3] * [4..6]
121125
print([(x, y) for x, y in (1 /to/ 3) * (4 /to/ 6)])
122126
# return [(1, 4), (1, 5), (1, 6), (2, 4), (2, 5), (2, 6), (3, 4), (3, 5), (3, 6)]

syntax_sugar/infix.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def __rtruediv__(self, left):
1919
ffilter = infix(flip(filter))
2020
freduce = infix(flip(reduce))
2121
take = infix(compose(list, islice))
22+
drop = infix(lambda seq, idx: islice(seq, idx, None))
2223

2324
INF = float('inf')
2425
NEGINF = float('-inf')
@@ -134,4 +135,5 @@ def by(to_object, step):
134135
'freduce',
135136
'ffilter',
136137
'take',
138+
'drop',
137139
]

tests/test_infix.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ def test_infinity():
8585
def test_take():
8686
assert 1 /to/ INF /take/ 5 == [1,2,3,4,5]
8787

88+
def test_drop():
89+
assert list(1 /to/ 10 /drop/ 2 /take/ 3) == [3, 4, 5]
90+
assert list(1 /to/ INF /drop/ 2 /take/ 3) == [3, 4, 5]
91+
assert list(10 /to/ 1 /drop/ 3 /take/ 2) == [7, 6]
92+
8893
def test_is_a():
8994
values_types_right = [
9095
(2, int),

0 commit comments

Comments
 (0)