def create3(): Observable.create(throw_error).transduce( compose( filtering(even), mapping(mul10)) ).subscribe() self.assertRaises(RxException, create3)
def test_chained_transducers(self): result = transduce(transducer=compose(mapping(lambda x: x * x), filtering(lambda x: x % 5 != 0), taking(6), dropping_while(lambda x: x < 15), distinct()), reducer=appending(), iterable=range(20)) self.assertSequenceEqual(result, [16, 36, 49])
def parse_group(lines): cmd, path_type, r, g, b = lines[0].split(';') color = float(r), float(g), float(b) strokes = transduce( compose(partitioning(lambda s: s.upper().startswith('MOVETO;')), filtering(lambda lines: len(lines) > 1), mapping(parse_path)), appending(), lines[1:]) path = PltmePathGroup(strokes, path_type, color) return path
def test_chained_transducers(self): result = transduce(transducer=compose( mapping(lambda x: x*x), filtering(lambda x: x % 5 != 0), taking(6), dropping_while(lambda x: x < 15), distinct()), reducer=appending(), iterable=range(20)) self.assertSequenceEqual(result, [16, 36, 49])
def test_chained_transducers(self): result = transduce(transducer=compose( mapping(lambda x: x*x), filtering(lambda x: x % 5 != 0), taking(6), dropping_while(lambda x: x < 15), distinct()), iterable=range(20)) expected = [16, 36, 49] for r, e in zip(result, expected): self.assertEqual(r, e)
def test_chained_transducers(self): input = [0.0, 0.2, 0.8, 0.9, 1.1, 2.3, 2.6, 3.0, 4.1] output = CollectingSink() iterable_source(iterable=input, target=transduce( compose(pairwise(), mapping(lambda p: p[1] - p[0]), filtering(lambda d: d < 0.5), mapping(lambda _: "double-click")), target=output())) result = list(output) self.assertListEqual(result, ['double-click', 'double-click', 'double-click', 'double-click', 'double-click'])
def test_chained_transducers(self): result = transduce( transducer=compose( mapping(lambda x: x * x), filtering(lambda x: x % 5 != 0), taking(6), dropping_while(lambda x: x < 15), distinct(), ), iterable=range(20), ) expected = [16, 36, 49] for r, e in zip(result, expected): self.assertEqual(r, e)
def test_chained_transducers(self): input = [0.0, 0.2, 0.8, 0.9, 1.1, 2.3, 2.6, 3.0, 4.1] output = CollectingSink() iterable_source(iterable=input, target=transduce(compose( pairwise(), mapping(lambda p: p[1] - p[0]), filtering(lambda d: d < 0.5), mapping(lambda _: "double-click")), target=output())) result = list(output) self.assertListEqual(result, [ 'double-click', 'double-click', 'double-click', 'double-click', 'double-click' ])
from transducer.transducers import filtering, mapping import cosmic_ray.commands import cosmic_ray.counting import cosmic_ray.modules import cosmic_ray.worker from cosmic_ray.testing.test_runner import TestOutcome from cosmic_ray.timing import Timer from cosmic_ray.util import redirect_stdout from cosmic_ray.work_db import use_db, WorkDB LOG = logging.getLogger() REMOVE_COMMENTS = mapping(lambda x: x.split('#')[0]) REMOVE_WHITESPACE = mapping(str.strip) NON_EMPTY = filtering(bool) CONFIG_FILE_PARSER = compose(REMOVE_COMMENTS, REMOVE_WHITESPACE, NON_EMPTY) def _load_file(config_file): """Read configuration from a file. This reads `config_file`, yielding each non-empty line with whitespace and comments stripped off. """ with open(config_file, 'rt', encoding='utf-8') as f: yield from transducer.lazy.transduce(CONFIG_FILE_PARSER, f) @dsc.command('load') def handle_load(config):
def test_filtering(self): result = transduce(transducer=filtering(lambda w: 'x' in w), reducer=appending(), iterable='socks in box fox on clocks'.split()) self.assertListEqual(result, ['box', 'fox'])
def create(): return xs.transduce(compose(filtering(even), mapping(mul10)))
def create3(): Observable.create(throw_error).transduce( compose(filtering(even), mapping(mul10))).subscribe() self.assertRaises(RxException, create3)
def create2(): Observable.empty().transduce( compose(filtering(even), mapping(mul10))).subscribe_(noop, noop, throw_error)
def create(): Observable.throw(RxException()).transduce( compose(filtering(even), mapping(mul10))).subscribe_(noop, throw_error)
import cosmic_ray.commands import cosmic_ray.counting import cosmic_ray.modules import cosmic_ray.json_util import cosmic_ray.worker import cosmic_ray.testing import cosmic_ray.timing from cosmic_ray.work_db import use_db, WorkDB LOG = logging.getLogger() REMOVE_COMMENTS = mapping(lambda x: x.split('#')[0]) REMOVE_WHITESPACE = mapping(str.strip) NON_EMPTY = filtering(bool) CONFIG_FILE_PARSER = compose(REMOVE_COMMENTS, REMOVE_WHITESPACE, NON_EMPTY) def _load_file(config_file): """Read configuration from a file. This reads `config_file`, yielding each non-empty line with whitespace and comments stripped off. """ with open(config_file, 'rt', encoding='utf-8') as f: yield from transducer.lazy.transduce(CONFIG_FILE_PARSER, f)
def create(): Observable.throw_exception(RxException()).transduce( compose( filtering(even), mapping(mul10)) ).subscribe(noop, throw_error)
def create2(): Observable.empty().transduce( compose( filtering(even), mapping(mul10)) ).subscribe(noop, noop, throw_error)