class Params(): coordinate = lens['coordinate'] coordinates = juxt([ coordinate['latitude'].get(), coordinate['longitude'].get(), compose(constrain(0, 1), float, lens.Get('tolerance', '0.5').get()), compose(constrain(10, 19), int, lens.Get('zoom', 16).get()) ]) image_url = lens['image_url'].get()
def make_env_lens(): return (make_filter_lens() & lens.Iso( partial( lambda k_src, k_dst, k_env, l_env, it: (k_src(it[1]), l_env(k_dst(it[1])), l_env(k_env(it[1]))), *(lens[key].get() for key in ("src", "dst")), lens.Get("env", {}).get(), lens.Recur(str).modify(derefer_var) ), dict )).collect()
def lens_food(food, default): incoming_meals = set(food.keys()) stage = lens.Get( 'food', default=default).Each().Filter(lambda tup: tup[0] in incoming_meals) def add_food(food_tup): meal, food_list = food_tup return (meal, uniq(food[meal] + food_list)) update = stage.modify(add_food) return stage.collect(), update
def test_frozendict_get(): state = frozendict.frozendict(one=1, two=2, three=3) result = frozendict.frozendict(one=1, two=2, three=3, four=4) assert lens.Get('four').set(4)(state) == result
def fn(n: int): stage = lens.Get(field) return stage.collect(), stage.modify(lambda m: (m or 0) + n)
def lens_mood(incoming_moods): stage = lens.Get('mood', default=[]) update = stage.set(incoming_moods) return stage.collect(), update
from lenses import lens parse_json = lens.Json() new_food = lens.Get('food') if __name__ == '__main__': comb = parse_json & new_food print(comb.get()('{"food": {"dinner": []}}'))
def get_limit(query: dict): return lens.Get("limit", [{}, {}])[1].Get("value", None).get()(query)
from functools import partial from typing import Callable, List, Optional, Union from lenses import lens from toolz import compose, curry, identity, pipe from phc.easy.util import add_prefixes MAX_RESULT_SIZE = 10000 DEFAULT_SCROLL_SIZE = int(MAX_RESULT_SIZE * 0.9) FHIR_WHERE = lens.Get("where", {}) FHIR_WHERE_TYPE = FHIR_WHERE.Get("type", "") FHIR_SIMPLE_QUERY = FHIR_WHERE.Get("query", {}) FHIR_BOOL_QUERY = FHIR_SIMPLE_QUERY.Get("bool", {}) FHIR_BOOL_MUST_QUERY = FHIR_BOOL_QUERY.Get("must", []) FHIR_LIMIT = lens.Get( "limit", [ {"type": "number", "value": 0}, {"type": "number", "value": DEFAULT_SCROLL_SIZE}, ], )[1]["value"] def get_limit(query: dict): return lens.Get("limit", [{}, {}])[1].Get("value", None).get()(query) def update_limit(query: dict, update: Callable[[int], int]): return FHIR_LIMIT.modify(compose(int, update))(query)
from lenses import lens is_ok = lens.Get('ok', default=0).F(lambda s: bool(int(s))).get()