What methods are needed to create a custom applicative functor for use with scalaz | @ |

I would like to be able to use scalaz | @ | on my own application functor.

Example:
val spread: Source[Yield] = (y2 |@| y1)(_ - _)

This is my class

sealed abstract class Source[+A] {
  def map[B](f: A => B): Source[B] 
  def unit[A](a: A): Source[A]
  def pureList[A](la: List[A]): Source[A]
  def zero[A]: Source[A]
  def map2[A, B, C](as: Source[A], bs: Source[B], f: (A, B) => C): Source[C]
}

I am sure that I need to implement map, because it is a functor.
An application can be implemented in various ways: for example, using apply()and unit()or map2()and unit().

Do I need apand pure?

As you can see, I'm not sure what is needed.

+4
source share
1 answer
implicit val mya = new Applicative[Source] {}

Let the compiler answer this question:

object creation impossible, since:
it has 2 unimplemented members.
/** As seen from <$anon: scalaz.Applicative[Source]>, the missing signatures are as follows.
 *  For convenience, these are usable as stub implementations.
 */
  // Members declared in scalaz.Applicative
  def point[A](a: => A): Source[A] = ???

  // Members declared in scalaz.Apply
  def ap[A, B](fa: => Source[A])(f: => Source[A => B]): Source[B] = ???
+6

Source: https://habr.com/ru/post/1683752/


All Articles