def iside(seq, fn):
    """
    Wrap an iterable with side effects, yielding the input unchanged.
    `fn` will be called as `fn(index, item)` for each `item` in `seq`

    E.g.:

        # print to STDERR to avoid buffering
        import sys
        def tell(index, item):
            if index % 100 == 0:
                print >> sys.stderr, index,

        total = 0
        for x in iside(xrange(10000), tell):
            total += sum(range(1, x))
        print 'total', total

    """
    for index, item in enumerate(seq):
        fn(index, item)
        yield item
