1 /* 2 * Make.org Core API 3 * Copyright (C) 2018 Make.org 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation, either version 3 of the 8 * License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Affero General Public License for more details. 14 * 15 * You should have received a copy of the GNU Affero General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package org.make.core.technical 21 22 import scala.collection.mutable.{HashMap => MMap} 23 24 object CollectionUtils { 25 26 implicit class ImprovedSeq[A](seq: Seq[A]) { 27 28 @SuppressWarnings(Array("org.wartremover.warts.MutableDataStructures")) 29 def countOccurencesBy[B](fn: A => B): MMap[B, Int] = { 30 val mMap = MMap[B, Int]() 31 seq.foreach(item => { 32 val key = fn(item) 33 mMap.update(key, mMap.getOrElse(key, 0) + 1) 34 }) 35 mMap 36 } 37 } 38 }
| Line | Stmt Id | Pos | Tree | Symbol | Tests | Code |
|---|---|---|---|---|---|---|
| 30 | 2481 | 1055 - 1069 | Apply | scala.collection.MapFactory.apply | org.make.api.sequence.sequencesimulationtest,org.make.api.sequence.selectionalgorithmtest | scala.collection.mutable.HashMap.apply[B, Int]() |
| 31 | 773 | 1076 - 1186 | Apply | scala.collection.IterableOnceOps.foreach | org.make.api.sequence.sequencesimulationtest,org.make.api.sequence.selectionalgorithmtest | ImprovedSeq.this.seq.foreach[Unit](((item: A) => { val key: B = fn.apply(item); mMap.update(key, mMap.getOrElse[Int](key, 0).+(1)) })) |
| 32 | 679 | 1116 - 1124 | Apply | scala.Function1.apply | org.make.api.sequence.sequencesimulationtest,org.make.api.sequence.selectionalgorithmtest | fn.apply(item) |
| 33 | 2905 | 1133 - 1177 | Apply | scala.collection.mutable.HashMap.update | org.make.api.sequence.sequencesimulationtest,org.make.api.sequence.selectionalgorithmtest | mMap.update(key, mMap.getOrElse[Int](key, 0).+(1)) |
| 33 | 4980 | 1150 - 1176 | Apply | scala.Int.+ | org.make.api.sequence.sequencesimulationtest,org.make.api.sequence.selectionalgorithmtest | mMap.getOrElse[Int](key, 0).+(1) |