faust.utils.functional
¶
Functional utilities.
-
faust.utils.functional.
consecutive_numbers
(it: Iterable[int]) → Iterator[Sequence[int]][source]¶ Find runs of consecutive numbers.
Notes
See https://docs.python.org/2.6/library/itertools.html#examples
-
faust.utils.functional.
deque_prune
(l: Deque[T], max: int = None) → Optional[T][source]¶ Prune oldest element in deque if size exceeds
max
.- Return type
Optional
[~T]
-
faust.utils.functional.
deque_pushpopmax
(l: Deque[T], item: T, max: int = None) → Optional[T][source]¶ Append to deque and remove oldest element if size exceeds
max
.- Return type
Optional
[~T]
-
faust.utils.functional.
translate
(table: Mapping, s: str) → str[source]¶ Replace characters and patterns in string
s
.Works similar to
str.translate()
, but replacements and patterns can be full length strings instead of character by character.- Parameters
Note
Table is the first argument in the signature for compatibility with
partial()
:>>> t = partial(translate, {'.': '_'}) >>> t('foo.bar') 'foo_bar'
Examples
>>> translate('foo.bar@baz', {'.': '_', '@': '.'}) 'foo_bar.baz'
- Return type