|
2 | 2 |
|
3 | 3 | __all__ = ['ifnone', 'maybe_attr', 'basic_repr', 'get_class', 'mk_class', 'wrap_class', 'ignore_exceptions', |
4 | 4 | 'exec_local', 'risinstance', 'Inf', 'in_', 'lt', 'gt', 'le', 'ge', 'eq', 'ne', 'add', 'sub', 'mul', |
5 | | - 'truediv', 'is_', 'is_not', 'in_', 'true', 'gen', 'chunked', 'AttrDict', 'dict2obj', 'with_cast', |
6 | | - 'store_attr', 'attrdict', 'properties', 'camel2snake', 'snake2camel', 'class2attr', 'hasattrs', 'setattrs', |
7 | | - 'ShowPrint', 'Int', 'Str', 'Float', 'tuplify', 'detuplify', 'replicate', 'uniqueify', 'setify', 'merge', |
8 | | - 'is_listy', 'range_of', 'groupby', 'last_index', 'shufflish', 'IterLen', 'ReindexCollection', 'num_methods', |
9 | | - 'rnum_methods', 'inum_methods', 'fastuple', 'trace', 'compose', 'maps', 'partialler', 'mapped', |
10 | | - 'instantiate', 'using_attr', 'Self', 'Self', 'open_file', 'save_pickle', 'load_pickle', 'bunzip', |
| 5 | + 'truediv', 'is_', 'is_not', 'in_', 'true', 'gen', 'chunked', 'otherwise', 'AttrDict', 'dict2obj', |
| 6 | + 'with_cast', 'store_attr', 'attrdict', 'properties', 'camel2snake', 'snake2camel', 'class2attr', 'hasattrs', |
| 7 | + 'setattrs', 'ShowPrint', 'Int', 'Str', 'Float', 'tuplify', 'detuplify', 'replicate', 'uniqueify', 'setify', |
| 8 | + 'merge', 'is_listy', 'range_of', 'groupby', 'last_index', 'shufflish', 'IterLen', 'ReindexCollection', |
| 9 | + 'num_methods', 'rnum_methods', 'inum_methods', 'fastuple', 'trace', 'compose', 'maps', 'partialler', |
| 10 | + 'mapped', 'instantiate', 'using_attr', 'Self', 'Self', 'open_file', 'save_pickle', 'load_pickle', 'bunzip', |
11 | 11 | 'join_path_file', 'urlread', 'urljson', 'run', 'do_request', 'sort_by_run', 'PrettyString', 'round_multiple', |
12 | 12 | 'even_mults', 'num_cpus', 'add_props', 'ContextManagers', 'typed', 'set_num_threads', 'ProcessPoolExecutor', |
13 | 13 | 'ThreadPoolExecutor', 'parallel', 'run_procs', 'parallel_gen', 'threaded'] |
@@ -166,6 +166,11 @@ def chunked(it, chunk_sz=None, drop_last=False, n_chunks=None): |
166 | 166 | if res and (len(res)==chunk_sz or not drop_last): yield res |
167 | 167 | if len(res)<chunk_sz: return |
168 | 168 |
|
| 169 | +# Cell |
| 170 | +def otherwise(x, tst, y): |
| 171 | + "`y if tst(x) else x`" |
| 172 | + return y if tst(x) else x |
| 173 | + |
169 | 174 | # Cell |
170 | 175 | class AttrDict(dict): |
171 | 176 | "`dict` subclass that also provides access to keys as attrs" |
|
0 commit comments