samer@13: % decorate - Decorate function with pre and post operations and optional pausing samer@13: % samer@13: % decorate :: samer@13: % (A->B{:}) ~'function from 1 argument to any number of returns', samer@13: % options { samer@13: % pre :: (A=>void)/@nop ~'action to perform before calling function'; samer@13: % post :: (A=>void)/@nop ~'action to perform after calling function' samer@13: % } samer@13: % -> (A->B{:}) ~'new function incorporating pre and post actions'. samer@13: function f1=decorate(f,varargin) samer@37: opts=options(varargin{:}); samer@13: pf=pauser(opts); samer@13: if isfield(opts,'pre') || isfield(opts,'post') samer@13: pre=getparam(opts,'pre',@nop); samer@13: post=getparam(opts,'post',@nop); samer@13: f1=@f_bracket; samer@13: else samer@13: f1=@f_simple; samer@13: end samer@13: samer@13: function x=f_simple(x), x=f(x); pf(); end samer@13: function x=f_bracket(x), pre(x); x=f(x); post(x); pf(); end samer@13: end