document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // Definición de una clase Functor en Scala
  2. trait Functor[F[_]] {
  3.   def map[A, B](fa: F[A])(f: A => B): F[B]
  4. }
  5.  
  6. // Implementación de Functor para List
  7. implicit val listFunctor: Functor[List] = new Functor[List] {
  8.   def map[A, B](fa: List[A])(f: A => B): List[B] = fa.map(f)
  9. }
  10.  
  11. // Uso del Functor
  12. val numbers = List(1, 2, 3, 4)
  13. val doubledNumbers = listFunctor.map(numbers)(_ * 2)
  14. println(doubledNumbers) // Salida: List(2, 4, 6, 8)
  15.  
');