@@ -1607,23 +1607,34 @@ limitations under the License.
1607
1607
std.filter (function (i) arr[i] == value, std.range (0 , std.length (arr) - 1 )),
1608
1608
1609
1609
all(arr)::
1610
- if !std.isArray (arr) then
1611
- error 'all() parameter should be an array, got ' + std.type (arr)
1612
- else
1613
- local and = function (x, y)
1614
- if !std.isBoolean (y) then
1615
- error std.format ('element "%s" of type %s is not a boolean' , y, std.type (y))
1616
- else x && y;
1617
- std.foldl (and, arr, true ),
1610
+ assert std.isArray (arr) : 'all() parameter should be an array, got ' + std.type (arr);
1611
+ local arrLen = std.length (arr);
1612
+ local aux(idx) =
1613
+ if idx >= arrLen then
1614
+ true
1615
+ else
1616
+ local e = arr[idx];
1617
+ assert std.isBoolean (e) : std.format ('element "%s" of type %s is not a boolean' , e, std.type (e));
1618
+ if !e then
1619
+ false
1620
+ else
1621
+ aux(idx + 1 ) tailstrict ;
1622
+ aux(0 ),
1623
+
1618
1624
any(arr)::
1619
- if !std.isArray (arr) then
1620
- error 'any() parameter should be an array, got ' + std.type (arr)
1621
- else
1622
- local or = function (x, y)
1623
- if !std.isBoolean (y) then
1624
- error std.format ('element "%s" of type %s is not a boolean' , y, std.type (y))
1625
- else x || y;
1626
- std.foldl (or, arr, false ),
1625
+ assert std.isArray (arr) : 'any() parameter should be an array, got ' + std.type (arr);
1626
+ local arrLen = std.length (arr);
1627
+ local aux(idx) =
1628
+ if idx >= arrLen then
1629
+ false
1630
+ else
1631
+ local e = arr[idx];
1632
+ assert std.isBoolean (e) : std.format ('element "%s" of type %s is not a boolean' , e, std.type (e));
1633
+ if e then
1634
+ true
1635
+ else
1636
+ aux(idx + 1 ) tailstrict ;
1637
+ aux(0 ),
1627
1638
1628
1639
// Three way comparison.
1629
1640
// TODO(sbarzowski): consider exposing and documenting it properly
0 commit comments