-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemdoc.py
More file actions
531 lines (520 loc) · 26.4 KB
/
emdoc.py
File metadata and controls
531 lines (520 loc) · 26.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# __coconut_hash__ = 0x4155f542
# Compiled with Coconut version 1.2.3 [Colonel]
# Coconut Header: --------------------------------------------------------
from __future__ import print_function, absolute_import, unicode_literals, division
import sys as _coconut_sys
if _coconut_sys.version_info < (3,):
py_chr, py_filter, py_hex, py_input, py_int, py_map, py_object, py_oct, py_open, py_print, py_range, py_str, py_zip, py_filter, py_reversed, py_enumerate = chr, filter, hex, input, int, map, object, oct, open, print, range, str, zip, filter, reversed, enumerate
py_raw_input, py_xrange = raw_input, xrange
_coconut_NotImplemented, _coconut_raw_input, _coconut_xrange, _coconut_int, _coconut_long, _coconut_print, _coconut_str, _coconut_unicode, _coconut_repr = NotImplemented, raw_input, xrange, int, long, print, str, unicode, repr
from future_builtins import *
chr, str = unichr, unicode
from io import open
class object(object):
__slots__ = ()
def __ne__(self, other):
eq = self == other
if eq is _coconut_NotImplemented:
return eq
else:
return not eq
class range(object):
__slots__ = ("_xrange",)
if hasattr(_coconut_xrange, "__doc__"):
__doc__ = _coconut_xrange.__doc__
def __init__(self, *args):
self._xrange = _coconut_xrange(*args)
def __iter__(self):
return _coconut.iter(self._xrange)
def __reversed__(self):
return _coconut.reversed(self._xrange)
def __len__(self):
return _coconut.len(self._xrange)
def __contains__(self, elem):
return elem in self._xrange
def __getitem__(self, index):
if _coconut.isinstance(index, _coconut.slice):
args = _coconut.slice(*self._args)
start, stop, step, ind_step = (args.start if args.start is not None else 0), args.stop, (args.step if args.step is not None else 1), (index.step if index.step is not None else 1)
return self.__class__((start if ind_step >= 0 else stop - step) if index.start is None else start + step * index.start if index.start >= 0 else stop + step * index.start, (stop if ind_step >= 0 else start - step) if index.stop is None else start + step * index.stop if index.stop >= 0 else stop + step * index.stop, step if index.step is None else step * index.step)
else:
return self._xrange[index]
def count(self, elem):
"""Count the number of times elem appears in the range."""
return int(elem in self._xrange)
def index(self, elem):
"""Find the index of elem in the range."""
if elem not in self._xrange: raise _coconut.ValueError(_coconut.repr(elem) + " is not in range")
start, _, step = self._xrange.__reduce_ex__(2)[1]
return (elem - start) // step
def __repr__(self):
return _coconut.repr(self._xrange)[1:]
@property
def _args(self):
return self._xrange.__reduce__()[1]
def __reduce_ex__(self, protocol):
return (self.__class__, self._xrange.__reduce_ex__(protocol)[1])
def __reduce__(self):
return self.__reduce_ex__(_coconut.pickle.DEFAULT_PROTOCOL)
def __hash__(self):
return _coconut.hash(self._args)
def __copy__(self):
return self.__class__(*self._args)
def __eq__(self, other):
return _coconut.isinstance(other, self.__class__) and self._args == other._args
from collections import Sequence as _coconut_Sequence
_coconut_Sequence.register(range)
class int(_coconut_int):
__slots__ = ()
if hasattr(_coconut_int, "__doc__"):
__doc__ = _coconut_int.__doc__
class __metaclass__(type):
def __instancecheck__(cls, inst):
return _coconut.isinstance(inst, (_coconut_int, _coconut_long))
def __subclasscheck__(cls, subcls):
return _coconut.issubclass(subcls, (_coconut_int, _coconut_long))
from functools import wraps as _coconut_wraps
@_coconut_wraps(_coconut_print)
def print(*args, **kwargs):
file = kwargs.get("file", _coconut_sys.stdout)
if _coconut.hasattr(file, "encoding") and file.encoding is not None:
return _coconut_print(*(_coconut_unicode(x).encode(file.encoding) for x in args), **kwargs)
else:
return _coconut_print(*(_coconut_unicode(x).encode() for x in args), **kwargs)
@_coconut_wraps(_coconut_raw_input)
def input(*args, **kwargs):
if _coconut.hasattr(_coconut_sys.stdout, "encoding") and _coconut_sys.stdout.encoding is not None:
return _coconut_raw_input(*args, **kwargs).decode(_coconut_sys.stdout.encoding)
else:
return _coconut_raw_input(*args, **kwargs).decode()
@_coconut_wraps(_coconut_repr)
def repr(obj):
if isinstance(obj, _coconut_unicode):
return _coconut_repr(obj)[1:]
else:
return _coconut_repr(obj)
ascii = repr
def raw_input(*args):
"""Coconut uses Python 3 "input" instead of Python 2 "raw_input"."""
raise _coconut.NameError('Coconut uses Python 3 "input" instead of Python 2 "raw_input"')
def xrange(*args):
"""Coconut uses Python 3 "range" instead of Python 2 "xrange"."""
raise _coconut.NameError('Coconut uses Python 3 "range" instead of Python 2 "xrange"')
if _coconut_sys.version_info < (2, 7):
import functools as _coconut_functools, copy_reg as _coconut_copy_reg
def _coconut_new_partial(func, args, keywords):
return _coconut_functools.partial(func, *(args if args is not None else ()), **(keywords if keywords is not None else {}))
_coconut_copy_reg.constructor(_coconut_new_partial)
def _coconut_reduce_partial(self):
return (_coconut_new_partial, (self.func, self.args, self.keywords))
_coconut_copy_reg.pickle(_coconut_functools.partial, _coconut_reduce_partial)
else:
py_chr, py_filter, py_hex, py_input, py_int, py_map, py_object, py_oct, py_open, py_print, py_range, py_str, py_zip, py_filter, py_reversed, py_enumerate = chr, filter, hex, input, int, map, object, oct, open, print, range, str, zip, filter, reversed, enumerate
class _coconut(object):
import collections, functools, imp, itertools, operator, types, copy, pickle
if _coconut_sys.version_info >= (2, 7):
OrderedDict = collections.OrderedDict
else:
OrderedDict = dict
if _coconut_sys.version_info < (3, 3):
abc = collections
else:
import collections.abc as abc
IndexError, KeyError, NameError, TypeError, ValueError, classmethod, dict, enumerate, filter, frozenset, getattr, hasattr, hash, int, isinstance, issubclass, iter, len, list, map, min, max, next, object, property, range, reversed, set, slice, str, sum, super, tuple, zip, repr, bytearray = IndexError, KeyError, NameError, TypeError, ValueError, classmethod, dict, enumerate, filter, frozenset, getattr, hasattr, hash, int, isinstance, issubclass, iter, len, list, map, min, max, next, object, property, range, reversed, set, slice, str, sum, super, tuple, zip, staticmethod(repr), bytearray
class MatchError(Exception):
"""Pattern-matching error."""
__slots__ = ("pattern", "value")
class _coconut_tail_call(Exception):
__slots__ = ("func", "args", "kwargs")
def __init__(self, func, *args, **kwargs):
self.func, self.args, self.kwargs = func, args, kwargs
def _coconut_tco(func):
@_coconut.functools.wraps(func)
def tail_call_optimized_func(*args, **kwargs):
call_func = func
while True:
try:
del kwargs["_coconut_inside_tco"]
except _coconut.KeyError:
pass
else:
return call_func(*args, **kwargs) # pass --no-tco to clean up your traceback
if _coconut.hasattr(call_func, "_coconut_is_tco"):
kwargs["_coconut_inside_tco"] = call_func._coconut_is_tco
try:
return call_func(*args, **kwargs) # pass --no-tco to clean up your traceback
except _coconut_tail_call as tail_call:
call_func, args, kwargs = tail_call.func, tail_call.args, tail_call.kwargs
tail_call_optimized_func._coconut_is_tco = True
return tail_call_optimized_func
def _coconut_igetitem(iterable, index):
if isinstance(iterable, (_coconut_reversed, _coconut_map, _coconut.filter, _coconut.zip, _coconut_enumerate, _coconut_count, _coconut.abc.Sequence)):
return iterable[index]
elif not _coconut.isinstance(index, _coconut.slice):
if index < 0:
return _coconut.collections.deque(iterable, maxlen=-index)[0]
else:
return _coconut.next(_coconut.itertools.islice(iterable, index, index + 1))
elif index.start is not None and index.start < 0 and (index.stop is None or index.stop < 0) and index.step is None:
queue = _coconut.collections.deque(iterable, maxlen=-index.start)
if index.stop is not None:
queue = _coconut.tuple(queue)[:index.stop - index.start]
return queue
elif (index.start is not None and index.start < 0) or (index.stop is not None and index.stop < 0) or (index.step is not None and index.step < 0):
return _coconut.tuple(iterable)[index]
else:
return _coconut.itertools.islice(iterable, index.start, index.stop, index.step)
class _coconut_compose(object):
__slots__ = ("funcs",)
def __init__(self, *funcs):
self.funcs = funcs
def __call__(self, *args, **kwargs):
arg = self.funcs[-1](*args, **kwargs)
for f in self.funcs[-2::-1]:
arg = f(arg)
return arg
def __repr__(self):
return "..".join(_coconut.repr(f) for f in self.funcs)
def __reduce__(self):
return (_coconut_compose, self.funcs)
def _coconut_pipe(x, f): return f(x)
def _coconut_starpipe(xs, f): return f(*xs)
def _coconut_backpipe(f, x): return f(x)
def _coconut_backstarpipe(f, xs): return f(*xs)
def _coconut_bool_and(a, b): return a and b
def _coconut_bool_or(a, b): return a or b
def _coconut_minus(*args): return _coconut.operator.neg(*args) if len(args) < 2 else _coconut.operator.sub(*args)
@_coconut.functools.wraps(_coconut.itertools.tee)
def tee(iterable, n=2):
if n >= 0 and _coconut.isinstance(iterable, (_coconut.tuple, _coconut.frozenset)):
return (iterable,)*n
elif n > 0 and (_coconut.hasattr(iterable, "__copy__") or _coconut.isinstance(iterable, _coconut.abc.Sequence)):
return (iterable,) + _coconut.tuple(_coconut.copy.copy(iterable) for i in range(n - 1))
else:
return _coconut.itertools.tee(iterable, n)
class reversed(object):
__slots__ = ("_iter",)
if hasattr(_coconut.map, "__doc__"):
__doc__ = _coconut.reversed.__doc__
def __new__(cls, iterable):
if _coconut.isinstance(iterable, _coconut.range):
return iterable[::-1]
elif not _coconut.hasattr(iterable, "__reversed__") or _coconut.isinstance(iterable, (_coconut.list, _coconut.tuple)):
return _coconut.object.__new__(cls)
else:
return _coconut.reversed(iterable)
def __init__(self, iterable):
self._iter = iterable
def __iter__(self):
return _coconut.reversed(self._iter)
def __getitem__(self, index):
if _coconut.isinstance(index, _coconut.slice):
return _coconut_igetitem(self._iter, _coconut.slice(-(index.start + 1) if index.start is not None else None, -(index.stop + 1) if index.stop else None, -(index.step if index.step is not None else 1)))
else:
return _coconut_igetitem(self._iter, -(index + 1))
def __reversed__(self):
return self._iter
def __len__(self):
return _coconut.len(self._iter)
def __repr__(self):
return "reversed(" + _coconut.repr(self._iter) + ")"
def __hash__(self):
return -_coconut.hash(self._iter)
def __reduce__(self):
return (self.__class__, (self._iter,))
def __reduce_ex__(self, _):
return self.__reduce__()
def __copy__(self):
return self.__class__(_coconut.copy.copy(self._iter))
def __eq__(self, other):
return isinstance(other, self.__class__) and self._iter == other._iter
def __contains__(self, elem):
return elem in self._iter
def count(self, elem):
"""Count the number of times elem appears in the reversed iterator."""
return self._iter.count(elem)
def index(self, elem):
"""Find the index of elem in the reversed iterator."""
return _coconut.len(self._iter) - self._iter.index(elem) - 1
def __fmap__(self, func):
return self.__class__(_coconut_map(func, self._iter))
class map(_coconut.map):
__slots__ = ("_func", "_iters")
if hasattr(_coconut.map, "__doc__"):
__doc__ = _coconut.map.__doc__
def __new__(cls, function, *iterables):
new_map = _coconut.map.__new__(cls, function, *iterables)
new_map._func, new_map._iters = function, iterables
return new_map
def __getitem__(self, index):
if _coconut.isinstance(index, _coconut.slice):
return self.__class__(self._func, *(_coconut_igetitem(i, index) for i in self._iters))
else:
return self._func(*(_coconut_igetitem(i, index) for i in self._iters))
def __reversed__(self):
return self.__class__(self._func, *(_coconut_reversed(i) for i in self._iters))
def __len__(self):
return _coconut.min(_coconut.len(i) for i in self._iters)
def __repr__(self):
return "map(" + _coconut.repr(self._func) + ", " + ", ".join((_coconut.repr(i) for i in self._iters)) + ")"
def __reduce__(self):
return (self.__class__, (self._func,) + self._iters)
def __reduce_ex__(self, _):
return self.__reduce__()
def __copy__(self):
return self.__class__(self._func, *_coconut_map(_coconut.copy.copy, self._iters))
def __fmap__(self, func):
return self.__class__(_coconut_compose(func, self._func), *self._iters)
class parallel_map(map):
"""Multiprocessing implementation of map using concurrent.futures.
Requires arguments to be pickleable."""
__slots__ = ()
def __iter__(self):
from concurrent.futures import ProcessPoolExecutor
with ProcessPoolExecutor() as executor:
return _coconut.iter(_coconut.tuple(executor.map(self._func, *self._iters)))
def __repr__(self):
return "parallel_" + _coconut_map.__repr__(self)
class concurrent_map(map):
"""Multithreading implementation of map using concurrent.futures."""
__slots__ = ()
def __iter__(self):
from concurrent.futures import ThreadPoolExecutor
from multiprocessing import cpu_count # cpu_count() * 5 is the default Python 3 thread count
with ThreadPoolExecutor(cpu_count() * 5) as executor:
return _coconut.iter(_coconut.tuple(executor.map(self._func, *self._iters)))
def __repr__(self):
return "concurrent_" + _coconut_map.__repr__(self)
class filter(_coconut.filter):
__slots__ = ("_func", "_iter")
if hasattr(_coconut.filter, "__doc__"):
__doc__ = _coconut.filter.__doc__
def __new__(cls, function, iterable):
new_filter = _coconut.filter.__new__(cls, function, iterable)
new_filter._func, new_filter._iter = function, iterable
return new_filter
def __reversed__(self):
return self.__class__(self._func, _coconut_reversed(self._iter))
def __repr__(self):
return "filter(" + _coconut.repr(self._func) + ", " + _coconut.repr(self._iter) + ")"
def __reduce__(self):
return (self.__class__, (self._func, self._iter))
def __reduce_ex__(self, _):
return self.__reduce__()
def __copy__(self):
return self.__class__(self._func, _coconut.copy.copy(self._iter))
def __fmap__(self, func):
return _coconut_map(func, self)
class zip(_coconut.zip):
__slots__ = ("_iters",)
if hasattr(_coconut.zip, "__doc__"):
__doc__ = _coconut.zip.__doc__
def __new__(cls, *iterables):
new_zip = _coconut.zip.__new__(cls, *iterables)
new_zip._iters = iterables
return new_zip
def __getitem__(self, index):
if _coconut.isinstance(index, _coconut.slice):
return self.__class__(*(_coconut_igetitem(i, index) for i in self._iters))
else:
return _coconut.tuple(_coconut_igetitem(i, index) for i in self._iters)
def __reversed__(self):
return self.__class__(*(_coconut_reversed(i) for i in self._iters))
def __len__(self):
return _coconut.min(_coconut.len(i) for i in self._iters)
def __repr__(self):
return "zip(" + ", ".join((_coconut.repr(i) for i in self._iters)) + ")"
def __reduce__(self):
return (self.__class__, self._iters)
def __reduce_ex__(self, _):
return self.__reduce__()
def __copy__(self):
return self.__class__(*_coconut_map(_coconut.copy.copy, self._iters))
def __fmap__(self, func):
return _coconut_map(func, self)
class enumerate(_coconut.enumerate):
__slots__ = ("_iter", "_start")
if hasattr(_coconut.enumerate, "__doc__"):
__doc__ = _coconut.enumerate.__doc__
def __new__(cls, iterable, start=0):
new_enumerate = _coconut.enumerate.__new__(cls, iterable, start)
new_enumerate._iter, new_enumerate._start = iterable, start
return new_enumerate
def __getitem__(self, index):
if _coconut.isinstance(index, _coconut.slice):
return self.__class__(_coconut_igetitem(self._iter, index), self._start + (0 if index.start is None else index.start if index.start >= 0 else len(self._iter) + index.start))
else:
return (self._start + index, _coconut_igetitem(self._iter, index))
def __len__(self):
return _coconut.len(self._iter)
def __repr__(self):
return "enumerate(" + _coconut.repr(self._iter) + ", " + _coconut.repr(self._start) + ")"
def __reduce__(self):
return (self.__class__, (self._iter, self._start))
def __reduce_ex__(self, _):
return self.__reduce__()
def __copy__(self):
return self.__class__(_coconut.copy.copy(self._iter), self._start)
def __fmap__(self, func):
return _coconut_map(func, self)
class count(object):
"""count(start, step) returns an infinite iterator starting at start and increasing by step."""
__slots__ = ("_start", "_step")
def __init__(self, start=0, step=1):
self._start, self._step = start, step
def __iter__(self):
while True:
yield self._start
self._start += self._step
def __contains__(self, elem):
return elem >= self._start and (elem - self._start) % self._step == 0
def __getitem__(self, index):
if _coconut.isinstance(index, _coconut.slice) and (index.start is None or index.start >= 0) and (index.stop is None or index.stop >= 0):
if index.stop is None:
return self.__class__(self._start + (index.start if index.start is not None else 0), self._step * (index.step if index.step is not None else 1))
elif _coconut.isinstance(self._start, _coconut.int) and _coconut.isinstance(self._step, _coconut.int):
return _coconut.range(self._start + self._step * (index.start if index.start is not None else 0), self._start + self._step * index.stop, self._step * (index.step if index.step is not None else 1))
else:
return _coconut_map(self.__getitem__, _coconut.range(index.start if index.start is not None else 0, index.stop, index.step if index.step is not None else 1))
elif index >= 0:
return self._start + self._step * index
else:
raise _coconut.IndexError("count indices must be positive")
def count(self, elem):
"""Count the number of times elem appears in the count."""
return int(elem in self)
def index(self, elem):
"""Find the index of elem in the count."""
if elem not in self:
raise _coconut.ValueError(_coconut.repr(elem) + " is not in count")
return (elem - self._start) // self._step
def __repr__(self):
return "count(" + _coconut.str(self._start) + ", " + _coconut.str(self._step) + ")"
def __hash__(self):
return _coconut.hash((self._start, self._step))
def __reduce__(self):
return (self.__class__, (self._start, self._step))
def __copy__(self):
return self.__class__(self._start, self._step)
def __eq__(self, other):
return isinstance(other, self.__class__) and self._start == other._start and self._step == other._step
def __fmap__(self, func):
return _coconut_map(func, self)
def recursive_iterator(func):
"""Decorates a function by optimizing it for iterator recursion.
Requires function arguments to be pickleable."""
tee_store = {}
@_coconut.functools.wraps(func)
def recursive_iterator_func(*args, **kwargs):
hashable_args_kwargs = _coconut.pickle.dumps((args, kwargs), _coconut.pickle.HIGHEST_PROTOCOL)
try:
to_tee = tee_store[hashable_args_kwargs]
except _coconut.KeyError:
to_tee = func(*args, **kwargs)
tee_store[hashable_args_kwargs], to_return = _coconut_tee(to_tee)
return to_return
return recursive_iterator_func
def addpattern(base_func):
"""Decorator to add a new case to a pattern-matching function, where the new case is checked last."""
def pattern_adder(func):
@_coconut.functools.wraps(func)
@_coconut_tco
def add_pattern_func(*args, **kwargs):
try:
return base_func(*args, **kwargs)
except _coconut_MatchError:
raise _coconut_tail_call(func, *args, **kwargs)
return add_pattern_func
return pattern_adder
def prepattern(base_func):
"""Decorator to add a new case to a pattern-matching function, where the new case is checked first."""
def pattern_prepender(func):
return addpattern(func)(base_func)
return pattern_prepender
class _coconut_partial(object):
__slots__ = ("func", "_argdict", "_arglen", "_stargs", "keywords")
if hasattr(_coconut.functools.partial, "__doc__"):
__doc__ = _coconut.functools.partial.__doc__
def __init__(self, func, argdict, arglen, *args, **kwargs):
self.func, self._argdict, self._arglen, self._stargs, self.keywords = func, argdict, arglen, args, kwargs
def __reduce__(self):
return (self.__class__, (self.func, self._argdict, self._arglen) + self._stargs, self.keywords)
def __setstate__(self, keywords):
self.keywords = keywords
@property
def args(self):
return _coconut.tuple(self._argdict.get(i) for i in _coconut.range(self._arglen)) + self._stargs
def __call__(self, *args, **kwargs):
callargs = []
argind = 0
for i in _coconut.range(self._arglen):
if i in self._argdict:
callargs.append(self._argdict[i])
elif argind >= _coconut.len(args):
raise _coconut.TypeError("expected at least " + _coconut.str(self._arglen - _coconut.len(self._argdict)) + " argument(s) to " + _coconut.repr(self))
else:
callargs.append(args[argind])
argind += 1
callargs += self._stargs
callargs += args[argind:]
kwargs.update(self.keywords)
return self.func(*callargs, **kwargs)
def __repr__(self):
args = []
for i in _coconut.range(self._arglen):
if i in self._argdict:
args.append(_coconut.repr(self._argdict[i]))
else:
args.append("?")
for arg in self._stargs:
args.append(_coconut.repr(arg))
return _coconut.repr(self.func) + "$(" + ", ".join(args) + ")"
class datamaker(object):
__slots__ = ("data_type",)
def __new__(cls, data_type):
if _coconut.hasattr(data_type, "_make") and (_coconut.issubclass(data_type, _coconut.tuple) or _coconut.isinstance(data_type, _coconut.tuple)):
return _coconut.object.__new__(cls)
else:
return _coconut.functools.partial(_coconut.super(data_type, data_type).__new__, data_type)
def __init__(self, data_type):
self.data_type = data_type
def __call__(self, *args, **kwargs):
return self.data_type._make(args, **kwargs)
def __repr__(self):
return "datamaker(" + _coconut.repr(data_type) + ")"
def __reduce__(self):
return (_coconut_datamaker, (self.data_type,))
def consume(iterable, keep_last=0):
"""Fully exhaust iterable and return the last keep_last elements."""
return _coconut.collections.deque(iterable, maxlen=keep_last) # fastest way to exhaust an iterator
def fmap(func, obj):
"""Creates a copy of obj with func applied to its contents."""
if _coconut.hasattr(obj, "__fmap__"):
return obj.__fmap__(func)
args = _coconut_map(func, obj)
if _coconut.isinstance(obj, _coconut.dict):
args = _coconut_zip(args, obj.values())
if _coconut.isinstance(obj, _coconut.tuple) and _coconut.hasattr(obj, "_make"):
return obj._make(args)
if _coconut.isinstance(obj, (_coconut.map, _coconut.range)):
return args
if _coconut.isinstance(obj, _coconut.str):
return "".join(args)
return obj.__class__(args)
_coconut_MatchError, _coconut_count, _coconut_enumerate, _coconut_reversed, _coconut_map, _coconut_tee, _coconut_zip, reduce, takewhile, dropwhile = MatchError, count, enumerate, reversed, map, tee, zip, _coconut.functools.reduce, _coconut.itertools.takewhile, _coconut.itertools.dropwhile
# Compiled Coconut: ------------------------------------------------------
class Emdoc(_coconut.collections.namedtuple("Emdoc", "title id secs"), _coconut.object):
__slots__ = ()
__ne__ = _coconut.object.__ne__
class Section(_coconut.collections.namedtuple("Section", "secnum heading initsubsecs subsecgrps"), _coconut.object):
__slots__ = ()
__ne__ = _coconut.object.__ne__
class Subsec(_coconut.collections.namedtuple("Subsec", "subsecnum content"), _coconut.object):
__slots__ = ()
__ne__ = _coconut.object.__ne__
class Subsecgrp(_coconut.collections.namedtuple("Subsecgrp", "subheading subsecs"), _coconut.object):
__slots__ = ()
__ne__ = _coconut.object.__ne__
egdoc = Emdoc('Example Explanatory Memo', '2017/1', [Section('1', 'Introduction', ['', 'This introduces the document.'], []), Section('2', 'Another Section', [], [Subsecgrp('First Group', [Subsec('2.1', 'Content for sec 2.1'), Subsec('2.2', 'Content for sec 2.2')])])])