Implemented `mapWithIndex`

As requested by @samuelgruetter in #372.