Created
July 14, 2014 08:29
-
-
Save kencoba/343e440767c55fc6d222 to your computer and use it in GitHub Desktop.
worksheet of quotient.
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
object quotient { | |
def mkCoset[E](objs: Seq[E], equivalence: (E) => E):Iterable[Seq[E]] = { | |
objs.groupBy(e => equivalence(e)).map(p => p._2) | |
} //> mkCoset: [E](objs: Seq[E], equivalence: E => E)Iterable[Seq[E]] | |
val coset = mkCoset((1 to 5), (e:Int) => e % 3) | |
//> coset : Iterable[Seq[Int]] = List(Vector(2, 5), Vector(1, 4), Vector(3)) | |
val originalSet = coset.flatten //> originalSet : Iterable[Int] = List(2, 5, 1, 4, 3) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment