Skip to content

Commit

Permalink
make each eager
Browse files Browse the repository at this point in the history
  • Loading branch information
czheo committed May 23, 2021
1 parent 82e09cb commit 26f87da
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pipe(10) | range | (map, lambda x: x**2) | list | print | END

from syntax_sugar import each
x = pipe(10) | range | each(lambda x: x ** 2) | END
# `each` is just a shortcut of the partial function of `map`
# We can also save the result in a variable
# We can also save the result in a variable.
# `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)

pipe(10) | range | each(str) | ''.join > 'test.txt'
# wanna write to a file? Why not!
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="syntax_sugar",
version="0.3.6",
version="0.3.7",
url='https://github.com/czheo/syntax_sugar_python',
description="add syntactic sugar to Python",
author="czheo",
Expand Down
2 changes: 1 addition & 1 deletion syntax_sugar/_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def puts(data, end="\n"):
return data

def each(fn):
return partial(map, fn)
return compose(list, partial(map, fn))

class End:
"mark end of pipe"
Expand Down
Empty file added tests/__init__.py
Empty file.
6 changes: 3 additions & 3 deletions tests/test_infix.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ def test_drop():
_assert_iter(10 /to/ 1 /drop/ 3 /take/ 2, [7, 6])

def test_iter_pipe():
assert 0 /to/ 9 | each(lambda x: x**2) | list | END == [x**2 for x in range(10)]
assert 0 /to/ 9 /take/ 2 | each(lambda x: x**2) | list | END == [x**2 for x in range(10)][:2]
assert 0 /to/ 9 /drop/ 2 | each(lambda x: x**2) | list| END == [x**2 for x in range(10)][2:]
assert 0 /to/ 9 | each(lambda x: x**2) | END == [x**2 for x in range(10)]
assert 0 /to/ 9 /take/ 2 | each(lambda x: x**2) | END == [x**2 for x in range(10)][:2]
assert 0 /to/ 9 /drop/ 2 | each(lambda x: x**2) | END == [x**2 for x in range(10)][2:]

def test_is_a():
values_types_right = [
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_pipe_with_list():
assert pipe([1,2,3,4]) | END == [1,2,3,4]

def test_each():
assert pipe(range(10)) | each(lambda x: x**2) | list | END \
assert pipe(range(10)) | each(lambda x: x**2) | END \
== [x**2 for x in range(10)]

def test_puts():
Expand Down

0 comments on commit 26f87da

Please sign in to comment.