Mercurial > hg > ishara
diff general/funutils/@function_handle/decorate.m @ 13:03694e5c8365
Reorganised some high order list functions to correct class-based method dispatch; fixed some docs.
author | samer |
---|---|
date | Wed, 16 Jan 2013 12:12:34 +0000 |
parents | |
children | beb8a3f4a345 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/general/funutils/@function_handle/decorate.m Wed Jan 16 12:12:34 2013 +0000 @@ -0,0 +1,23 @@ +% decorate - Decorate function with pre and post operations and optional pausing +% +% decorate :: +% (A->B{:}) ~'function from 1 argument to any number of returns', +% options { +% pre :: (A=>void)/@nop ~'action to perform before calling function'; +% post :: (A=>void)/@nop ~'action to perform after calling function' +% } +% -> (A->B{:}) ~'new function incorporating pre and post actions'. +function f1=decorate(f,varargin) + opts=prefs(varargin{:}); + pf=pauser(opts); + if isfield(opts,'pre') || isfield(opts,'post') + pre=getparam(opts,'pre',@nop); + post=getparam(opts,'post',@nop); + f1=@f_bracket; + else + f1=@f_simple; + end + + function x=f_simple(x), x=f(x); pf(); end + function x=f_bracket(x), pre(x); x=f(x); post(x); pf(); end +end