Skip to content

Commit 26f87da

Browse files
author
czheo
committed
make each eager
1 parent 82e09cb commit 26f87da

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ pipe(10) | range | (map, lambda x: x**2) | list | print | END
4141

4242
from syntax_sugar import each
4343
x = pipe(10) | range | each(lambda x: x ** 2) | END
44-
# `each` is just a shortcut of the partial function of `map`
45-
# We can also save the result in a variable
44+
# We can also save the result in a variable.
45+
# `each` is an eager evaluated version of the partial function of `map`, which returns a list instead of a map object. (Equivalent to `map` in Python 2)
4646

4747
pipe(10) | range | each(str) | ''.join > 'test.txt'
4848
# wanna write to a file? Why not!

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="syntax_sugar",
5-
version="0.3.6",
5+
version="0.3.7",
66
url='https://github.com/czheo/syntax_sugar_python',
77
description="add syntactic sugar to Python",
88
author="czheo",

syntax_sugar/_pipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def puts(data, end="\n"):
2222
return data
2323

2424
def each(fn):
25-
return partial(map, fn)
25+
return compose(list, partial(map, fn))
2626

2727
class End:
2828
"mark end of pipe"

tests/__init__.py

Whitespace-only changes.

tests/test_infix.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ def test_drop():
8585
_assert_iter(10 /to/ 1 /drop/ 3 /take/ 2, [7, 6])
8686

8787
def test_iter_pipe():
88-
assert 0 /to/ 9 | each(lambda x: x**2) | list | END == [x**2 for x in range(10)]
89-
assert 0 /to/ 9 /take/ 2 | each(lambda x: x**2) | list | END == [x**2 for x in range(10)][:2]
90-
assert 0 /to/ 9 /drop/ 2 | each(lambda x: x**2) | list| END == [x**2 for x in range(10)][2:]
88+
assert 0 /to/ 9 | each(lambda x: x**2) | END == [x**2 for x in range(10)]
89+
assert 0 /to/ 9 /take/ 2 | each(lambda x: x**2) | END == [x**2 for x in range(10)][:2]
90+
assert 0 /to/ 9 /drop/ 2 | each(lambda x: x**2) | END == [x**2 for x in range(10)][2:]
9191

9292
def test_is_a():
9393
values_types_right = [

tests/test_pipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_pipe_with_list():
99
assert pipe([1,2,3,4]) | END == [1,2,3,4]
1010

1111
def test_each():
12-
assert pipe(range(10)) | each(lambda x: x**2) | list | END \
12+
assert pipe(range(10)) | each(lambda x: x**2) | END \
1313
== [x**2 for x in range(10)]
1414

1515
def test_puts():

0 commit comments

Comments
 (0)