Skip to content

Commit 4456199

Browse files
committed
-
1 parent 44fbb6e commit 4456199

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

source_py3/python_toolbox/combi/chain_space.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ class ChainSpace(sequence_tools.CuteSequenceMixin, collections.Sequence):
2222
index number rather than just iteration.
2323
'''
2424
def __init__(self, sequences):
25-
2625
self.sequences = nifty_collections.LazyTuple(
2726
(sequence_tools.ensure_iterable_is_immutable_sequence(
2827
sequence, default_type=nifty_collections.LazyTuple)
2928
for sequence in sequences)
3029
)
30+
3131
@caching.CachedProperty
3232
@nifty_collections.LazyTuple.factory()
3333
def accumulated_lengths(self):
@@ -46,7 +46,6 @@ def accumulated_lengths(self):
4646

4747
length = caching.CachedProperty(lambda self: self.accumulated_lengths[-1])
4848

49-
5049
def __repr__(self):
5150
return '<%s: %s>' % (
5251
type(self).__name__,
@@ -87,6 +86,7 @@ def __contains__(self, item):
8786
if (not isinstance(sequence, str) or isinstance(item, str)))
8887

8988
def index(self, item):
89+
'''Get the index number of `item` in this space.'''
9090
for sequence, accumulated_length in zip(self.sequences,
9191
self.accumulated_lengths):
9292
try:
@@ -105,6 +105,4 @@ def __bool__(self):
105105
try: next(iter(self))
106106
except StopIteration: return False
107107
else: return True
108-
109-
110108

source_py3/python_toolbox/combi/map_space.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212

1313

1414
class MapSpace(sequence_tools.CuteSequenceMixin, collections.Sequence):
15+
'''
16+
A space of a function applied to a sequence.
17+
18+
This is similar to Python's builtin `map`, except that it behaves like a
19+
sequence rather than an iterable. (Though it's also iterable.) You can
20+
access any item by its index number.
21+
'''
1522
def __init__(self, function, sequence):
1623

1724
self.function = function

0 commit comments

Comments
 (0)