annotate 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 |
rev |
line source |
samer@13
|
1 % decorate - Decorate function with pre and post operations and optional pausing
|
samer@13
|
2 %
|
samer@13
|
3 % decorate ::
|
samer@13
|
4 % (A->B{:}) ~'function from 1 argument to any number of returns',
|
samer@13
|
5 % options {
|
samer@13
|
6 % pre :: (A=>void)/@nop ~'action to perform before calling function';
|
samer@13
|
7 % post :: (A=>void)/@nop ~'action to perform after calling function'
|
samer@13
|
8 % }
|
samer@13
|
9 % -> (A->B{:}) ~'new function incorporating pre and post actions'.
|
samer@13
|
10 function f1=decorate(f,varargin)
|
samer@13
|
11 opts=prefs(varargin{:});
|
samer@13
|
12 pf=pauser(opts);
|
samer@13
|
13 if isfield(opts,'pre') || isfield(opts,'post')
|
samer@13
|
14 pre=getparam(opts,'pre',@nop);
|
samer@13
|
15 post=getparam(opts,'post',@nop);
|
samer@13
|
16 f1=@f_bracket;
|
samer@13
|
17 else
|
samer@13
|
18 f1=@f_simple;
|
samer@13
|
19 end
|
samer@13
|
20
|
samer@13
|
21 function x=f_simple(x), x=f(x); pf(); end
|
samer@13
|
22 function x=f_bracket(x), pre(x); x=f(x); post(x); pf(); end
|
samer@13
|
23 end
|