×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Scala
Posted by: osocron coder
Added: Nov 15, 2016 3:39 AM
Views: 11
The most general reverse function I've found so far... there is probably a better way
  1. def reversed[A, F[_]](fa: F[A])
  2.                        (implicit
  3.                         monoid: Monoid[F[A]],
  4.                         monad: Monad[F],
  5.                         foldable: Foldable[F]): F[A] = {
  6.     foldable.foldLeft(fa, monoid.zero)((acc, next) =>
  7.       monoid.append(monad.pure(next), acc))
  8.   }