Mercurial > hg > ishara
view 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 |
line wrap: on
line source
function o=takewhile(f,source) % takewhile - Take elements of seq while a condition is met. % % takewhile :: (A->bool), seq A -> seq A if nargin==0, o=takewhile(@(e)true,0); elseif isa(source,'takewhile'), o=source; elseif isempty(source), o=[]; elseif ~f(head(source)), o=[]; else ft.datafn=@datafn; ft.stringfn=@stringfn; ft.nextfn=@nextfn; o.f=f; o.x=head(source); o=class(o,'takewhile',ddata(source,size(source),ft)); end function x=datafn(o), x=o.x; function s=stringfn(o), s=sprintf('takewhile(%s)',tostring(o.f)); function o=nextfn(o) o=next_c(o); if ~isempty(o), o.x=headsource(o); if ~o.f(o.x), o=[]; end end