def var_substep_trigger(substeps): def trigger(end_substep, y, f): pre_conditions = {'substep': substeps} cond_opp = lambda a, b: a and b return var_trigger(y, f, pre_conditions, cond_opp) return lambda y, f: curry(trigger)(substeps)(y)(f)
def gen_range_query2d_data(draw): global MAX_LEN max_key = 2147483647 #2**31 ixys = draw(st.lists( st.tuples( st.integers(min_value=1, max_value=MAX_LEN), st.integers(min_value=1, max_value=max_key), st.integers(min_value=1, max_value=max_key), ), min_size=2, max_size=MAX_LEN, unique_by=lambda ixy:ixy[0] )) nt_ixys = F.lmap(tup(Ixy), ixys) # min/max x max_x_ = max(map(prop('x'),nt_ixys)) max_xv = min(max_x_ + max_x_ // 2, max_key) min_x_ = min(map(prop('x'),nt_ixys)) min_xv = max(min_x_ - min_x_ // 2, 1) min_x, max_x = sorted([ draw(st.integers( min_value=min_xv, max_value=max_xv)), draw(st.integers( min_value=min_xv, max_value=max_xv)) ]) # min/max y max_y_ = max(map(prop('y'),nt_ixys)) max_yv = min(max_y_ + max_y_ // 2, max_key) min_y_ = min(map(prop('y'),nt_ixys)) min_yv = max(min_y_ - min_y_ // 2, 1) min_y, max_y = sorted([ draw(st.integers( min_value=min_yv, max_value=max_yv)), draw(st.integers( min_value=min_yv, max_value=max_yv)) ]) def included(ixy): return(min_x <= ixy.x <= max_x and min_y <= ixy.y <= max_y) #def excluded(ixy): return key(ixy) < min_key or max_key < key(ixy) includeds = go( filter(included,nt_ixys), F.partial(sorted, key=prop('x')), F.curry(F.lmap)(tuple)) #excludeds = [tuple(ixy) for ixy in filter(excluded,nt_ixys)] ixy_map = F.zipdict( map(F.first, ixys), map(tup(Ixy), ixys)) return dict( ixys=ixys, ixy_map=ixy_map, min_x=min_x, max_x=max_x, min_y=min_y, max_y=max_y, includeds=includeds )
def lift_a(cls, n): def _lift_an(c: cls, f, *args): f = c.of(f) for arg in args: f = f.ap_with(c.of(arg)) return f if not isinstance(n, int): return cls.lift_a(1)(n) if n <= 0: raise ValueError return curry(_lift_an, n + 2)(cls)
def env_trigger(end_substep): def trigger(end_substep, trigger_field, trigger_vals, funct_list): def env_update(state_dict, sweep_dict, target_value): state_dict_copy = deepcopy(state_dict) # Use supstep to simulate current sysMetrics if state_dict_copy['substep'] == end_substep: state_dict_copy['timestep'] = state_dict_copy['timestep'] + 1 if state_dict_copy[trigger_field] in trigger_vals: for g in funct_list: target_value = g(sweep_dict, target_value) del state_dict_copy return target_value return env_update return lambda trigger_field, trigger_vals, funct_list: \ curry(trigger)(end_substep)(trigger_field)(trigger_vals)(funct_list)
def apply(f, y: str, incr_by: int): return lambda _g, step, sL, s, _input: (y, curry(f)(s[y])(incr_by))
from typing import Any, Callable, Dict, List, Tuple from copy import deepcopy from functools import reduce from funcy import curry from cadCAD.utils import flatten from cadCAD.engine.utils import engine_exception id_exception: Callable = curry(engine_exception)(KeyError)(KeyError)(None) class Executor: def __init__(self, policy_ops, policy_update_exception: Callable = id_exception, state_update_exception: Callable = id_exception) -> None: self.policy_ops = policy_ops self.state_update_exception = state_update_exception self.policy_update_exception = policy_update_exception def get_policy_input(self, sweep_dict: Dict[str, List[Any]], sub_step: int, sL: List[Dict[str, Any]], s: Dict[str, Any], funcs: List[Callable], additional_objs) -> Dict[str, Any]: ops = self.policy_ops def get_col_results(sweep_dict, sub_step, sL, s, funcs): def policy_scope_tuner(additional_objs, f): if additional_objs is None:
# | |__| |_| | | | | |_) | || |\ |/ ___ \| || |_| | _ < ___) | # \____\___/|_| |_|____/___|_| \_/_/ \_\_| \___/|_| \_\____/ # def map_union(proc, lst): res = NodeSet() for node in lst: res.append_or_extend(proc(node)) return res def nfilter(pred, nodes): return NodeSet.from_seq(filter(pred, nodes.as_node_set())) make_filter = curry(nfilter) def make_mapper(func): def _mapper(nodes): return map_union(func, nodes.as_node_set()) return _mapper def compose_selectors(*selectors): # compose_selectors(fn1, fn2) == lambda x: fn2(fn1(x)) _compose = lambda f,g: lambda x: g(f(x)) return reduce(_compose, selectors) # ____ _____ _ _____ ____ _____ ___ ____ ____ # / ___|| ____| | | ____/ ___|_ _/ _ \| _ \/ ___|
def __init__(self, something): self._value = something if not isinstance(something, Callable) else curry(something)
# \____\___/|_| |_|____/___|_| \_/_/ \_\_| \___/|_| \_\____/ # def map_union(proc, lst): res = NodeSet() for node in lst: res.append_or_extend(proc(node)) return res def nfilter(pred, nodes): return NodeSet.from_seq(filter(pred, nodes.as_node_set())) make_filter = curry(nfilter) def make_mapper(func): def _mapper(nodes): return map_union(func, nodes.as_node_set()) return _mapper def compose_selectors(*selectors): # compose_selectors(fn1, fn2) == lambda x: fn2(fn1(x)) _compose = lambda f, g: lambda x: g(f(x)) return reduce(_compose, selectors)
MUTABLE = {list, set, dict} Primitive = Union[int, bool, float, str, set, list, tuple, dict, bytes] Listlike = Union[set, list, tuple] Singular = Union[Primitive, Callable] Plural = Union[set, list, tuple, dict] Dualism = Union[Singular, Plural] PipeCombineFn = Callable[[Any, None, None], Any] textual = fy.isa(*TEXTLIKE) numeric = fy.isa(numbers.Number) isint = fy.isa(int) isdict = fy.isa(dict) isgen = fy.isa(types.GeneratorType) iseq = fy.curry(operator.eq) def unbox(x: Any) -> Singular: """ >>> unbox(1) 1 >>> unbox((1,)) 1 >>> unbox((1,2)) (1, 2) >>> unbox((1,2,(3,4))) (1, 2, (3, 4)) """ return x[0] if fy.is_seqcoll(x) and len(x) == 1 else x
def of(cls, something: _SometimesCallable[_a]) -> Cont[_SometimesCallable[_a]]: return Cont(curry(lambda k: k(something)))
def __init__(self: Cont[_r, _a], something: _a): self._composing = curry(something) if isinstance( something, Callable) else something
import funcy import operator from contas import gerar_contas from pinterest import criar_conta, seguir_conta contas = gerar_contas(300, "kivson+teste59{}@gmail.com", 'supersenha@123') contas_criadas = filter(operator.itemgetter('criado'), map(criar_conta, contas)) me_seguir = funcy.curry(seguir_conta)([ 'https://br.pinterest.com/kmarcell', 'https://www.pinterest.com/laismeuchi' ]) seguindo = map(me_seguir, contas_criadas) for c in seguindo: print(c)
def __init__(self: Just[_a], something: _a): self._value = something if not isinstance( something, Callable) else curry(something)
def filter_history(path: 'Path') -> 'list[str]': return flow(path, os.listdir, sorted, curry(lfilter)(_ != 'history'))