| ScalaZ |
| 1 | package scalaz |
| 2 | //// /** * A [[scalaz.Category]] supporting all ordinary functions, as well as * combining arrows product-wise. Every Arrow forms a * [[scalaz.Contravariant]] in one type parameter, and a * [[scalaz.Applicative]] in the other, just as with ordinary * functions. */ //// trait Arrow[=>:[_, _]] extends Split[=>:] with Strong[=>:] with Category[=>:] { self => //// |
| 3 | /** Lift an ordinary function. */ def arr[A, B](f: A => B): A =>: B |
| 4 | override def covariantInstance[C]: Applicative[C =>: ?] = new Applicative[C =>: ?] with SndCovariant[C] { def point[A](a: => A): C =>: A = arr(_ => a) def ap[A, B](fa: => (C =>: A))(f: => (C =>: (A => B))): (C =>: B) = <<<(arr((y: (A => B, A)) => y._1(y._2)), combine(f, fa)) } |
| 5 | /** Alias for `compose`. */ final def <<<[A, B, C](fbc: (B =>: C), fab: (A =>: B)): =>:[A, C] = compose(fbc, fab) |
| 6 | /** Flipped `<<<`. */ def >>>[A, B, C](fab: (A =>: B), fbc: (B =>: C)): (A =>: C) = compose(fbc, fab) |
| 7 | /** Pass `C` through untouched. */ def second[A, B, C](f: (A =>: B)): ((C, A) =>: (C, B)) = { def swap[X, Y] = arr[(X, Y), (Y, X)] { case (x, y) => (y, x) } |
| 8 | >>>(<<<(first[A, B, C](f), swap), swap) } |
| 9 | /** Alias for `split`. */ final def splitA[A, B, C, D](fab: (A =>: B), fcd: (C =>: D)): ((A, C) =>: (B, D)) = split(fab, fcd) |
| 10 | /** Run `fab` and `fcd` alongside each other. Sometimes `***`. */ def split[A, B, C, D](f: A =>: B, g: C =>: D): ((A, C) =>: (B, D)) = >>>(first[A, B, C](f), second[C, D, B](g)) |
| 11 | /** Run two `fab`s alongside each other. */ def product[A, B](fab: (A =>: B)): ((A, A) =>: (B, B)) = splitA(fab, fab) |
| 12 | /** Run `fab` and `fac` on the same `A`. Sometimes `&&&`. */ def combine[A, B, C](fab: (A =>: B), fac: (A =>: C)): (A =>: (B, C)) = >>>(arr((a: A) => (a, a)), splitA(fab, fac)) |
| 13 | /** Contramap on `A`. */ def mapfst[A, B, C](fab: (A =>: B))(f: C => A): (C =>: B) = >>>[C, A, B](arr(f), fab) |
| 14 | /** Functor map on `B`. */ def mapsnd[A, B, C](fab: (A =>: B))(f: B => C): (A =>: C) = <<<[A, B, C](arr(f), fab) |
| 15 | //// val arrowSyntax = new scalaz.syntax.ArrowSyntax[=>:] { def F = Arrow.this } } |
| 16 | object Arrow { @inline def apply[F[_, _]](implicit F: Arrow[F]): Arrow[F] = F |
| 17 | //// |
| 18 | //// } |
Комментарии