Plugin Directory

Changeset 3432928


Ignore:
Timestamp:
01/05/2026 05:12:48 PM (3 months ago)
Author:
whiteshadow
Message:

Minor: Add foldLeft()

I had some doubts if this should be reduce...() or fold...(), and finally decided to do it the Scala way.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • admin-menu-editor/trunk/includes/ame-collections.php

    r3428599 r3432928  
    181181        }
    182182    }
     183
     184    /**
     185     * @template A Accumulator type
     186     * @template T Collection element type
     187     *
     188     * @param A $accumulator
     189     * @param callable(A,T):A $callback
     190     * @return A
     191     */
     192    public function foldLeft($accumulator, callable $callback) {
     193        foreach ($this->array as $value) {
     194            $accumulator = $callback($accumulator, $value);
     195        }
     196        return $accumulator;
     197    }
    183198}
    184199
Note: See TracChangeset for help on using the changeset viewer.