In addition to map, instances of Functor.Ix also implement a method called
mapWithIndex that will provide to its callback argument an additional parameter, ix.
Note that ix does not have to be a number. If the source data type is a record, ix
would be a string. For a tree, the index might be a path.
The nice thing about separating the "index" logic into a functor is that it clearly delineates
who is responsible for what:
When defining a Functor.Ix instance, it's your responsibility to
keep track of the index
make sure updates to the index are deterministic
provide the index to the caller
define its semantics, and communicate them clearly
Functor.IxA
Functorthat has been equipped with an index.In addition to
map, instances ofFunctor.Ixalso implement a method calledmapWithIndexthat will provide to its callback argument an additional parameter,ix.Note that
ixdoes not have to be a number. If the source data type is a record,ixwould be astring. For a tree, the index might be a path.The nice thing about separating the "index" logic into a functor is that it clearly delineates who is responsible for what:
When defining a
Functor.Ixinstance, it's your responsibility to