Skip to content

Commit 7da6ef1

Browse files
committed
fix docstrings markup for docs
1 parent 52e04db commit 7da6ef1

File tree

4 files changed

+70
-65
lines changed

4 files changed

+70
-65
lines changed

fn/immutable/heap.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ class SkewHeap(_MergeBased):
4040
done in O(log n).
4141
4242
Skew heaps may be described with the following recursive definition:
43-
* a heap with only one element is a skew heap
44-
* the result of skew merging two skew heaps is also a skew heap
43+
* a heap with only one element is a skew heap
44+
* the result of skew merging two skew heaps is also a skew heap
4545
46-
In Haskell type definition it should looks like following:
47-
data Skew a = Empty | Node a (Skew a) (Skew a)
46+
In Haskell type definition it should looks like following::
47+
48+
data Skew a = Empty | Node a (Skew a) (Skew a)
4849
4950
More information on Wikipedia:
5051
[1] http://en.wikipedia.org/wiki/Skew_heap
@@ -91,7 +92,7 @@ def extract(self):
9192
* minimum (or maximum regarding to given compare function)
9293
* new skew heap without extracted element
9394
94-
Or None and empty heap if self is an empty heap.
95+
Or ``None`` and empty heap if ``self`` is an empty heap.
9596
"""
9697
if not self:
9798
return None, self._make_heap()
@@ -121,17 +122,17 @@ class PairingHeap(_MergeBased):
121122
property requires that all the root elements of the subheaps in the list
122123
are not smaller (bigger) than the root element of the heap.
123124
124-
In Haskell type definition it should looks like following:
125-
data Pairing a = Empty | Node a [Pairing a]
125+
In Haskell type definition it should looks like following::
126+
127+
data Pairing a = Empty | Node a [Pairing a]
126128
127129
Pairing heap has and excellent practical amortized performance. The
128130
amortized time per extract is less than O(log n), find-min/find-max, merge
129131
and insert are O(1).
130132
131133
More information about performance bounds you can find here:
132134
"The Pairing Heap: A New Form of Self-Adjusting Heap"
133-
[1]
134-
http://www.cs.cmu.edu/afs/cs.cmu.edu/user/sleator/www/papers/pairing-heaps.pdf
135+
[1] http://www.cs.cmu.edu/afs/cs.cmu.edu/user/sleator/www/papers/pairing-heaps.pdf
135136
136137
More general information on Wikipedia:
137138
[2] http://en.wikipedia.org/wiki/Pairing_heap
@@ -176,8 +177,8 @@ def insert(self, el):
176177

177178
def extract(self):
178179
"""Returns pair of values:
179-
* minimum (or maximum regarding to given compare function)
180-
* new pairing heap without extracted element
180+
* minimum (or maximum regarding to given compare function)
181+
* new pairing heap without extracted element
181182
182183
Or None and empty heap if self is an empty heap.
183184
"""

fn/monad.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
and get rid of many ``if/else`` blocks. See usage examples below.
66
77
Assume that you have ``Request`` class that gives you parameter
8-
value by its name. To get uppercase notation for non-empty striped value:
8+
value by its name. To get uppercase notation for non-empty striped value::
99
1010
class Request(dict):
1111
def parameter(self, name):
@@ -23,7 +23,7 @@ def parameter(self, name):
2323
fixed = param.upper()
2424
2525
26-
Hmm, looks ugly.. Update code with ``fn.monad.Option``:
26+
Hmm, looks ugly.. Update code with ``fn.monad.Option``::
2727
2828
from operator import methodcaller
2929
from fn.monad import optionable
@@ -43,7 +43,7 @@ def parameter(self, name):
4343
``fn.monad.Option.or_call`` is good method for trying several
4444
variant to end computation. I.e. use have ``Request`` class
4545
with optional attributes ``type``, ``mimetype``, ``url``.
46-
You need to evaluate "request type" using at least on attribute:
46+
You need to evaluate "request type" using at least on attribute::
4747
4848
from fn.monad import Option
4949

fn/op.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ def foldl(f, init=None):
5252
using passed function as reducer.
5353
5454
Usage:
55-
>>> print foldl(_ + _)([0,1,2,3,4])
56-
10
57-
>>> print foldl(_ * _, 1)([1,2,3])
58-
6
55+
>>> print foldl(_ + _)([0,1,2,3,4])
56+
10
57+
>>> print foldl(_ * _, 1)([1,2,3])
58+
6
5959
"""
60+
6061
def fold(it):
6162
args = [f, it]
6263
if init is not None:
@@ -72,9 +73,10 @@ def foldr(f, init=None):
7273
from iterator from right-to-left).
7374
7475
Usage:
75-
>>> print foldr(call, 10)([lambda s: s**2, lambda k: k+10])
76-
400
76+
>>> print foldr(call, 10)([lambda s: s**2, lambda k: k+10])
77+
400
7778
"""
79+
7880
def fold(it):
7981
args = [flip(f), reversed(it)]
8082
if init is not None:
@@ -88,15 +90,17 @@ def unfold(f):
8890
"""Return function to unfold value into stream using
8991
passed function as values producer. Passed function should
9092
accept current cursor and should return:
93+
9194
* tuple of two elements (value, cursor), value will be added
9295
to output, cursor will be used for next function call
9396
* None in order to stop producing sequence
9497
9598
Usage:
96-
>>> doubler = unfold(lambda x: (x*2, x*2))
97-
>>> list(islice(doubler(10), 0, 10))
98-
[20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240]
99+
>>> doubler = unfold(lambda x: (x*2, x*2))
100+
>>> list(islice(doubler(10), 0, 10))
101+
[20, 40, 80, 160, 320, 640, 1280, 2560, 5120, 10240]
99102
"""
103+
100104
def _unfolder(start):
101105
value, curr = None, start
102106
while 1:

fn/recur.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class tco(object):
1313
* (func, args) or (func, kwargs) - will repeat loop with new callable
1414
and new arguments
1515
16-
Usage example:
16+
Usage example::
1717
18-
@recur.tco
19-
def accumulate(origin, f=operator.add, acc=0):
20-
n = next(origin, None)
21-
if n is None: return False, acc
22-
return True, (origin, f, f(acc, n))
18+
@recur.tco
19+
def accumulate(origin, f=operator.add, acc=0):
20+
n = next(origin, None)
21+
if n is None: return False, acc
22+
return True, (origin, f, f(acc, n))
2323
2424
Idea was described on python mailing list:
2525
http://mail.python.org/pipermail/python-ideas/2009-May/004486.html
@@ -57,42 +57,42 @@ class stackless(object):
5757
5858
Usage examples:
5959
60-
Tail call optimised recursion with tailcall():
61-
62-
@recur.stackless
63-
def fact(n, acc=1):
64-
if n == 0:
65-
yield acc
66-
return
67-
yield fact.tailcall(n-1, n*acc)
68-
69-
Non-tail recursion with call() uses heap space so won't overflow:
70-
71-
@recur.stackless
72-
def fib(n):
73-
if n == 0:
74-
yield 1
75-
return
76-
if n == 1:
77-
yield 1
78-
return
79-
yield (yield fib.call(n-1)) + (yield fib.call(n-2))
80-
81-
Mutual recursion also works:
82-
83-
@recur.stackless
84-
def is_odd(n):
85-
if n == 0:
86-
yield False
87-
return
88-
yield is_even.tailcall(n-1)
89-
90-
@recur.stackless
91-
def is_even(n):
92-
if n == 0:
93-
yield True
94-
return
95-
yield is_odd.tailcall(n-1)
60+
Tail call optimised recursion with tailcall()::
61+
62+
@recur.stackless
63+
def fact(n, acc=1):
64+
if n == 0:
65+
yield acc
66+
return
67+
yield fact.tailcall(n-1, n*acc)
68+
69+
Non-tail recursion with call() uses heap space so won't overflow::
70+
71+
@recur.stackless
72+
def fib(n):
73+
if n == 0:
74+
yield 1
75+
return
76+
if n == 1:
77+
yield 1
78+
return
79+
yield (yield fib.call(n-1)) + (yield fib.call(n-2))
80+
81+
Mutual recursion also works::
82+
83+
@recur.stackless
84+
def is_odd(n):
85+
if n == 0:
86+
yield False
87+
return
88+
yield is_even.tailcall(n-1)
89+
90+
@recur.stackless
91+
def is_even(n):
92+
if n == 0:
93+
yield True
94+
return
95+
yield is_odd.tailcall(n-1)
9696
9797
"""
9898

0 commit comments

Comments
 (0)