Exemple #1
0
 def switch_file(self):
     return (
         self._current_repo_ro /
         __.checkout_file(self.msg.id, self.msg.path) /
         __.map(lambda a: CommitCurrent()) /
         UnitTask
     )
Exemple #2
0
def measure_layout_views(views: List[ViewMeasureData],
                         total: float) -> List[float]:
    # each pane spacer takes up one cell
    pane_spacers = views.length - 1
    cells = total - pane_spacers
    in_cells = lambda s: s if s > 1 else s * cells
    min_s = actual_min_sizes(views) / in_cells
    max_s = actual_max_sizes(views) / __.map(in_cells)
    minimized = views.map(lambda a: a.state.minimized)
    return balance_sizes(min_s, max_s, view_weights(views), minimized,
                         cells) / round
Exemple #3
0
    def from_yify(self, result):
        data = Map(result)
        title_long = data.get('title_long') | 'no title'
        title = data.get('title') | 'no title'

        def parse(torr):
            td = Map(torr)
            name = '{} {}'.format(title_long, td.get('quality') | '')
            size = td.get('size_bytes') | 0
            size_str = sizeof_fmt(str(size))
            seeds = td.get('seeds') | 0
            hsh = td.get('hash') | 'no_hash'
            magnet_link = yify_magnet(title, hsh)
            return SearchResult(name, size, size_str, seeds, magnet_link)

        return data.get('torrents') / List.wrap / __.map(parse) | List()
Exemple #4
0
 def recover_with(self, f: Callable[[IOException], B]) -> 'IO[B]':
     return IO.delay(lambda: self.attempt).flat_map(
         __.map(IO.pure).value_or(f))
Exemple #5
0
from typing import TypeVar, Callable

from lenses import bind
from lenses.ui import UnboundLens, BoundLens

from amino import Maybe, List, __, Boolean, _, L
from amino.lenses.lens import lens

A = TypeVar('A')

_add = lambda l: __.map(lens.add_lens(l).add_lens)


def path_lens_pred(a: A, sub: Callable[[A], List[A]], lsub,
                   f: Callable[[A], bool]) -> Maybe[BoundLens]:
    g = lambda a: Boolean(f(lsub(a))).maybe(lsub(lens))
    return path_lens(a, sub, g)


def path_lens(a: A, sub: Callable[[A], List[A]],
              f: Callable[[A], Maybe[UnboundLens]]) -> Maybe[BoundLens]:
    return _path_lens(a, sub, f).map(lambda b: bind(a).tuple_(*b))


def path_lens_unbound_pre(a: A, sub: Callable[[A], List[A]],
                          f: Callable[[A], Maybe[UnboundLens]],
                          pre: Callable) -> Maybe[UnboundLens]:
    return (_path_lens(pre(a), sub, f) / (_ / pre(lens).add_lens) /
            __.cons(lens)).map(lambda b: lens.tuple_(*b))

Exemple #6
0
 def map(self, fa: LazyList[A], f: Callable[[A], B]) -> LazyList[B]:
     return fa.copy(lambda a: map(f, a), __.map(f))
Exemple #7
0
 def layout_node(self, node: LayoutNode[L, P]) -> ViewTree:
     sub = node.mod.sub(__.map(self))
     return (self.f.update_layout(sub) if self.f.pred_layout(sub) else sub)