Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[util-core, inject-utils]: Move c.t.inject.conversions.seq to util-core
Problem Finatra's inject-utils/conversions contains useful seq conversion methods that would fit better in util-core/conversions. Solution Deprecate everything in `c.t.inject.conversions.seq`, and move the functionality to util-core, along with the corresponding tests. JIRA Issues: CSL-10371 Differential Revision: https://phabricator.twitter.biz/D578605
- Loading branch information
Showing
3 changed files
with
15 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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
40 changes: 12 additions & 28 deletions
40
inject/inject-utils/src/main/scala/com/twitter/inject/conversions/seq.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,31 @@ | ||
package com.twitter.inject.conversions | ||
|
||
import scala.annotation.tailrec | ||
import com.twitter.conversions.SeqOps | ||
|
||
@deprecated("Use com.twitter.conversions.SeqOps instead", "2020-11-16") | ||
object seq { | ||
|
||
implicit class RichSeq[A](val self: Seq[A]) extends AnyVal { | ||
|
||
def createMap[K, V](keys: A => K, values: A => V): Map[K, V] = { | ||
self.iterator.map { elem => | ||
keys(elem) -> values(elem) | ||
}.toMap | ||
} | ||
@deprecated("Use com.twitter.conversions.SeqOps#createMap instead", "2020-11-16") | ||
def createMap[K, V](keys: A => K, values: A => V): Map[K, V] = | ||
SeqOps.createMap(self, keys, values) | ||
|
||
def createMap[K, V](values: A => V): Map[A, V] = { | ||
self.iterator.map { elem => | ||
elem -> values(elem) | ||
}.toMap | ||
} | ||
@deprecated("Use com.twitter.conversions.SeqOps#createMap instead", "2020-11-16") | ||
def createMap[K, V](values: A => V): Map[A, V] = SeqOps.createMap(self, values) | ||
|
||
def foreachPartial(pf: PartialFunction[A, Unit]): Unit = { | ||
|
||
self.foreach { elem => | ||
if (pf.isDefinedAt(elem)) { | ||
pf(elem) | ||
} | ||
} | ||
} | ||
@deprecated("Use com.twitter.conversions.SeqOps#foreachPartial instead", "2020-11-16") | ||
def foreachPartial(pf: PartialFunction[A, Unit]): Unit = SeqOps.foreachPartial(self, pf) | ||
|
||
/** | ||
* Chooses last element in seq when key collision occurs | ||
*/ | ||
@deprecated("Use com.twitter.conversions.SeqOps#groupBySingleValue instead", "2020-11-16") | ||
def groupBySingleValue[B](keys: A => B): Map[B, A] = { | ||
createMap(keys, identity) | ||
} | ||
|
||
def findItemAfter(itemToFind: A): Option[A] = { | ||
@tailrec | ||
def recurse(itemToFind: A, seq: Seq[A]): Option[A] = seq match { | ||
case Seq(x, xs @ _*) if x == itemToFind => xs.headOption | ||
case Seq(x, xs @ _*) => recurse(itemToFind, xs) | ||
case Seq() => None | ||
} | ||
recurse(itemToFind, self) | ||
} | ||
@deprecated("Use com.twitter.conversions.SeqOps#findItemAfter instead", "2020-11-16") | ||
def findItemAfter(itemToFind: A): Option[A] = SeqOps.findItemAfter(self, itemToFind) | ||
} | ||
} |
38 changes: 0 additions & 38 deletions
38
...inject-utils/src/test/scala/com/twitter/inject/tests/conversions/SeqConversionsTest.scala
This file was deleted.
Oops, something went wrong.