Mercurial > hg > ishara
annotate sequences/@seq/spanc.m @ 29:61921dceded1
More documentation on type system.
author | samer |
---|---|
date | Sat, 19 Jan 2013 17:56:21 +0000 |
parents | 3f77126f7b5f |
children |
rev | line source |
---|---|
samer@3 | 1 function [Y,x]=spanc(f,x) |
samer@3 | 2 % spanc - divide sequence using a test function |
samer@3 | 3 % |
samer@3 | 4 % spanc :: (A->bool), seq(A) -> {[N]->A}, seq(A). |
samer@3 | 5 % |
samer@3 | 6 % spanc f x = (seq2cell (takeWhile f x),dropWhile f x) |
samer@3 | 7 % Will not terminate if head segments turns out to be infinite. |
samer@3 | 8 % |
samer@3 | 9 % Note: this is like span but returns a cell array for the head sequence |
samer@3 | 10 |
samer@3 | 11 if isempty(x), Y={}; return |
samer@3 | 12 else |
samer@3 | 13 Y={}; |
samer@3 | 14 y=head(x); |
samer@3 | 15 while f(y) |
samer@3 | 16 Y=horzcat(Y,y); |
samer@3 | 17 x=next(x); |
samer@3 | 18 if isempty(x), break; end |
samer@3 | 19 y=head(x); |
samer@3 | 20 end |
samer@3 | 21 end |
samer@3 | 22 |