Created
October 17, 2017 09:13
-
-
Save stacycurl/6b46c0bf0d218b1f828b2718b34e5e74 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit def tuple2Semigroup[A, B](implicit A: Semigroup[A], B: Semigroup[B]): Semigroup[(A, B)] = instance[(A, B)] { | |
case ((la, lb), (ra, rb)) => (A.append(la, ra), B.append(lb, rb)) | |
} | |
/** Make an associative binary function into an __Serializable__ instance. */ | |
def instance[A](f: (A, => A) => A): Semigroup[A] = SerializableSemigroup(f) | |
private case class SerializableSemigroup[A](f: (A, => A) => A) extends Semigroup[A] { | |
private val self: Semigroup[A] = this | |
override def append(lhs: A, rhs: => A): A = f(lhs, rhs) | |
override val semigroupSyntax: SSemigroupSyntax[A] = new SSemigroupSyntax[A] with Serializable { | |
def F: Semigroup[A] = self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment