annotate sequences/+seq/binder.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents 9e7be347b3a0
children
rev   line source
samer@36 1 % binder - sort of monadic bind for sequences.
samer@3 2 %
samer@36 3 % binder ::
samer@3 4 % seq(A) ~ 'the first sequence',
samer@3 5 % (A->seq(A)) ~ 'function to return second sequence given last element of first'
samer@3 6 % -> seq(A) ~ 'resultant sequence'.
samer@3 7 %
samer@3 8 % The resulting sequence consists of the entire sequence represented by the
samer@3 9 % first parameter, followed by the sequence obtained by applying the second
samer@23 10 % parameter to the last element of the first sequence.
samer@3 11 %
samer@3 12 % Example:
samer@3 13 %
samer@3 14 % gather(2,bindcat(cellseq({1,2,3,4}),@(x)take(head(x),0)))
samer@3 15 %
samer@3 16 % ans = 1 2 3 4 0 0 0 0
samer@36 17 classdef binder < seq
samer@3 18 properties (GetAccess=private, SetAccess=private)
samer@3 19 source
samer@3 20 nfn
samer@3 21 x
samer@3 22 end
samer@3 23 methods
samer@36 24 function o=binder(X,F)
samer@3 25 o.source=X;
samer@3 26 o.nfn=F;
samer@3 27 o.x=head(X);
samer@3 28 end
samer@3 29
samer@3 30 function z=elsize(o), z=size(o.x); end
samer@3 31 function s=tostring(o), s=sprintf('%s >>= %s',tostring(o.source),tostring(o.nfn)); end
samer@3 32 function x=head(o), x=o.x; end
samer@3 33 function o=next(o),
samer@3 34 o.source=next(o.source);
samer@3 35 if isempty(o.source), o=o.nfn(o.x);
samer@3 36 else o.x=head(o.source);
samer@3 37 end
samer@3 38 end
samer@3 39 end
samer@3 40 end