annotate sequences/@takewhile/takewhile.m @ 2:7357e1dc2ad6
Simplified scheduler library with new schedule representation.
author |
samer |
date |
Sat, 22 Dec 2012 16:17:51 +0000 |
parents |
672052bd81f8 |
children |
|
rev |
line source |
samer@0
|
1 function o=takewhile(f,source)
|
samer@0
|
2 % takewhile - Take elements of seq while a condition is met.
|
samer@0
|
3 %
|
samer@0
|
4 % takewhile :: (A->bool), seq A -> seq A
|
samer@0
|
5
|
samer@0
|
6 if nargin==0, o=takewhile(@(e)true,0);
|
samer@0
|
7 elseif isa(source,'takewhile'), o=source;
|
samer@0
|
8 elseif isempty(source), o=[];
|
samer@0
|
9 elseif ~f(head(source)), o=[];
|
samer@0
|
10 else
|
samer@0
|
11 ft.datafn=@datafn;
|
samer@0
|
12 ft.stringfn=@stringfn;
|
samer@0
|
13 ft.nextfn=@nextfn;
|
samer@0
|
14 o.f=f;
|
samer@0
|
15 o.x=head(source);
|
samer@0
|
16 o=class(o,'takewhile',ddata(source,size(source),ft));
|
samer@0
|
17 end
|
samer@0
|
18
|
samer@0
|
19 function x=datafn(o), x=o.x;
|
samer@0
|
20 function s=stringfn(o), s=sprintf('takewhile(%s)',tostring(o.f));
|
samer@0
|
21 function o=nextfn(o)
|
samer@0
|
22 o=next_c(o);
|
samer@0
|
23 if ~isempty(o),
|
samer@0
|
24 o.x=headsource(o);
|
samer@0
|
25 if ~o.f(o.x), o=[]; end
|
samer@0
|
26 end
|
samer@0
|
27
|
samer@0
|
28
|
samer@0
|
29
|