Skip to content

Commit ab8fd84

Browse files
authored
Merge pull request #491 from zzhengnan/update-docs
Update official docs
2 parents d69968e + 25b69df commit ab8fd84

File tree

6 files changed

+29
-28
lines changed

6 files changed

+29
-28
lines changed

doc/source/control.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,27 @@ Programming is hard when we have to juggle many code elements of each type at
3838
the same time. Good programming is about managing these three elements so that
3939
the developer is only required to think about a handful of them at a time. For
4040
example we might collect many integer variables into a list of integers or
41-
build a big function out of smaller ones. While we have natural ways to manage
42-
data and functions, control flow presents more of a challenge.
41+
build a big function out of smaller ones.
4342

4443
We organize our data into **data structures** like lists, dictionaries, or objects
4544
in order to group related data together -- this allows us to manipulate large
4645
collections of related data as if we were only manipulating a single entity.
4746

48-
We **build large functions out of smaller ones**; enabling us to break up a
47+
We **build large functions out of smaller ones**, enabling us to break up a
4948
complex task like doing laundry into a sequence of simpler tasks.
5049

5150
.. code::
5251
5352
def do_laundry(clothes):
54-
wet_clothes = wash(clothes, coins)
55-
dry_clothes = dry(wet_clothes, coins)
53+
wet_clothes = wash(clothes)
54+
dry_clothes = dry(wet_clothes)
5655
return fold(dry_clothes)
5756
58-
**Control flow is more challenging**; how do we break down complex control flow
59-
into simpler pieces that fit in our brain? How do we encapsulate commonly
60-
recurring patterns?
57+
While we have natural ways to manage data and functions, **control flow presents more of a challenge**.
58+
How do we break down complex control flow into simpler pieces that fit in our brain?
59+
How do we encapsulate commonly recurring patterns?
6160

62-
Lets motivate this with an example of a common control structure, applying a
61+
Let's motivate this with an example of a common control structure, applying a
6362
function to each element in a list. Imagine we want to download the HTML
6463
source for a number of webpages.
6564

@@ -71,7 +70,6 @@ source for a number of webpages.
7170
html_texts = []
7271
for item in urls:
7372
html_texts.append(urlopen(item))
74-
return html_texts
7573
7674
Or maybe we want to compute the Fibonacci numbers on a particular set of
7775
integers
@@ -82,7 +80,6 @@ integers
8280
fib_integers = []
8381
for item in integers:
8482
fib_integers.append(fib(item))
85-
return fib_integers
8683
8784
These two unrelated applications share an identical control flow pattern. They
8885
apply a function (``urlopen`` or ``fib``) onto each element of an input list
@@ -156,8 +153,8 @@ Most programmers however don't know about the many cousins of
156153
>>> groupby(len, names)
157154
{3: ['Bob', 'Dan'], 5: ['Alice', 'Edith', 'Frank'], 7: ['Charlie']}
158155
159-
Groupby collects each element of a list into sublists determined by the value
160-
of a function. Lets see ``groupby`` in action again, grouping numbers by
156+
``groupby`` collects each element of a list into sublists determined by the value
157+
of a function. Let's see ``groupby`` in action again, grouping numbers by
161158
evenness.
162159

163160
.. code::
@@ -186,6 +183,9 @@ like they may have repeated the ``map`` control pattern. When we identify code
186183
as a ``groupby`` operation we mentally collapse the detailed manipulation into
187184
a single concept.
188185

186+
Additional Considerations
187+
^^^^^^^^^^^^^^^^^^^^^^^^^
188+
189189
The Toolz library contains dozens of patterns like ``map`` and ``groupby``.
190190
Learning a core set (maybe a dozen) covers the vast majority of common
191191
programming tasks often done by hand.

doc/source/curry.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ higher order function from ``functools``. Currying provides syntactic sugar.
88
.. code::
99
1010
>>> double = partial(mul, 2) # Partial evaluation
11-
>>> doubled = double(2) # Currying
11+
>>> doubled = double(5) # Currying
1212
1313
This syntactic sugar is valuable when developers chain several higher order
1414
functions together.
@@ -54,7 +54,7 @@ In general
5454
>>> def g(z):
5555
... return f(a, b, z)
5656
57-
>>> # partially evaluate f with known values a and b
57+
>>> # alternatively we could use `partial`
5858
>>> g = partial(f, a, b)
5959
6060
Curry
@@ -74,7 +74,7 @@ compute a result.
7474
7575
>>> double = mul(2) # mul didn't receive enough arguments to evaluate
7676
... # so it holds onto the 2 and waits, returning a
77-
... # partially evaluated function, double
77+
... # partially evaluated function `double`
7878
7979
>>> double(5)
8080
10

doc/source/laziness.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Computation
3636
-----------
3737

3838
We can lazily operate on lazy iterators without doing any actual computation.
39-
For example lets read the book in upper case
39+
For example let's read the book in upper case
4040

4141
.. code::
4242

doc/source/parallelism.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ multiprocessing, to distributed computation all with the same domain code.
7474
This smooth transition is possible because
7575

7676
1. The ``map`` abstraction is a simple function call and so can be replaced.
77-
This transformation would be difficult if we had written our code with a
78-
for loop or list comprehension
77+
By contrast, this transformation would be difficult if we had written our code with a
78+
for loop or list comprehension.
7979
2. The operation ``wordcount`` is separate from the parallel solution.
8080
3. The task is embarrassingly parallel, needing only a very simple parallel
8181
strategy. Fortunately this is the common case.
@@ -90,5 +90,5 @@ general solution is to build algorithms that operate around a user-supplied
9090
parallel map function.
9191

9292
In particular we provide a parallel ``fold`` in ``toolz.sandbox.parallel.fold``.
93-
This fold can work equally well with ``multiprocessing.Pool.map``
94-
``threading.Pool.map`` or ``ipyparallel``'s ``map_async``.
93+
This fold can work equally well with ``multiprocessing.Pool.map``,
94+
``threading.Pool.map``, or ``ipyparallel``'s ``map_async``.

doc/source/streaming-analytics.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ These functions correspond to the SQL commands ``SELECT`` and ``WHERE``.
3838
... map(get([1, 2])),
3939
... list)
4040
41-
Note: this uses the `curried`_ versions of ``map`` and ``filter``.
41+
Note: this uses the `curried`` versions of ``map`` and ``filter``.
4242

4343
Of course, these operations are also well supported with standard
4444
list/generator comprehension syntax. This syntax is more often used and
@@ -89,7 +89,7 @@ groups.
8989
'M': [(2, 'Bob', 200, 'M'), (3, 'Charlie', 150, 'M'), (4, 'Dennis', 50, 'M')]}
9090
9191
>>> valmap(compose(sum, pluck(2)),
92-
... _)
92+
... _) # The underscore captures results from the previous prompt
9393
{'F': 400, 'M': 400}
9494
9595
@@ -116,8 +116,8 @@ understand this section you should first be familiar with the builtin function
116116

117117
The ``reduceby`` operation takes a key function, like ``get(3)`` or ``lambda x:
118118
x[3]``, and a binary operator like ``add`` or ``lesser = lambda acc, x: acc if
119-
acc < x else x``. It successively applies the key function to each item in
120-
succession, accumulating running totals for each key by combining each new
119+
acc < x else x``. It applies the key function to each item in succession,
120+
accumulating running totals for each key by combining each new
121121
value with the previous using the binary operator. It can't accept full
122122
reduction operations like ``sum`` or ``min`` as these require access to the
123123
entire group at once. Here is a simple example:
@@ -180,8 +180,9 @@ common first column, id.
180180
.. code::
181181
182182
SELECT accounts.name, addresses.address
183-
FROM accounts, addresses
184-
WHERE accounts.id = addresses.id;
183+
FROM accounts
184+
JOIN addresses
185+
ON accounts.id = addresses.id;
185186
186187
187188
.. code::

doc/source/tips-and-tricks.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Tips and Tricks
22
===============
33

44
Toolz functions can be combined to make functions that, while common, aren't
5-
a part of toolz's standard library. This section presents
5+
a part of toolz's standard offerings. This section presents
66
a few of these recipes.
77

88

0 commit comments

Comments
 (0)