annotate general/funutils/@function_handle/decorate.m @ 61:eff6bddf82e3
tip
Finally implemented perceptual brightness thing.
author |
samer |
date |
Sun, 11 Oct 2015 10:20:42 +0100 |
parents |
beb8a3f4a345 |
children |
|
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@37
|
11 opts=options(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
|