view sequences/@seq/spanc.m @ 6:0ce3c2070089

Removed duplicate code and fixed doc in timed_action.
author samer
date Mon, 14 Jan 2013 14:33:37 +0000
parents 3f77126f7b5f
children
line wrap: on
line source
function [Y,x]=spanc(f,x)
% spanc - divide sequence using a test function
%
% spanc :: (A->bool), seq(A) -> {[N]->A}, seq(A).
%
% spanc f x = (seq2cell (takeWhile f x),dropWhile f x)
% Will not terminate if head segments turns out to be infinite.
%
% Note: this is like span but returns a cell array for the head sequence

if isempty(x), Y={}; return
else
	Y={};
	y=head(x);
	while f(y)
		Y=horzcat(Y,y);
		x=next(x);
		if isempty(x), break; end
		y=head(x);
	end
end