Ejemplo n.º 1
0
def unzip(seq):
    """Inverse of ``zip``

    >>> a, b = unzip([('a', 1), ('b', 2)])
    >>> list(a)
    ['a', 'b']
    >>> list(b)
    [1, 2]

    Unlike the naive implementation ``def unzip(seq): zip(*seq)`` this
    implementation can handle a finite sequence of infinite sequences.

    Caveats:

    * The implementation uses ``tee``, and so can use a significant amount
      of auxiliary storage if the resulting iterators are consumed at
      different times.

    * The top level sequence cannot be infinite.

    """

    seq = iter(seq)

    # Check how many iterators we need
    try:
        first = tuple(next(seq))
    except StopIteration:
        return tuple()

    # and create them
    niters = len(first)
    seqs = tee(cons(first, seq), niters)

    return tuple(starmap(pluck, enumerate(seqs)))
Ejemplo n.º 2
0
Archivo: main.py Proyecto: tek/proteome
 def __init__(
         self,
         vim: NvimFacade,
         config_path: Path,
         plugins: List[str],
         bases: List[Path],
         type_bases: Map[Path, List[str]],
         initial_projects: Maybe[Projects]=Empty()
 ) -> None:
     self._config_path = config_path
     self._bases = bases
     self._type_bases = type_bases
     self._initial_projects = initial_projects
     core = 'proteome.plugins.core'
     ProteomeState.__init__(self, vim, List.wrap(cons(core, plugins)))
Ejemplo n.º 3
0
def test_cons():
    assert list(cons(1, [2, 3])) == [1, 2, 3]
Ejemplo n.º 4
0
Archivo: list.py Proyecto: tek/tryp.py
 def cons(self, item):
     return List.wrap(cons(item, self))
                compose(list, partial(take, args.predictions_limit))),
            ujson.load(args.dataset_file)))

    sections = groupby(lambda x: tuple(map(x.get, ['make', 'model'])),
                       dataset).items()

    evaluation_base_url = f'https://storage.cloud.google.com/dev_visual_search/evaluations/output/by-id/{args.evaluation_id}'

    def link_to_page(key):
        if key is None:
            return None
        make, model = key
        return f'{evaluation_base_url}/prediction-{make}-{model}.html'

    for prev, current, next in sliding_window(
            3, cons(None, concat([sections, [None]]))):
        key, section = current
        make, model = key

        prev_key, _ = prev if prev is not None else (None, None)
        next_key, _ = next if next is not None else (None, None)

        page = to_page(
            section, {
                'prev': link_to_page(prev_key),
                'parent': '',
                'next': link_to_page(next_key)
            }, {
                'title': f'Prediction report for {make} / {model}',
                'evaluation_id': args.evaluation_id,
                'image_base_path': args.image_base_path,
Ejemplo n.º 6
0
 def cons(self, item: A) -> 'List[A]':
     return List.wrap(cons(item, self))