from transducer._util import UNSET
from transducer.infrastructure import Reduced


# Transducible processes

def transduce(transducer, reducer, iterable, init=UNSET):
    r = transducer(reducer)
    accumulator = reducer.initial() if init is UNSET else init
    for item in iterable:
        accumulator = r.step(accumulator, item)
        if isinstance(accumulator, Reduced):
            accumulator = accumulator.value
            break
    return r.complete(accumulator)

from transducer._util import UNSET
from transducer.infrastructure import Reduced


# Transducible processes

def transduce(transducer, reducer, iterable, init=UNSET):
    r = transducer(reducer)
    accumulator = r.initial() if init is UNSET else init
    for item in iterable:
        accumulator = r.step(accumulator, item)
        if isinstance(accumulator, Reduced):
            accumulator = accumulator.value
            break
    return r.complete(accumulator)

Call initial() on the transformed reducer rather than on the 'bottom' reducer.
Call initial() on the transformed reducer rather than on the 'bottom' reducer.
