I am wondering if there is a typeclass
in Cats or Scalaz which offers an operator like this:
def scan[G[_],A,B](zero: B)(g: G[A],f: (A,B) => B):G[B]
Or if there exists some mathematical definition for such operator (something like Monad
for bind/flatMap
).
The idea of this typeclass
would be apply a binary function to a type constructor and obtain back the same type constructor but with a different type parameter (the same type that binary function returns).
I think would be similar to scanLeft
of Scala Standard Library collections.
scan
on collection-like types. But can we generalize this? – AlleywayG[_]
) could be a Monad/Functor like.. thescan
itself can be implemented in terms offlatMap/map
with an state in the method maybe. My thinking is something similar to Elm'sfoldp
. Sorry for the late response. – Picador