Skip to content

Commit 03a8496

Browse files
author
czheo
committed
2 parents e44fb66 + fe71d74 commit 03a8496

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

README.md

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# syntax_sugar ![travis_status](https://travis-ci.org/czheo/syntax_sugar_python.svg?branch=master)
1+
# syntax_sugar [![travis_status](https://travis-ci.org/czheo/syntax_sugar_python.svg?branch=master)](https://travis-ci.org/czheo/syntax_sugar_python)
22

33
This lib adds some syntactic sugar to Python.
44

5-
NOTE: This is merely a prototype. Only tested under Python 3.6.0. Everything is evolving.
5+
NOTE: This is merely an experimental prototype to show some potential of operator overloading in Python. Only tested under Python 3.6.0. Anything may evolve without announcement in advance.
66

77
Inspired by https://github.com/matz/streem.
88

@@ -55,11 +55,11 @@ Here is an example of requesting a list of urls in parrallel
5555
``` python
5656
import requests
5757
(
58-
(pipe(['google', 'twitter', 'yahoo', 'facebook', 'github'])
58+
pipe(['google', 'twitter', 'yahoo', 'facebook', 'github'])
5959
| each(lambda name: 'http://' + name + '.com')
6060
| [requests.get] * 3 # !! `requests.get` runs in a ThreadPool of size 3
6161
| each(lambda resp: (resp.url, resp.headers.get('Server')))
62-
| dump())
62+
| dump()
6363
)
6464

6565
# returns
@@ -75,9 +75,6 @@ import requests
7575
1 /of/ int
7676
# equivalent to `isinstance(1, int)`
7777

78-
[1,2,3,4,5] /contains/ 3
79-
# equivalent to `3 in [1,2,3,4,5]`
80-
8178
1 /to/ 10
8279
# equivalent to `range(1, 11)`
8380
# Python's nasty range() is right-exclusive. This is right-inclusive.
@@ -88,11 +85,12 @@ import requests
8885

8986
# make your own infix functions
9087
@infix
91-
def plus(a, b):
92-
return a + b
88+
def push(lst, x):
89+
lst.append(x)
90+
return lst
9391

94-
1 /plus/ 2
95-
# returns 3
92+
[] /push/ 1 /push/ 2 /push/ 3
93+
# returns [1,2,3]
9694
```
9795

9896
### composable function
@@ -106,13 +104,8 @@ lmap = compose(list, map)
106104
lmap(lambda x: x ** 2, range(10))
107105
```
108106

109-
Let's try some math.
110-
```
111-
f(x) = x^2 + 1
112-
g(x) = 2x - 1
113-
h(x) = -2x^3 + 3
114-
```
115-
We want to represent `f * g * h` in a program, i.e. `fn(x) = f(g(h(x)))`
107+
Let's say we want to represent `f * g * h` in a program, i.e. `fn(x) = f(g(h(x)))`
108+
116109
``` python
117110
f = lambda x: x**2 + 1
118111
g = lambda x: 2*x - 1

0 commit comments

Comments
 (0)