1 /*
2 
3 Copyright 2018 Sebastian B. Galkin
4 
5 This file is part of paraseba/scaladores-may-2018-talk.
6 
7 paraseba/scaladores-may-2018-talk is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 paraseba/scaladores-may-2018-talk is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
19 
20 */
21 
22 package monoid.monoids
23 
24 import scala.collection.immutable._
25 import scala.collection.parallel.TaskSupport
26 
27 trait Semigroup[M] {
28 
29   def append(a: M, b: => M): M
30 
31 }
32 
33 trait Monoid[M] extends Semigroup[M] {
34 
35   def zero: M
36 
37 }
38 
39 object Monoid {
40   def apply[A:Monoid]: Monoid[A] = implicitly[Monoid[A]]
41 }
42 
43 object Semigroup {
44   def apply[A:Semigroup]: Semigroup[A] = implicitly[Semigroup[A]]
45 }
46 
47 object SemigroupSyntax {
48   @SuppressWarnings(Array("org.wartremover.warts.ImplicitConversion"))
49   implicit def ToSemigroupOps[A:Semigroup](v: A): SemigroupOps[A] =
50     new SemigroupOps[A](v)
51 
52   final class SemigroupOps[A:Semigroup](val self: A) {
53     def |+|(other: => A): A =
54       Semigroup[A].append(self, other)
55   }
56 }
57 
58 object SimpleMonoids {
59   import SemigroupSyntax._
60 
61   implicit def intAddMon: Monoid[Int] = new Monoid[Int] {
62     def zero = 0
63     def append(a: Int, b: => Int): Int = a + b
64   }
65 
66 
67   // is this really a monoid?
68   implicit def floatAddMon: Monoid[Double] = new Monoid[Double] {
69     def zero: Double = 0
70     def append(a: Double, b: => Double): Double = a + b
71   }
72 
73   implicit def intMulMon: Monoid[Int] = new Monoid[Int] {
74     def zero = 1
75     def append(a: Int, b: => Int): Int = a * b
76   }
77 
78   implicit def freeMon[A]: Monoid[List[A]] = new Monoid[List[A]] {
79     def zero: List[A] = List()
80     def append(as: List[A], bs: => List[A]): List[A] = as ++ bs
81   }
82 
83   def firstMon[A]: Monoid[Option[A]] = new Monoid[Option[A]] {
84     def zero = None
85     def append(a: Option[A], b: => Option[A]): Option[A] = a orElse b
86   }
87 
88   implicit def optionMon[A:Semigroup]: Monoid[Option[A]] =
89     new Monoid[Option[A]] {
90 
91       def zero: Option[A] = None
92 
93       def append(a: Option[A], b: => Option[A]): Option[A] =
94         (a,b) match {
95           case (a, None) => a
96           case (None, b) => b
97           case (Some(a), Some(b)) => Some(a |+| b)
98         }
99   }
100 
101   implicit def endoMon[A]: Monoid[A => A] = new Monoid[A => A] {
102     def zero: A => A = identity
103     def append(f: A => A, g: => (A => A)): A => A = g andThen f
104   }
105 
106   implicit def monFunSemi[A, B:Semigroup]: Semigroup[A => B] =
107     new Semigroup[A => B] {
108 
109       def append(f: A => B, g: => (A => B)): A => B =
110         a => f(a) |+| g(a)
111     }
112 
113   implicit def monFunMon[A, B:Monoid]: Monoid[A => B] =
114     new Monoid[A => B] {
115 
116       def zero: A => B = _ => Monoid[B].zero
117 
118       def append(f: A => B, g: => (A => B)): A => B =
119         a => f(a) |+| g(a)
120   }
121 
122   //(implicit am: Monoid[A], implicit bm: Monoid[B])
123   implicit def pairMon[A: Monoid, B: Monoid]: Monoid[(A,B)] = new Monoid[(A, B)] {
124 
125     def zero: (A,B) = (Monoid[A].zero, Monoid[B].zero)
126 
127     def append(x: (A, B), y: => (A, B)): (A,B) =
128       (x._1 |+| y._1, x._2 |+| y._2)
129   }
130 
131   implicit def tripleMon[A: Monoid, B: Monoid, C: Monoid]: Monoid[(A,B,C)] = new Monoid[(A, B, C)] {
132 
133     def zero: (A,B,C) = (Monoid[A].zero, Monoid[B].zero, Monoid[C].zero)
134 
135     def append(x: (A, B, C), y: => (A, B, C)): (A,B, C) =
136       (x._1 |+| y._1, x._2 |+| y._2, x._3 |+| y._3)
137   }
138 
139 
140   def mconcat[A:Monoid](as: Traversable[A]): A =
141     as.foldLeft(Monoid[A].zero)(_ |+| _)
142 
143   def sum(xs: Traversable[Int]): Int =
144     mconcat(xs)(intAddMon)
145 
146   def first[A](xs: Traversable[Option[A]]): Option[A] =
147     mconcat(xs)(firstMon)
148 
149   def concat[A](xs: Traversable[List[A]]): List[A] =
150     mconcat(xs)(freeMon)
151 
152   def sumO[A](xs: Traversable[Option[Int]]): Option[Int] =
153     mconcat(xs)(optionMon(intAddMon))
154 
155   def foldMap[A, M:Monoid](as: Traversable[A], f: A => M): M =
156     as.foldLeft(Monoid[M].zero) { _ |+| f(_) }
157 
158   def foldMap2[A, M:Monoid](as: Traversable[A], f: A => M): M =
159     mconcat(as.map(f))
160 
161   def filter[A](as: List[A], f: A => Boolean): List[A] =
162     foldMap(as, (a:A) => if (f(a)) List(a) else List())(freeMon)
163 
164   val allMonoid: Monoid[Boolean] = new Monoid[Boolean] {
165     def zero: Boolean = true
166     def append(a: Boolean, b: => Boolean): Boolean = a && b
167   }
168 
169 
170   implicit val mon: Monoid[Boolean] = allMonoid
171 
172   @SuppressWarnings(Array("org.wartremover.warts.Equals"))
173   val numbers: Iterable[Int] = 1.to(100).filter(
174     // we only add zero to exercise the method, not really needed
175     ((n:Int) => n % 2 == 0) |+| ((n:Int) => n >= 10) |+| ((n:Int) => n < 20) |+| Monoid[ Int=> Boolean].zero
176   )
177 
178   def minMon[A:Ordering]: Monoid[Option[A]] = new Monoid[Option[A]] {
179     def zero: Option[A] = None
180 
181     def append(a: Option[A], b: => Option[A]): Option[A] = (a, b) match {
182       case (None, x) => x
183       case (x, None) => x
184       case (Some(x), Some(y)) => Some(Ordering[A].min(x,y))
185     }
186   }
187 
188   def maxMon[A:Ordering]: Monoid[Option[A]] = new Monoid[Option[A]] {
189     def zero: Option[A] = None
190 
191     def append(a: Option[A], b: => Option[A]): Option[A] = (a, b) match {
192       case (None, x) => x
193       case (x, None) => x
194       case (Some(x), Some(y)) => Some(Ordering[A].max(x,y))
195     }
196   }
197 
198   def maxSemi[A:Ordering]: Semigroup[A] = new Semigroup[A] {
199     def append(a: A, b: => A): A = Ordering[A].max(a,b)
200   }
201 
202   def minSemi[A:Ordering]: Semigroup[A] = new Semigroup[A] {
203     def append(a: A, b: => A): A = Ordering[A].min(a,b)
204   }
205 
206   def min[A: Ordering](as: Traversable[A]): Option[A] =
207     foldMap(as, (a:A) => Option(a))(minMon) // map and reduce
208 
209   def max[A: Ordering](as: Traversable[A]): Option[A] =
210     foldMap(as, (a:A) => Option(a))(maxMon) // map and reduce
211 
212   def minMaxMon[A:Ordering]: Monoid[(Option[A], Option[A])] = pairMon(minMon, maxMon)
213 
214   def minmax[A: Ordering](as: Traversable[A]): Option[(A,A)] =
215     foldMap(as, (a:A) => (Option(a), Option(a)))(minMaxMon) match {
216       case (Some(mi), Some(ma)) => Some((mi,ma))
217       case _ => None
218     }
219 }
220 
221 
222 object Parallel {
223 
224   import SemigroupSyntax._
225 
226   // We receive a Task Support to make testing easier, thread pools are shared between tests
227   def mconcat[A:Monoid](as: Traversable[A])(ts: TaskSupport): A = {
228     val parAs = as.par
229     parAs.tasksupport = ts
230     parAs.fold(Monoid[A].zero)(_ |+| _)
231   }
232 }
233 
234 object Stats {
235 
236   sealed abstract class MeanVar
237   final case object EmptyMeanVar extends MeanVar
238   final case class MeanVarV(m1: Double, m2: Double, n: Long) extends MeanVar
239 
240   object MeanVar {
241     import SimpleMonoids.foldMap
242 
243     def singleton(x: Double): MeanVar = MeanVarV(x, 0, 1)
244 
245     def sample(xs: Traversable[Double]): MeanVar =
246       foldMap(xs, singleton)
247 
248     def mean: MeanVar => Option[Double] = {
249       case MeanVarV(m1, _, _) => Some(m1)
250       case _ => None
251     }
252 
253     def variance: MeanVar => Option[Double] = {
254       case MeanVarV(_, _, 1) => Some(0)
255       case MeanVarV(_, m2, n) => Some(m2/(n - 1.0))
256       case _ => None
257     }
258 
259     def sampleSize: MeanVar => Long = {
260       case MeanVarV(_, _, n) => n
261       case _ => 0
262     }
263 
264     implicit val meanVarMonoid: Monoid[MeanVar] = new Monoid[MeanVar] {
265       def zero: MeanVar = EmptyMeanVar
266 
267       def append(a: MeanVar, b: => MeanVar): MeanVar = (a, b) match {
268         case (MeanVarV(m1a, m2a, na), MeanVarV(m1b, m2b, nb)) => {
269           val (nt, delta) = (na + nb, m1b - m1a)
270           MeanVarV((na * m1a + nb * m1b ) / nt,
271                    m2a + m2b + delta * delta * na * nb / nt,
272                    nt)
273         }
274 
275         case (EmptyMeanVar, a) => a
276         case (a, EmptyMeanVar) => a
277       }
278     }
279   }
280 
281 
282 
283 }
Line Stmt Id Pos Tree Symbol Code
40 116 1022 - 1043 ApplyToImplicitArgs scala.Predef.implicitly scala.Predef.implicitly[monoid.monoids.Monoid[A]](evidence$1)
44 117 1107 - 1131 ApplyToImplicitArgs scala.Predef.implicitly scala.Predef.implicitly[monoid.monoids.Semigroup[A]](evidence$2)
50 118 1303 - 1325 ApplyToImplicitArgs monoid.monoids.SemigroupSyntax.SemigroupOps.<init> new monoid.monoids.SemigroupSyntax.SemigroupOps[A](v)(evidence$3)
54 119 1427 - 1427 Select monoid.monoids.SemigroupSyntax.SemigroupOps.evidence$4 SemigroupOps.this.evidence$4
54 121 1418 - 1450 Apply monoid.monoids.Semigroup.append Semigroup.apply[A](SemigroupOps.this.evidence$4).append(SemigroupOps.this.self, other)
54 120 1438 - 1442 Select monoid.monoids.SemigroupSyntax.SemigroupOps.self SemigroupOps.this.self
61 124 1549 - 1552 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
62 122 1582 - 1583 Literal <nosymbol> 0
63 123 1625 - 1630 Apply scala.Int.+ a.+(b)
68 127 1712 - 1715 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
69 125 1756 - 1757 Literal <nosymbol> 0.0
70 126 1808 - 1813 Apply scala.Double.+ a.+(b)
73 130 1859 - 1862 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
74 128 1892 - 1893 Literal <nosymbol> 1
75 129 1935 - 1940 Apply scala.Int.* a.*(b)
78 134 1991 - 1994 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
79 131 2037 - 2043 Select scala.collection.immutable.Nil scala.collection.immutable.Nil
80 133 2099 - 2107 ApplyToImplicitArgs scala.collection.immutable.List.++ as.++[A, List[A]](bs)(immutable.this.List.canBuildFrom[A])
80 132 2102 - 2102 TypeApply scala.collection.immutable.List.canBuildFrom immutable.this.List.canBuildFrom[A]
83 137 2152 - 2155 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
84 135 2191 - 2195 Select scala.None scala.None
85 136 2255 - 2265 Apply scala.Option.orElse a.orElse[A](b)
89 141 2334 - 2337 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
91 138 2387 - 2391 Select scala.None scala.None
97 140 2573 - 2586 Apply scala.Some.apply scala.Some.apply[A](SemigroupSyntax.ToSemigroupOps[A](a)(evidence$5).|+|(b))
97 139 2578 - 2585 Apply monoid.monoids.SemigroupSyntax.SemigroupOps.|+| SemigroupSyntax.ToSemigroupOps[A](a)(evidence$5).|+|(b)
101 144 2646 - 2649 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
102 142 2690 - 2698 Apply scala.Predef.identity scala.Predef.identity[A](x)
103 143 2751 - 2762 Apply scala.Function1.andThen g.andThen[A](f)
107 148 2835 - 2838 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
110 146 2936 - 2940 Apply scala.Function1.apply g.apply(a)
110 145 2927 - 2931 Apply scala.Function1.apply f.apply(a)
110 147 2927 - 2940 Apply monoid.monoids.SemigroupSyntax.SemigroupOps.|+| SemigroupSyntax.ToSemigroupOps[B](f.apply(a))(evidence$6).|+|(g.apply(a))
114 153 3008 - 3011 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
116 149 3060 - 3074 Select monoid.monoids.Monoid.zero Monoid.apply[B](evidence$7).zero
119 151 3152 - 3156 Apply scala.Function1.apply g.apply(a)
119 150 3143 - 3147 Apply scala.Function1.apply f.apply(a)
119 152 3143 - 3156 Apply monoid.monoids.SemigroupSyntax.SemigroupOps.|+| SemigroupSyntax.ToSemigroupOps[B](f.apply(a))(evidence$7).|+|(g.apply(a))
123 164 3277 - 3280 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
125 155 3338 - 3352 Select monoid.monoids.Monoid.zero Monoid.apply[B](evidence$9).zero
125 154 3322 - 3336 Select monoid.monoids.Monoid.zero Monoid.apply[A](evidence$8).zero
125 156 3321 - 3353 Apply scala.Tuple2.apply scala.Tuple2.apply[A, B](Monoid.apply[A](evidence$8).zero, Monoid.apply[B](evidence$9).zero)
128 158 3420 - 3424 Select scala.Tuple2._1 y._1
128 160 3426 - 3430 Select scala.Tuple2._2 x._2
128 163 3410 - 3440 Apply scala.Tuple2.apply scala.Tuple2.apply[A, B](SemigroupSyntax.ToSemigroupOps[A](x._1)(evidence$8).|+|(y._1), SemigroupSyntax.ToSemigroupOps[B](x._2)(evidence$9).|+|(y._2))
128 157 3411 - 3415 Select scala.Tuple2._1 x._1
128 159 3411 - 3424 Apply monoid.monoids.SemigroupSyntax.SemigroupOps.|+| SemigroupSyntax.ToSemigroupOps[A](x._1)(evidence$8).|+|(y._1)
128 162 3426 - 3439 Apply monoid.monoids.SemigroupSyntax.SemigroupOps.|+| SemigroupSyntax.ToSemigroupOps[B](x._2)(evidence$9).|+|(y._2)
128 161 3435 - 3439 Select scala.Tuple2._2 y._2
131 179 3523 - 3526 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
133 167 3605 - 3619 Select monoid.monoids.Monoid.zero Monoid.apply[C](evidence$12).zero
133 166 3589 - 3603 Select monoid.monoids.Monoid.zero Monoid.apply[B](evidence$11).zero
133 165 3573 - 3587 Select monoid.monoids.Monoid.zero Monoid.apply[A](evidence$10).zero
133 168 3572 - 3620 Apply scala.Tuple3.apply scala.Tuple3.apply[A, B, C](Monoid.apply[A](evidence$10).zero, Monoid.apply[B](evidence$11).zero, Monoid.apply[C](evidence$12).zero)
136 173 3711 - 3715 Select scala.Tuple3._2 y._2
136 176 3726 - 3730 Select scala.Tuple3._3 y._3
136 175 3717 - 3721 Select scala.Tuple3._3 x._3
136 169 3687 - 3691 Select scala.Tuple3._1 x._1
136 178 3686 - 3731 Apply scala.Tuple3.apply scala.Tuple3.apply[A, B, C](SemigroupSyntax.ToSemigroupOps[A](x._1)(evidence$10).|+|(y._1), SemigroupSyntax.ToSemigroupOps[B](x._2)(evidence$11).|+|(y._2), SemigroupSyntax.ToSemigroupOps[C](x._3)(evidence$12).|+|(y._3))
136 172 3702 - 3706 Select scala.Tuple3._2 x._2
136 174 3702 - 3715 Apply monoid.monoids.SemigroupSyntax.SemigroupOps.|+| SemigroupSyntax.ToSemigroupOps[B](x._2)(evidence$11).|+|(y._2)
136 177 3717 - 3730 Apply monoid.monoids.SemigroupSyntax.SemigroupOps.|+| SemigroupSyntax.ToSemigroupOps[C](x._3)(evidence$12).|+|(y._3)
136 171 3687 - 3700 Apply monoid.monoids.SemigroupSyntax.SemigroupOps.|+| SemigroupSyntax.ToSemigroupOps[A](x._1)(evidence$10).|+|(y._1)
136 170 3696 - 3700 Select scala.Tuple3._1 y._1
141 182 3791 - 3827 Apply scala.collection.TraversableOnce.foldLeft as.foldLeft[A](Monoid.apply[A](evidence$13).zero)(((x$2: A, x$3: A) => SemigroupSyntax.ToSemigroupOps[A](x$2)(evidence$13).|+|(x$3)))
141 181 3819 - 3826 Apply monoid.monoids.SemigroupSyntax.SemigroupOps.|+| SemigroupSyntax.ToSemigroupOps[A](x$2)(evidence$13).|+|(x$3)
141 180 3803 - 3817 Select monoid.monoids.Monoid.zero Monoid.apply[A](evidence$13).zero
144 184 3872 - 3894 Apply monoid.monoids.SimpleMonoids.mconcat SimpleMonoids.this.mconcat[Int](xs)(SimpleMonoids.this.intAddMon)
144 183 3884 - 3893 Select monoid.monoids.SimpleMonoids.intAddMon SimpleMonoids.this.intAddMon
147 185 3968 - 3976 TypeApply monoid.monoids.SimpleMonoids.firstMon SimpleMonoids.this.firstMon[A]
147 186 3956 - 3977 Apply monoid.monoids.SimpleMonoids.mconcat SimpleMonoids.this.mconcat[Option[A]](xs)(SimpleMonoids.this.firstMon[A])
150 187 4048 - 4055 TypeApply monoid.monoids.SimpleMonoids.freeMon SimpleMonoids.this.freeMon[A]
150 188 4036 - 4056 Apply monoid.monoids.SimpleMonoids.mconcat SimpleMonoids.this.mconcat[List[A]](xs)(SimpleMonoids.this.freeMon[A])
153 191 4121 - 4154 Apply monoid.monoids.SimpleMonoids.mconcat SimpleMonoids.this.mconcat[Option[Int]](xs)(SimpleMonoids.this.optionMon[Int](SimpleMonoids.this.intAddMon))
153 190 4133 - 4153 Apply monoid.monoids.SimpleMonoids.optionMon SimpleMonoids.this.optionMon[Int](SimpleMonoids.this.intAddMon)
153 189 4143 - 4152 Select monoid.monoids.SimpleMonoids.intAddMon SimpleMonoids.this.intAddMon
156 194 4253 - 4263 Apply monoid.monoids.SemigroupSyntax.SemigroupOps.|+| SemigroupSyntax.ToSemigroupOps[M](x$4)(evidence$14).|+|(f.apply(x$5))
156 193 4259 - 4263 Apply scala.Function1.apply f.apply(x$5)
156 192 4235 - 4249 Select monoid.monoids.Monoid.zero Monoid.apply[M](evidence$14).zero
156 195 4223 - 4265 Apply scala.collection.TraversableOnce.foldLeft as.foldLeft[M](Monoid.apply[M](evidence$14).zero)(((x$4: M, x$5: A) => SemigroupSyntax.ToSemigroupOps[M](x$4)(evidence$14).|+|(f.apply(x$5))))
159 196 4335 - 4353 ApplyToImplicitArgs monoid.monoids.SimpleMonoids.mconcat SimpleMonoids.this.mconcat[M](as.map[M, scala.collection.immutable.Traversable[M]](f)(immutable.this.Traversable.canBuildFrom[M]))(evidence$15)
162 200 4460 - 4466 Select scala.collection.immutable.Nil scala.collection.immutable.Nil
162 202 4468 - 4475 TypeApply monoid.monoids.SimpleMonoids.freeMon SimpleMonoids.this.freeMon[A]
162 199 4447 - 4454 Block scala.collection.immutable.List.apply scala.collection.immutable.List.apply[A](a)
162 198 4447 - 4454 Apply scala.collection.immutable.List.apply scala.collection.immutable.List.apply[A](a)
162 201 4460 - 4466 Block scala.collection.immutable.Nil scala.collection.immutable.Nil
162 203 4416 - 4476 Apply monoid.monoids.SimpleMonoids.foldMap SimpleMonoids.this.foldMap[A, List[A]](as, ((a: A) => if (f.apply(a)) scala.collection.immutable.List.apply[A](a) else scala.collection.immutable.Nil))(SimpleMonoids.this.freeMon[A])
162 197 4441 - 4445 Apply scala.Function1.apply f.apply(a)
164 206 4513 - 4516 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
165 204 4559 - 4563 Literal <nosymbol> true
166 205 4617 - 4623 Apply scala.Boolean.&& a.&&(b)
170 207 4668 - 4677 Select monoid.monoids.SimpleMonoids.allMonoid SimpleMonoids.this.allMonoid
173 209 4774 - 4777 Literal <nosymbol> 100
173 208 4769 - 4770 Literal <nosymbol> 1
173 225 4769 - 4965 Apply scala.collection.TraversableLike.filter scala.Predef.intWrapper(1).to(100).filter(SemigroupSyntax.ToSemigroupOps[Int => Boolean](SemigroupSyntax.ToSemigroupOps[Int => Boolean](SemigroupSyntax.ToSemigroupOps[Int => Boolean](((n: Int) => n.%(2).==(0)))(SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)).|+|(((n: Int) => n.>=(10))))(SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)).|+|(((n: Int) => n.<(20))))(SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)).|+|(Monoid.apply[Int => Boolean](SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)).zero))
175 218 4857 - 4929 Apply monoid.monoids.SemigroupSyntax.SemigroupOps.|+| SemigroupSyntax.ToSemigroupOps[Int => Boolean](SemigroupSyntax.ToSemigroupOps[Int => Boolean](((n: Int) => n.%(2).==(0)))(SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)).|+|(((n: Int) => n.>=(10))))(SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)).|+|(((n: Int) => n.<(20)))
175 211 4866 - 4866 Select monoid.monoids.SimpleMonoids.mon SimpleMonoids.this.mon
175 220 4906 - 4906 ApplyToImplicitArgs monoid.monoids.SimpleMonoids.monFunMon SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)
175 223 4934 - 4961 Select monoid.monoids.Monoid.zero Monoid.apply[Int => Boolean](SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)).zero
175 214 4857 - 4905 Apply monoid.monoids.SemigroupSyntax.SemigroupOps.|+| SemigroupSyntax.ToSemigroupOps[Int => Boolean](((n: Int) => n.%(2).==(0)))(SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)).|+|(((n: Int) => n.>=(10)))
175 217 4922 - 4928 Apply scala.Int.< n.<(20)
175 216 4881 - 4881 ApplyToImplicitArgs monoid.monoids.SimpleMonoids.monFunMon SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)
175 210 4869 - 4879 Apply scala.Int.== n.%(2).==(0)
175 219 4906 - 4906 Select monoid.monoids.SimpleMonoids.mon SimpleMonoids.this.mon
175 213 4897 - 4904 Apply scala.Int.>= n.>=(10)
175 222 4940 - 4940 ApplyToImplicitArgs monoid.monoids.SimpleMonoids.monFunMon SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)
175 221 4940 - 4940 Select monoid.monoids.SimpleMonoids.mon SimpleMonoids.this.mon
175 212 4866 - 4866 ApplyToImplicitArgs monoid.monoids.SimpleMonoids.monFunMon SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)
175 215 4881 - 4881 Select monoid.monoids.SimpleMonoids.mon SimpleMonoids.this.mon
175 224 4857 - 4961 Apply monoid.monoids.SemigroupSyntax.SemigroupOps.|+| SemigroupSyntax.ToSemigroupOps[Int => Boolean](SemigroupSyntax.ToSemigroupOps[Int => Boolean](SemigroupSyntax.ToSemigroupOps[Int => Boolean](((n: Int) => n.%(2).==(0)))(SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)).|+|(((n: Int) => n.>=(10))))(SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)).|+|(((n: Int) => n.<(20))))(SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)).|+|(Monoid.apply[Int => Boolean](SimpleMonoids.this.monFunMon[Int, Boolean](SimpleMonoids.this.mon)).zero)
178 229 5013 - 5016 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
179 226 5063 - 5067 Select scala.None scala.None
184 227 5233 - 5253 Apply scala.math.Ordering.min scala.`package`.Ordering.apply[A](evidence$16).min(x, y)
184 228 5228 - 5254 Apply scala.Some.apply scala.Some.apply[A](scala.`package`.Ordering.apply[A](evidence$16).min(x, y))
188 233 5312 - 5315 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
189 230 5362 - 5366 Select scala.None scala.None
194 232 5527 - 5553 Apply scala.Some.apply scala.Some.apply[A](scala.`package`.Ordering.apply[A](evidence$17).max(x, y))
194 231 5532 - 5552 Apply scala.math.Ordering.max scala.`package`.Ordering.apply[A](evidence$17).max(x, y)
198 235 5607 - 5610 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
199 234 5661 - 5681 Apply scala.math.Ordering.max scala.`package`.Ordering.apply[A](evidence$18).max(a, b)
202 237 5729 - 5732 Apply monoid.monoids.SimpleMonoids.$anon.<init> new $anon()
203 236 5783 - 5803 Apply scala.math.Ordering.min scala.`package`.Ordering.apply[A](evidence$19).min(a, b)
207 238 5890 - 5899 Apply scala.Option.apply scala.Option.apply[A](a)
207 240 5869 - 5908 Apply monoid.monoids.SimpleMonoids.foldMap SimpleMonoids.this.foldMap[A, Option[A]](as, ((a: A) => scala.Option.apply[A](a)))(SimpleMonoids.this.minMon[A](evidence$20))
207 239 5901 - 5907 ApplyToImplicitArgs monoid.monoids.SimpleMonoids.minMon SimpleMonoids.this.minMon[A](evidence$20)
210 241 6009 - 6018 Apply scala.Option.apply scala.Option.apply[A](a)
210 243 5988 - 6027 Apply monoid.monoids.SimpleMonoids.foldMap SimpleMonoids.this.foldMap[A, Option[A]](as, ((a: A) => scala.Option.apply[A](a)))(SimpleMonoids.this.maxMon[A](evidence$21))
210 242 6020 - 6026 ApplyToImplicitArgs monoid.monoids.SimpleMonoids.maxMon SimpleMonoids.this.maxMon[A](evidence$21)
212 245 6125 - 6131 ApplyToImplicitArgs monoid.monoids.SimpleMonoids.maxMon SimpleMonoids.this.maxMon[A](evidence$22)
212 244 6117 - 6123 ApplyToImplicitArgs monoid.monoids.SimpleMonoids.minMon SimpleMonoids.this.minMon[A](evidence$22)
212 246 6109 - 6132 Apply monoid.monoids.SimpleMonoids.pairMon SimpleMonoids.this.pairMon[Option[A], Option[A]](SimpleMonoids.this.minMon[A](evidence$22), SimpleMonoids.this.maxMon[A](evidence$22))
215 247 6223 - 6232 Apply scala.Option.apply scala.Option.apply[A](a)
215 250 6246 - 6255 ApplyToImplicitArgs monoid.monoids.SimpleMonoids.minMaxMon SimpleMonoids.this.minMaxMon[A](evidence$23)
215 249 6222 - 6244 Apply scala.Tuple2.apply scala.Tuple2.apply[Option[A], Option[A]](scala.Option.apply[A](a), scala.Option.apply[A](a))
215 248 6234 - 6243 Apply scala.Option.apply scala.Option.apply[A](a)
215 251 6201 - 6256 Apply monoid.monoids.SimpleMonoids.foldMap SimpleMonoids.this.foldMap[A, (Option[A], Option[A])](as, ((a: A) => scala.Tuple2.apply[Option[A], Option[A]](scala.Option.apply[A](a), scala.Option.apply[A](a))))(SimpleMonoids.this.minMaxMon[A](evidence$23))
216 253 6300 - 6313 Apply scala.Some.apply scala.Some.apply[(A, A)](scala.Tuple2.apply[A, A](mi, ma))
216 252 6305 - 6312 Apply scala.Tuple2.apply scala.Tuple2.apply[A, A](mi, ma)
217 254 6330 - 6334 Select scala.None scala.None
228 255 6569 - 6575 Select scala.collection.Parallelizable.par as.par
229 256 6580 - 6602 Apply scala.collection.parallel.ParIterableLike.tasksupport_= parAs.tasksupport_=(ts)
230 259 6607 - 6642 Apply scala.collection.parallel.ParIterableLike.fold parAs.fold[A](Monoid.apply[A](evidence$24).zero)(((x$6: A, x$7: A) => SemigroupSyntax.ToSemigroupOps[A](x$6)(evidence$24).|+|(x$7)))
230 258 6634 - 6641 Apply monoid.monoids.SemigroupSyntax.SemigroupOps.|+| SemigroupSyntax.ToSemigroupOps[A](x$6)(evidence$24).|+|(x$7)
230 257 6618 - 6632 Select monoid.monoids.Monoid.zero Monoid.apply[A](evidence$24).zero
243 260 6918 - 6935 Apply monoid.monoids.Stats.MeanVarV.apply Stats.this.MeanVarV.apply(x, 0.0, 1L)
246 262 7001 - 7001 Select monoid.monoids.Stats.MeanVar.meanVarMonoid MeanVar.this.meanVarMonoid
246 261 7006 - 7015 Apply monoid.monoids.Stats.MeanVar.singleton MeanVar.this.singleton(x)
246 263 6994 - 7016 ApplyToImplicitArgs monoid.monoids.SimpleMonoids.foldMap SimpleMonoids.foldMap[Double, monoid.monoids.Stats.MeanVar](xs, { ((x: Double) => MeanVar.this.singleton(x)) })(MeanVar.this.meanVarMonoid)
249 264 7095 - 7103 Apply scala.Some.apply scala.Some.apply[Double](m1)
250 265 7120 - 7124 Select scala.None scala.None
254 266 7212 - 7219 Apply scala.Some.apply scala.Some.apply[Double](0.0)
255 268 7258 - 7270 Apply scala.Double./ m2./(n.-(1.0))
255 267 7262 - 7269 Apply scala.Long.- n.-(1.0)
255 269 7253 - 7271 Apply scala.Some.apply scala.Some.apply[Double](m2./(n.-(1.0)))
256 270 7288 - 7292 Select scala.None scala.None
261 271 7390 - 7391 Literal <nosymbol> 0L
264 279 7449 - 7452 Apply monoid.monoids.Stats.MeanVar.$anon.<init> new $anon()
265 272 7497 - 7509 Select monoid.monoids.Stats.EmptyMeanVar Stats.this.EmptyMeanVar
269 274 7667 - 7667 Select scala.Tuple2._2 x$8._2
269 273 7663 - 7663 Select scala.Tuple2._1 x$8._1
270 275 7716 - 7743 Apply scala.Double./ na.*(m1a).+(nb.*(m1b))./(nt)
270 278 7707 - 7828 Apply monoid.monoids.Stats.MeanVarV.apply Stats.this.MeanVarV.apply(na.*(m1a).+(nb.*(m1b))./(nt), m2a.+(m2b).+(delta.*(delta).*(na).*(nb)./(nt)), nt)
271 277 7764 - 7804 Apply scala.Double.+ m2a.+(m2b).+(delta.*(delta).*(na).*(nb)./(nt))
271 276 7776 - 7804 Apply scala.Double./ delta.*(delta).*(na).*(nb)./(nt)