@@ -336,10 +336,10 @@ |
||
| 336 | 336 | // $text = 'foo ("bar baz" alpha) beta' |
| 337 | 337 | $counters = [ |
| 338 | 338 | 'values' => [], // each item of this array refers to the number |
| 339 | - // of closings needed for an opening |
|
| 339 | + // of closings needed for an opening |
|
| 340 | 340 | 'openings' => [], // an associative array where the key is an opening |
| 341 | - // and the value is the index of corresponding cell |
|
| 342 | - // in the 'values' field |
|
| 341 | + // and the value is the index of corresponding cell |
|
| 342 | + // in the 'values' field |
|
| 343 | 343 | 'closings' => [], // associative array for closings like the previous one |
| 344 | 344 | 'total' => 0 // the total number of needed closings |
| 345 | 345 | ]; |
@@ -3,127 +3,127 @@ |
||
| 3 | 3 | use Tarsana\Functional as F; |
| 4 | 4 | |
| 5 | 5 | return F\map(F\apply(F\_f('_stream_operation')), [ |
| 6 | - ['then', 'Function -> Any -> Any', F\_f('_stream_then')], |
|
| 7 | - ['and', 'Boolean -> Boolean -> Boolean', F\and_()], |
|
| 8 | - ['or', 'Boolean -> Boolean -> Boolean', F\or_()], |
|
| 9 | - ['not', 'Boolean -> Boolean', F\not()], |
|
| 10 | - ['eq', 'Any -> Any -> Boolean', F\eq()], |
|
| 11 | - ['notEq', 'Any -> Any -> Boolean', F\notEq()], |
|
| 12 | - ['eqq', 'Any -> Any -> Boolean', F\eqq()], |
|
| 13 | - ['notEqq', 'Any -> Any -> Boolean', F\notEqq()], |
|
| 14 | - ['equals', 'Any -> Any -> Boolean', F\equals()], |
|
| 15 | - ['equalBy', 'Function -> Any -> Any -> Boolean', F\equalBy()], |
|
| 16 | - ['lt', 'Any -> Any -> Boolean', F\lt()], |
|
| 17 | - ['lte', 'Any -> Any -> Boolean', F\lte()], |
|
| 18 | - ['gt', 'Any -> Any -> Boolean', F\gt()], |
|
| 19 | - ['gte', 'Any -> Any -> Boolean', F\gte()], |
|
| 20 | - ['is', 'String -> Any -> Boolean', F\is()], |
|
| 21 | - ['toString', 'Any -> String', F\toString()], |
|
| 22 | - ['attributes', 'Object|Array -> Object|Array', F\attributes()], |
|
| 23 | - ['keys', 'List -> List', F\keys()], |
|
| 24 | - ['keys', 'Object|Array -> List', F\keys()], |
|
| 25 | - ['values', 'List -> List', F\values()], |
|
| 26 | - ['values', 'Object|Array -> List', F\values()], |
|
| 27 | - ['has', 'Any -> Object|Array -> Boolean', F\has()], |
|
| 28 | - ['get', 'Any -> Object|Array -> Any', F\get()], |
|
| 29 | - ['getPath', 'List -> Object|Array -> Any', F\getPath()], |
|
| 30 | - ['set', 'Any -> Any -> Object|Array -> Object|Array', F\set()], |
|
| 31 | - ['update', 'Any -> Function -> Object|Array -> Object|Array', F\update()], |
|
| 32 | - ['satisfies', 'Function -> Any -> Object|Array -> Boolean', F\satisfies()], |
|
| 33 | - ['satisfiesAll', 'Object|Array -> Object|Array -> Boolean', F\satisfiesAll()], |
|
| 34 | - ['satisfiesAny', 'Object|Array -> Object|Array -> Boolean', F\satisfiesAny()], |
|
| 35 | - ['toPairs', 'Object|Array -> List', F\toPairs()], |
|
| 36 | - ['toPairs', 'List -> List', F\toPairs()], |
|
| 37 | - ['split', 'String -> String -> List', F\split()], |
|
| 38 | - ['join', 'String -> List -> String', F\join()], |
|
| 39 | - ['replace', 'String|List -> String|List -> String -> String', F\replace()], |
|
| 40 | - ['regReplace', 'String -> String -> String -> String', F\regReplace()], |
|
| 41 | - ['upperCase', 'String -> String', F\upperCase()], |
|
| 42 | - ['lowerCase', 'String -> String', F\lowerCase()], |
|
| 43 | - ['camelCase', 'String -> String', F\camelCase()], |
|
| 44 | - ['snakeCase', 'String -> String -> String', F\snakeCase()], |
|
| 45 | - ['startsWith', 'String -> String -> Boolean', F\startsWith()], |
|
| 46 | - ['endsWith', 'String -> String -> Boolean', F\endsWith()], |
|
| 47 | - ['test', 'String -> String -> Boolean', F\test()], |
|
| 48 | - ['match', 'String -> String -> List', F\match()], |
|
| 49 | - ['occurences', 'String -> String -> Number', F\occurences()], |
|
| 50 | - ['chunks', 'String -> String -> String -> List', F\chunks()], |
|
| 51 | - ['map', 'Function -> List -> List', F\map()], |
|
| 52 | - ['map', 'Function -> Object|Array -> Object|Array', F\map()], |
|
| 53 | - ['chain', 'Function -> List -> List', F\chain()], |
|
| 54 | - ['filter', 'Function -> List -> List', F\filter()], |
|
| 55 | - ['reduce', 'Function -> Any -> List -> Any', F\reduce()], |
|
| 56 | - ['each', 'Function -> List -> List', F\each()], |
|
| 57 | - ['head', 'List -> Any', F\head()], |
|
| 58 | - ['head', 'String -> String', F\head()], |
|
| 59 | - ['last', 'List -> Any', F\last()], |
|
| 60 | - ['last', 'String -> String', F\last()], |
|
| 61 | - ['init', 'List -> Any', F\init()], |
|
| 62 | - ['init', 'String -> String', F\init()], |
|
| 63 | - ['tail', 'List -> Any', F\tail()], |
|
| 64 | - ['tail', 'String -> String', F\tail()], |
|
| 65 | - ['reverse', 'List -> List', F\reverse()], |
|
| 66 | - ['reverse', 'String -> String', F\reverse()], |
|
| 67 | - ['length', 'List -> Number', F\length()], |
|
| 68 | - ['length', 'String -> Number', F\length()], |
|
| 69 | - ['allSatisfies', 'Function -> List -> Boolean', F\allSatisfies()], |
|
| 70 | - ['anySatisfies', 'Function -> List -> Boolean', F\anySatisfies()], |
|
| 71 | - ['concat', 'List -> List -> List', F\concat()], |
|
| 72 | - ['concat', 'String -> String -> String', F\concat()], |
|
| 73 | - ['concatAll', 'List -> List', F\concatAll()], |
|
| 74 | - ['insert', 'Number -> Any -> List -> List', F\insert()], |
|
| 75 | - ['insert', 'Number -> String -> String -> String', F\insert()], |
|
| 76 | - ['insertAll', 'Number -> List -> List -> List', F\insertAll()], |
|
| 77 | - ['insertAll', 'Number -> String -> String -> String', F\insertAll()], |
|
| 78 | - ['append', 'Any -> List -> List', F\append()], |
|
| 79 | - ['append', 'String -> String -> String', F\append()], |
|
| 80 | - ['prepend', 'Any -> List -> List', F\prepend()], |
|
| 81 | - ['prepend', 'String -> String -> String', F\prepend()], |
|
| 82 | - ['take', 'Number -> List -> List', F\take()], |
|
| 83 | - ['take', 'Number -> String -> String', F\take()], |
|
| 84 | - ['takeWhile', 'Function -> List -> List', F\takeWhile()], |
|
| 85 | - ['takeLastWhile', 'Function -> List -> List', F\takeLastWhile()], |
|
| 86 | - ['takeUntil', 'Function -> List -> List', F\takeUntil()], |
|
| 87 | - ['takeLastUntil', 'Function -> List -> List', F\takeLastUntil()], |
|
| 88 | - ['remove', 'Number -> List -> List', F\remove()], |
|
| 89 | - ['remove', 'Number -> String -> String', F\remove()], |
|
| 90 | - ['removeWhile', 'Function -> List -> List', F\removeWhile()], |
|
| 91 | - ['removeLastWhile', 'Function -> List -> List', F\removeLastWhile()], |
|
| 92 | - ['removeUntil', 'Function -> List -> List', F\removeUntil()], |
|
| 93 | - ['removeLastUntil', 'Function -> List -> List', F\removeLastUntil()], |
|
| 94 | - ['fromPairs', 'List -> Object|Array', F\fromPairs()], |
|
| 95 | - ['slices', 'Number -> List -> List', F\slices()], |
|
| 96 | - ['slices', 'Number -> String -> List', F\slices()], |
|
| 97 | - ['contains', 'Any -> List -> Boolean', F\contains()], |
|
| 98 | - ['contains', 'String -> String -> Boolean', F\contains()], |
|
| 99 | - ['findIndex', 'Function -> List -> Number|Null', F\findIndex()], |
|
| 100 | - ['findIndex', 'Function -> Object|Array -> Any', F\findIndex()], |
|
| 101 | - ['findLastIndex', 'Function -> List -> Number|Null', F\findLastIndex()], |
|
| 102 | - ['findLastIndex', 'Function -> Object|Array -> Any', F\findLastIndex()], |
|
| 103 | - ['find', 'Function -> List -> Any', F\find()], |
|
| 104 | - ['findLast', 'Function -> List -> Any', F\findLast()], |
|
| 105 | - ['indexOf', 'Any -> List -> Number', F\indexOf()], |
|
| 106 | - ['indexOf', 'Any -> Object|Array -> Any', F\indexOf()], |
|
| 107 | - ['indexOf', 'String -> String -> Number', F\indexOf()], |
|
| 108 | - ['lastIndexOf', 'Any -> List -> Number', F\lastIndexOf()], |
|
| 109 | - ['lastIndexOf', 'Any -> Object|Array -> Any', F\lastIndexOf()], |
|
| 110 | - ['lastIndexOf', 'String -> String -> Number', F\lastIndexOf()], |
|
| 111 | - ['uniqueBy', 'Function -> List -> List', F\uniqueBy()], |
|
| 112 | - ['unique', 'List -> List', F\unique()], |
|
| 113 | - ['groupBy', 'Function -> List -> Object|Array', F\groupBy()], |
|
| 114 | - ['pairsFrom', 'List -> List -> List', F\pairsFrom()], |
|
| 115 | - ['sort', 'Function -> List -> List', F\sort()], |
|
| 116 | - ['plus', 'Number -> Number -> Number', F\plus()], |
|
| 117 | - ['minus', 'Number -> Number -> Number', F\minus()], |
|
| 118 | - ['negate', 'Number -> Number', F\negate()], |
|
| 119 | - ['multiply', 'Number -> Number -> Number', F\multiply()], |
|
| 120 | - ['divide', 'Number -> Number -> Number', F\divide()], |
|
| 121 | - ['modulo', 'Number -> Number -> Number', F\modulo()], |
|
| 122 | - ['sum', 'List -> Number', F\sum()], |
|
| 123 | - ['product', 'List -> Number', F\product()], |
|
| 124 | - ['min', 'Number -> Number -> Number', F\min()], |
|
| 125 | - ['minBy', 'Function -> Any -> Any -> Any', F\minBy()], |
|
| 126 | - ['max', 'Number -> Number -> Number', F\max()], |
|
| 127 | - ['maxBy', 'Function -> Any -> Any -> Any', F\maxBy()], |
|
| 6 | + ['then', 'Function -> Any -> Any', F\_f('_stream_then')], |
|
| 7 | + ['and', 'Boolean -> Boolean -> Boolean', F\and_()], |
|
| 8 | + ['or', 'Boolean -> Boolean -> Boolean', F\or_()], |
|
| 9 | + ['not', 'Boolean -> Boolean', F\not()], |
|
| 10 | + ['eq', 'Any -> Any -> Boolean', F\eq()], |
|
| 11 | + ['notEq', 'Any -> Any -> Boolean', F\notEq()], |
|
| 12 | + ['eqq', 'Any -> Any -> Boolean', F\eqq()], |
|
| 13 | + ['notEqq', 'Any -> Any -> Boolean', F\notEqq()], |
|
| 14 | + ['equals', 'Any -> Any -> Boolean', F\equals()], |
|
| 15 | + ['equalBy', 'Function -> Any -> Any -> Boolean', F\equalBy()], |
|
| 16 | + ['lt', 'Any -> Any -> Boolean', F\lt()], |
|
| 17 | + ['lte', 'Any -> Any -> Boolean', F\lte()], |
|
| 18 | + ['gt', 'Any -> Any -> Boolean', F\gt()], |
|
| 19 | + ['gte', 'Any -> Any -> Boolean', F\gte()], |
|
| 20 | + ['is', 'String -> Any -> Boolean', F\is()], |
|
| 21 | + ['toString', 'Any -> String', F\toString()], |
|
| 22 | + ['attributes', 'Object|Array -> Object|Array', F\attributes()], |
|
| 23 | + ['keys', 'List -> List', F\keys()], |
|
| 24 | + ['keys', 'Object|Array -> List', F\keys()], |
|
| 25 | + ['values', 'List -> List', F\values()], |
|
| 26 | + ['values', 'Object|Array -> List', F\values()], |
|
| 27 | + ['has', 'Any -> Object|Array -> Boolean', F\has()], |
|
| 28 | + ['get', 'Any -> Object|Array -> Any', F\get()], |
|
| 29 | + ['getPath', 'List -> Object|Array -> Any', F\getPath()], |
|
| 30 | + ['set', 'Any -> Any -> Object|Array -> Object|Array', F\set()], |
|
| 31 | + ['update', 'Any -> Function -> Object|Array -> Object|Array', F\update()], |
|
| 32 | + ['satisfies', 'Function -> Any -> Object|Array -> Boolean', F\satisfies()], |
|
| 33 | + ['satisfiesAll', 'Object|Array -> Object|Array -> Boolean', F\satisfiesAll()], |
|
| 34 | + ['satisfiesAny', 'Object|Array -> Object|Array -> Boolean', F\satisfiesAny()], |
|
| 35 | + ['toPairs', 'Object|Array -> List', F\toPairs()], |
|
| 36 | + ['toPairs', 'List -> List', F\toPairs()], |
|
| 37 | + ['split', 'String -> String -> List', F\split()], |
|
| 38 | + ['join', 'String -> List -> String', F\join()], |
|
| 39 | + ['replace', 'String|List -> String|List -> String -> String', F\replace()], |
|
| 40 | + ['regReplace', 'String -> String -> String -> String', F\regReplace()], |
|
| 41 | + ['upperCase', 'String -> String', F\upperCase()], |
|
| 42 | + ['lowerCase', 'String -> String', F\lowerCase()], |
|
| 43 | + ['camelCase', 'String -> String', F\camelCase()], |
|
| 44 | + ['snakeCase', 'String -> String -> String', F\snakeCase()], |
|
| 45 | + ['startsWith', 'String -> String -> Boolean', F\startsWith()], |
|
| 46 | + ['endsWith', 'String -> String -> Boolean', F\endsWith()], |
|
| 47 | + ['test', 'String -> String -> Boolean', F\test()], |
|
| 48 | + ['match', 'String -> String -> List', F\match()], |
|
| 49 | + ['occurences', 'String -> String -> Number', F\occurences()], |
|
| 50 | + ['chunks', 'String -> String -> String -> List', F\chunks()], |
|
| 51 | + ['map', 'Function -> List -> List', F\map()], |
|
| 52 | + ['map', 'Function -> Object|Array -> Object|Array', F\map()], |
|
| 53 | + ['chain', 'Function -> List -> List', F\chain()], |
|
| 54 | + ['filter', 'Function -> List -> List', F\filter()], |
|
| 55 | + ['reduce', 'Function -> Any -> List -> Any', F\reduce()], |
|
| 56 | + ['each', 'Function -> List -> List', F\each()], |
|
| 57 | + ['head', 'List -> Any', F\head()], |
|
| 58 | + ['head', 'String -> String', F\head()], |
|
| 59 | + ['last', 'List -> Any', F\last()], |
|
| 60 | + ['last', 'String -> String', F\last()], |
|
| 61 | + ['init', 'List -> Any', F\init()], |
|
| 62 | + ['init', 'String -> String', F\init()], |
|
| 63 | + ['tail', 'List -> Any', F\tail()], |
|
| 64 | + ['tail', 'String -> String', F\tail()], |
|
| 65 | + ['reverse', 'List -> List', F\reverse()], |
|
| 66 | + ['reverse', 'String -> String', F\reverse()], |
|
| 67 | + ['length', 'List -> Number', F\length()], |
|
| 68 | + ['length', 'String -> Number', F\length()], |
|
| 69 | + ['allSatisfies', 'Function -> List -> Boolean', F\allSatisfies()], |
|
| 70 | + ['anySatisfies', 'Function -> List -> Boolean', F\anySatisfies()], |
|
| 71 | + ['concat', 'List -> List -> List', F\concat()], |
|
| 72 | + ['concat', 'String -> String -> String', F\concat()], |
|
| 73 | + ['concatAll', 'List -> List', F\concatAll()], |
|
| 74 | + ['insert', 'Number -> Any -> List -> List', F\insert()], |
|
| 75 | + ['insert', 'Number -> String -> String -> String', F\insert()], |
|
| 76 | + ['insertAll', 'Number -> List -> List -> List', F\insertAll()], |
|
| 77 | + ['insertAll', 'Number -> String -> String -> String', F\insertAll()], |
|
| 78 | + ['append', 'Any -> List -> List', F\append()], |
|
| 79 | + ['append', 'String -> String -> String', F\append()], |
|
| 80 | + ['prepend', 'Any -> List -> List', F\prepend()], |
|
| 81 | + ['prepend', 'String -> String -> String', F\prepend()], |
|
| 82 | + ['take', 'Number -> List -> List', F\take()], |
|
| 83 | + ['take', 'Number -> String -> String', F\take()], |
|
| 84 | + ['takeWhile', 'Function -> List -> List', F\takeWhile()], |
|
| 85 | + ['takeLastWhile', 'Function -> List -> List', F\takeLastWhile()], |
|
| 86 | + ['takeUntil', 'Function -> List -> List', F\takeUntil()], |
|
| 87 | + ['takeLastUntil', 'Function -> List -> List', F\takeLastUntil()], |
|
| 88 | + ['remove', 'Number -> List -> List', F\remove()], |
|
| 89 | + ['remove', 'Number -> String -> String', F\remove()], |
|
| 90 | + ['removeWhile', 'Function -> List -> List', F\removeWhile()], |
|
| 91 | + ['removeLastWhile', 'Function -> List -> List', F\removeLastWhile()], |
|
| 92 | + ['removeUntil', 'Function -> List -> List', F\removeUntil()], |
|
| 93 | + ['removeLastUntil', 'Function -> List -> List', F\removeLastUntil()], |
|
| 94 | + ['fromPairs', 'List -> Object|Array', F\fromPairs()], |
|
| 95 | + ['slices', 'Number -> List -> List', F\slices()], |
|
| 96 | + ['slices', 'Number -> String -> List', F\slices()], |
|
| 97 | + ['contains', 'Any -> List -> Boolean', F\contains()], |
|
| 98 | + ['contains', 'String -> String -> Boolean', F\contains()], |
|
| 99 | + ['findIndex', 'Function -> List -> Number|Null', F\findIndex()], |
|
| 100 | + ['findIndex', 'Function -> Object|Array -> Any', F\findIndex()], |
|
| 101 | + ['findLastIndex', 'Function -> List -> Number|Null', F\findLastIndex()], |
|
| 102 | + ['findLastIndex', 'Function -> Object|Array -> Any', F\findLastIndex()], |
|
| 103 | + ['find', 'Function -> List -> Any', F\find()], |
|
| 104 | + ['findLast', 'Function -> List -> Any', F\findLast()], |
|
| 105 | + ['indexOf', 'Any -> List -> Number', F\indexOf()], |
|
| 106 | + ['indexOf', 'Any -> Object|Array -> Any', F\indexOf()], |
|
| 107 | + ['indexOf', 'String -> String -> Number', F\indexOf()], |
|
| 108 | + ['lastIndexOf', 'Any -> List -> Number', F\lastIndexOf()], |
|
| 109 | + ['lastIndexOf', 'Any -> Object|Array -> Any', F\lastIndexOf()], |
|
| 110 | + ['lastIndexOf', 'String -> String -> Number', F\lastIndexOf()], |
|
| 111 | + ['uniqueBy', 'Function -> List -> List', F\uniqueBy()], |
|
| 112 | + ['unique', 'List -> List', F\unique()], |
|
| 113 | + ['groupBy', 'Function -> List -> Object|Array', F\groupBy()], |
|
| 114 | + ['pairsFrom', 'List -> List -> List', F\pairsFrom()], |
|
| 115 | + ['sort', 'Function -> List -> List', F\sort()], |
|
| 116 | + ['plus', 'Number -> Number -> Number', F\plus()], |
|
| 117 | + ['minus', 'Number -> Number -> Number', F\minus()], |
|
| 118 | + ['negate', 'Number -> Number', F\negate()], |
|
| 119 | + ['multiply', 'Number -> Number -> Number', F\multiply()], |
|
| 120 | + ['divide', 'Number -> Number -> Number', F\divide()], |
|
| 121 | + ['modulo', 'Number -> Number -> Number', F\modulo()], |
|
| 122 | + ['sum', 'List -> Number', F\sum()], |
|
| 123 | + ['product', 'List -> Number', F\product()], |
|
| 124 | + ['min', 'Number -> Number -> Number', F\min()], |
|
| 125 | + ['minBy', 'Function -> Any -> Any -> Any', F\minBy()], |
|
| 126 | + ['max', 'Number -> Number -> Number', F\max()], |
|
| 127 | + ['maxBy', 'Function -> Any -> Any -> Any', F\maxBy()], |
|
| 128 | 128 | |
| 129 | 129 | ]); |
@@ -314,11 +314,11 @@ |
||
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | function _iterable_reduce(callable $reducer, $acc, \Iterator $iterator) { |
| 317 | - $iterator->rewind(); |
|
| 318 | - while ($iterator->valid()) { |
|
| 319 | - $acc = $reducer($acc, $iterator->current(), $iterator->key()); |
|
| 320 | - $iterator->next(); |
|
| 321 | - } |
|
| 322 | - return $acc; |
|
| 317 | + $iterator->rewind(); |
|
| 318 | + while ($iterator->valid()) { |
|
| 319 | + $acc = $reducer($acc, $iterator->current(), $iterator->key()); |
|
| 320 | + $iterator->next(); |
|
| 321 | + } |
|
| 322 | + return $acc; |
|
| 323 | 323 | } |
| 324 | 324 | |
@@ -13,66 +13,66 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class _IteratorAdapter implements \Iterator |
| 15 | 15 | { |
| 16 | - private $objectStorage; |
|
| 16 | + private $objectStorage; |
|
| 17 | 17 | |
| 18 | - public function __construct(\SplObjectStorage $theObjectStorage) |
|
| 19 | - { |
|
| 20 | - $this->objectStorage = $theObjectStorage; |
|
| 21 | - } |
|
| 18 | + public function __construct(\SplObjectStorage $theObjectStorage) |
|
| 19 | + { |
|
| 20 | + $this->objectStorage = $theObjectStorage; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Return the current element |
|
| 25 | - * @link http://php.net/manual/en/iterator.current.php |
|
| 26 | - * @return mixed Can return any type. |
|
| 27 | - * @since 5.0.0 |
|
| 28 | - */ |
|
| 29 | - public function current() |
|
| 30 | - { |
|
| 31 | - return $this->objectStorage->getInfo(); |
|
| 32 | - } |
|
| 23 | + /** |
|
| 24 | + * Return the current element |
|
| 25 | + * @link http://php.net/manual/en/iterator.current.php |
|
| 26 | + * @return mixed Can return any type. |
|
| 27 | + * @since 5.0.0 |
|
| 28 | + */ |
|
| 29 | + public function current() |
|
| 30 | + { |
|
| 31 | + return $this->objectStorage->getInfo(); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Move forward to next element |
|
| 36 | - * @link http://php.net/manual/en/iterator.next.php |
|
| 37 | - * @return void Any returned value is ignored. |
|
| 38 | - * @since 5.0.0 |
|
| 39 | - */ |
|
| 40 | - public function next() |
|
| 41 | - { |
|
| 42 | - return $this->objectStorage->next(); |
|
| 43 | - } |
|
| 34 | + /** |
|
| 35 | + * Move forward to next element |
|
| 36 | + * @link http://php.net/manual/en/iterator.next.php |
|
| 37 | + * @return void Any returned value is ignored. |
|
| 38 | + * @since 5.0.0 |
|
| 39 | + */ |
|
| 40 | + public function next() |
|
| 41 | + { |
|
| 42 | + return $this->objectStorage->next(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Return the key of the current element |
|
| 47 | - * @link http://php.net/manual/en/iterator.key.php |
|
| 48 | - * @return mixed scalar on success, or null on failure. |
|
| 49 | - * @since 5.0.0 |
|
| 50 | - */ |
|
| 51 | - public function key() |
|
| 52 | - { |
|
| 53 | - return $this->objectStorage->current(); |
|
| 54 | - } |
|
| 45 | + /** |
|
| 46 | + * Return the key of the current element |
|
| 47 | + * @link http://php.net/manual/en/iterator.key.php |
|
| 48 | + * @return mixed scalar on success, or null on failure. |
|
| 49 | + * @since 5.0.0 |
|
| 50 | + */ |
|
| 51 | + public function key() |
|
| 52 | + { |
|
| 53 | + return $this->objectStorage->current(); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Checks if current position is valid |
|
| 58 | - * @link http://php.net/manual/en/iterator.valid.php |
|
| 59 | - * @return boolean The return value will be casted to boolean and then evaluated. |
|
| 60 | - * Returns true on success or false on failure. |
|
| 61 | - * @since 5.0.0 |
|
| 62 | - */ |
|
| 63 | - public function valid() |
|
| 64 | - { |
|
| 65 | - return $this->objectStorage->valid(); |
|
| 66 | - } |
|
| 56 | + /** |
|
| 57 | + * Checks if current position is valid |
|
| 58 | + * @link http://php.net/manual/en/iterator.valid.php |
|
| 59 | + * @return boolean The return value will be casted to boolean and then evaluated. |
|
| 60 | + * Returns true on success or false on failure. |
|
| 61 | + * @since 5.0.0 |
|
| 62 | + */ |
|
| 63 | + public function valid() |
|
| 64 | + { |
|
| 65 | + return $this->objectStorage->valid(); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Rewind the Iterator to the first element |
|
| 70 | - * @link http://php.net/manual/en/iterator.rewind.php |
|
| 71 | - * @return void Any returned value is ignored. |
|
| 72 | - * @since 5.0.0 |
|
| 73 | - */ |
|
| 74 | - public function rewind() |
|
| 75 | - { |
|
| 76 | - return $this->objectStorage->rewind(); |
|
| 77 | - } |
|
| 68 | + /** |
|
| 69 | + * Rewind the Iterator to the first element |
|
| 70 | + * @link http://php.net/manual/en/iterator.rewind.php |
|
| 71 | + * @return void Any returned value is ignored. |
|
| 72 | + * @since 5.0.0 |
|
| 73 | + */ |
|
| 74 | + public function rewind() |
|
| 75 | + { |
|
| 76 | + return $this->objectStorage->rewind(); |
|
| 77 | + } |
|
| 78 | 78 | } |
| 79 | 79 | \ No newline at end of file |
@@ -73,35 +73,35 @@ discard block |
||
| 73 | 73 | function filter() { |
| 74 | 74 | static $filter = false; |
| 75 | 75 | $filter = $filter ?: curry(function(callable $fn, $list) { |
| 76 | - $isArray = is_array($list); |
|
| 77 | - $isObjectStorage = $list instanceof \SplObjectStorage; |
|
| 76 | + $isArray = is_array($list); |
|
| 77 | + $isObjectStorage = $list instanceof \SplObjectStorage; |
|
| 78 | 78 | |
| 79 | - $result = $isArray ? [] |
|
| 80 | - : ($isObjectStorage ? new \SplObjectStorage() |
|
| 81 | - : new \ArrayObject()); |
|
| 79 | + $result = $isArray ? [] |
|
| 80 | + : ($isObjectStorage ? new \SplObjectStorage() |
|
| 81 | + : new \ArrayObject()); |
|
| 82 | 82 | |
| 83 | - if ($isArray) |
|
| 84 | - { |
|
| 85 | - foreach ($list as $item) { |
|
| 86 | - if ($fn($item)) |
|
| 87 | - $result[] = $item; |
|
| 88 | - } |
|
| 89 | - return $result; |
|
| 90 | - } |
|
| 83 | + if ($isArray) |
|
| 84 | + { |
|
| 85 | + foreach ($list as $item) { |
|
| 86 | + if ($fn($item)) |
|
| 87 | + $result[] = $item; |
|
| 88 | + } |
|
| 89 | + return $result; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - return _iterable_reduce( |
|
| 93 | - _make_filterer($isObjectStorage ? |
|
| 94 | - function(\ArrayAccess $xs, $value) { |
|
| 95 | - $xs->offsetSet($value); |
|
| 96 | - } : |
|
| 97 | - function(\ArrayObject $xs, $value) { |
|
| 98 | - $xs->append($value); |
|
| 99 | - }, |
|
| 100 | - $fn |
|
| 101 | - ), |
|
| 102 | - $result, |
|
| 103 | - $isObjectStorage ? $list : $list->getIterator() |
|
| 104 | - ); |
|
| 92 | + return _iterable_reduce( |
|
| 93 | + _make_filterer($isObjectStorage ? |
|
| 94 | + function(\ArrayAccess $xs, $value) { |
|
| 95 | + $xs->offsetSet($value); |
|
| 96 | + } : |
|
| 97 | + function(\ArrayObject $xs, $value) { |
|
| 98 | + $xs->append($value); |
|
| 99 | + }, |
|
| 100 | + $fn |
|
| 101 | + ), |
|
| 102 | + $result, |
|
| 103 | + $isObjectStorage ? $list : $list->getIterator() |
|
| 104 | + ); |
|
| 105 | 105 | }); |
| 106 | 106 | return _apply($filter, func_get_args()); |
| 107 | 107 | } |
@@ -113,12 +113,12 @@ discard block |
||
| 113 | 113 | * @return \Closure |
| 114 | 114 | */ |
| 115 | 115 | function _make_filterer (callable $append, callable $predicate) { |
| 116 | - return function ($acc, ...$entry) use ($append, $predicate) { |
|
| 117 | - if ($predicate($entry[0])) { |
|
| 118 | - $append($acc, ...$entry); |
|
| 119 | - } |
|
| 120 | - return $acc; |
|
| 121 | - }; |
|
| 116 | + return function ($acc, ...$entry) use ($append, $predicate) { |
|
| 117 | + if ($predicate($entry[0])) { |
|
| 118 | + $append($acc, ...$entry); |
|
| 119 | + } |
|
| 120 | + return $acc; |
|
| 121 | + }; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -155,30 +155,30 @@ discard block |
||
| 155 | 155 | * @return array|\ArrayObject|\SplObjectStorage|callable |
| 156 | 156 | */ |
| 157 | 157 | function filter_values() { |
| 158 | - static $filter_values = false; |
|
| 158 | + static $filter_values = false; |
|
| 159 | 159 | $filter_values = $filter_values ?: curry(function(callable $predicate, $list) { |
| 160 | - $isArray = is_array($list); |
|
| 161 | - $isObjectStorage = $list instanceof \SplObjectStorage; |
|
| 160 | + $isArray = is_array($list); |
|
| 161 | + $isObjectStorage = $list instanceof \SplObjectStorage; |
|
| 162 | 162 | |
| 163 | - $result = $isArray ? [] |
|
| 164 | - : ($isObjectStorage ? new \SplObjectStorage() |
|
| 165 | - : new \ArrayObject()); |
|
| 163 | + $result = $isArray ? [] |
|
| 164 | + : ($isObjectStorage ? new \SplObjectStorage() |
|
| 165 | + : new \ArrayObject()); |
|
| 166 | 166 | |
| 167 | - return _iterable_reduce( |
|
| 168 | - _make_filterer($isArray ? |
|
| 169 | - function(array &$xs, $value, $key) { |
|
| 170 | - $xs[$key] = $value; |
|
| 171 | - } : |
|
| 172 | - function(\ArrayAccess $xs, $value, $key) { |
|
| 173 | - $xs->offsetSet($key, $value); |
|
| 174 | - }, |
|
| 175 | - $predicate |
|
| 176 | - ), |
|
| 177 | - $result, |
|
| 178 | - $isArray ? new \ArrayIterator($list) |
|
| 179 | - : ($isObjectStorage ? new _IteratorAdapter($list) |
|
| 180 | - : $list->getIterator()) |
|
| 181 | - ); |
|
| 167 | + return _iterable_reduce( |
|
| 168 | + _make_filterer($isArray ? |
|
| 169 | + function(array &$xs, $value, $key) { |
|
| 170 | + $xs[$key] = $value; |
|
| 171 | + } : |
|
| 172 | + function(\ArrayAccess $xs, $value, $key) { |
|
| 173 | + $xs->offsetSet($key, $value); |
|
| 174 | + }, |
|
| 175 | + $predicate |
|
| 176 | + ), |
|
| 177 | + $result, |
|
| 178 | + $isArray ? new \ArrayIterator($list) |
|
| 179 | + : ($isObjectStorage ? new _IteratorAdapter($list) |
|
| 180 | + : $list->getIterator()) |
|
| 181 | + ); |
|
| 182 | 182 | }); |
| 183 | 183 | return _apply($filter_values, func_get_args()); |
| 184 | 184 | } |