You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+122Lines changed: 122 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,8 +61,11 @@ Now use this library's functions on an `Array`, `Iterable`, or `Iterator` and le
61
61
|[`count`](https://github.com/RobertBorghese/Haxe-MagicArrayTools#count)| Counts the number of elements that match the condition |
62
62
|[`find` and `findIndex`](https://github.com/RobertBorghese/Haxe-MagicArrayTools#find-and-findindex)| Finds the first element that matches the condition |
63
63
|[`indexOf`](https://github.com/RobertBorghese/Haxe-MagicArrayTools#indexOf)| Returns the index of the provided element |
64
+
|[`every` and `some`](https://github.com/RobertBorghese/Haxe-MagicArrayTools#every-and-some)| Check if some or all elements match the condition |
65
+
|[`reduce`](https://github.com/RobertBorghese/Haxe-MagicArrayTools#reduce)| Reduce to single value summed together using function |
64
66
|[`asList` and `asVector`](https://github.com/RobertBorghese/Haxe-MagicArrayTools#aslist-and-asvector)| Provides the result as a `haxe.ds.List` or `haxe.ds.Vector`|
65
67
|[`concat`](https://github.com/RobertBorghese/Haxe-MagicArrayTools#concat)| Appends another `Array`, `Iterable`, or even separate for-loop |
68
+
|[`fill`](https://github.com/RobertBorghese/Haxe-MagicArrayTools#fill)| Fill a subsection or the entire `Array` with a value |
`every` returns `true` if every element returns `true` when passed to the provided callback. On the other hand, `some` returns `true` as long as at least one element passes.
383
+
```haxe
384
+
function every(callback: (T) -> Bool): Bool;
385
+
function some(callback: (T) -> Bool): Bool;
386
+
```
387
+
```haxe
388
+
[75, 7, 12, 93].every(_ > 0);
389
+
390
+
// |
391
+
// V
392
+
393
+
{
394
+
var result = true;
395
+
for(it in [75, 7, 12, 93]) {
396
+
if(it <= 0) {
397
+
result = false;
398
+
break;
399
+
}
400
+
}
401
+
result;
402
+
}
403
+
```
404
+
405
+
```haxe
406
+
(1...10).some(_ == 4);
407
+
408
+
// |
409
+
// V
410
+
411
+
{
412
+
var result = false;
413
+
for(it in 1...10) {
414
+
if(it == 4) {
415
+
result = true;
416
+
break;
417
+
}
418
+
}
419
+
result;
420
+
}
421
+
```
422
+
423
+
424
+
425
+
### `reduce`
426
+
427
+
`reduce` calls a function on every element to accumulate all the values. The returned value of the previous call is passed as the first argument; the second argument is the element being iterated on. The returned value of the final call is what `reduce` returns.
428
+
```haxe
429
+
function reduce(callback: (T, T) -> T): T;
430
+
```
431
+
```haxe
432
+
["a", "b", "c", "d"].reduce((a, b) -> a + b);
433
+
434
+
// |
435
+
// V
436
+
437
+
{
438
+
var result = null;
439
+
var _hasFoundValue = false;
440
+
for(it in ["a", "b", "c", "d"]) {
441
+
if(!_hasFoundValue) {
442
+
_hasFoundValue = true;
443
+
result = it;
444
+
} else {
445
+
result = result + it;
446
+
};
447
+
};
448
+
result;
449
+
}
450
+
```
451
+
452
+
453
+
377
454
### `asList` and `asVector`
378
455
379
456
These functions change the resulting data-structure to either be a `haxe.ds.List` or `haxe.ds.Vector`.
0 commit comments