implements reduce