mirror of
https://github.com/wader/fq.git
synced 2024-12-26 23:15:04 +03:00
Merge pull request #173 from wader/intepr-finally-improv
interp: Make _finally handle null, call fin once and last
This commit is contained in:
commit
4798917ae3
@ -72,15 +72,22 @@ def _input_decode_errors(f): _global_var("input_decode_errors"; f);
|
|||||||
def _variables: _global_var("variables");
|
def _variables: _global_var("variables");
|
||||||
def _variables(f): _global_var("variables"; f);
|
def _variables(f): _global_var("variables"; f);
|
||||||
|
|
||||||
# eval f and finally eval fin even on empty or error.
|
# eval f and finally eval fin even if empty or error.
|
||||||
# note that if f outputs more than one value fin will be called
|
# _finally(1; debug)
|
||||||
# for each value.
|
# _finally(null; debug)
|
||||||
|
# _finally(error("a"); debug)
|
||||||
|
# _finally(empty; debug)
|
||||||
|
# _finally(1,2,3; debug)
|
||||||
|
# _finally({a:1}; debug)
|
||||||
def _finally(f; fin):
|
def _finally(f; fin):
|
||||||
( try f // (fin | empty)
|
try
|
||||||
catch (fin as $_ | error)
|
( f
|
||||||
| fin as $_
|
, (fin | empty)
|
||||||
| .
|
)
|
||||||
);
|
catch
|
||||||
|
( fin as $_
|
||||||
|
| error
|
||||||
|
);
|
||||||
|
|
||||||
# TODO: figure out a saner way to force int
|
# TODO: figure out a saner way to force int
|
||||||
def _to_int: (. % (. + 1));
|
def _to_int: (. % (. + 1));
|
||||||
|
Loading…
Reference in New Issue
Block a user