view sequences/@seq/spanc.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
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