1 
2 /*******************************************************************************
3  * Breaks
4  * Breaks are pure higher-order functions that evaluate a list up to a certain
5  * point. For convenience, any function dealing with conditional collection of
6  * a list or array is put into Breaks.
7  */
8 
9 module cookbook.ingredients.functional.fbreak;
10 import cookbook.essential.common;
11 
12 pure T[] filterBreak(alias pred,T)(T[] data){
13   T[] ret;
14   for(int i = 0; i < data.length; i++){
15     if(!pred(data[i]))
16       return ret;
17     else
18       ret = append!T(ret,data[i]);
19   }
20   return ret;
21 }
22 
23 pure T[] removeBreak(alias pred,T)(T[] data){
24   for(int i = 0; i < data.length; i++){
25     if(!pred(data[i]))
26       return data[i..$].dup;
27   }
28   return data;
29 }
30 
31 pure bool imbreak(alias pred,T)(T[] data){
32   foreach(item; data)
33     if(!pred(item)) return false;
34   return true;
35 }