Skip to content

Commit 7fdeee0

Browse files
committed
moved to flatgraph. only change left: deprecation onlyChecked
1 parent 32b3ac9 commit 7fdeee0

File tree

2 files changed

+1
-107
lines changed

2 files changed

+1
-107
lines changed

codepropertygraph/src/main/scala/io/shiftleft/Implicits.scala

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,9 @@ import org.slf4j.{Logger, LoggerFactory}
55
object Implicits {
66
private val logger: Logger = LoggerFactory.getLogger(Implicits.getClass)
77

8-
extension [A](iterable: IterableOnce[A]) {
9-
10-
/** @see {{{loneElement(hint)}}} */
11-
def loneElement: A =
12-
loneElement(hint = "")
13-
14-
/** @return
15-
* the one and only element from an Iterable
16-
* @throws NoSuchElementException
17-
* if the Iterable is empty
18-
* @throws AssertionError
19-
* if the Iterable has more than one element
20-
*/
21-
def loneElement(hint: String): A = {
22-
lazy val hintMaybe =
23-
if (hint.isEmpty) ""
24-
else s" Hint: $hint"
25-
26-
val iter = iterable.iterator
27-
if (iter.isEmpty) {
28-
throw new NoSuchElementException(
29-
s"Iterable was expected to have exactly one element, but it is empty.$hintMaybe"
30-
)
31-
} else {
32-
val res = iter.next()
33-
if (iter.hasNext) {
34-
val collectionSizeHint = iterable.knownSize match {
35-
case -1 => "it has more than one" // cannot be computed cheaply, i.e. without traversing the collection
36-
case knownSize => s"it has $knownSize"
37-
}
38-
throw new AssertionError(
39-
s"Iterable was expected to have exactly one element, but $collectionSizeHint.$hintMaybe"
40-
)
41-
}
42-
res
43-
}
44-
}
45-
46-
/** @return
47-
* {{{Some(element)}}} if the Iterable has exactly one element, or {{{None}}} if the Iterable has zero or more
48-
* than 1 element. Note: if the lone element is {{{null}}}, this will return {{{Some(null)}}}, which is in
49-
* accordance with how {{{headOption}}} works.
50-
*/
51-
def loneElementOption: Option[A] = {
52-
val iter = iterable.iterator
53-
if (iter.isEmpty) {
54-
None
55-
} else {
56-
val result = iter.next()
57-
if (iter.hasNext) {
58-
None
59-
} else {
60-
Some(result)
61-
}
62-
}
63-
}
64-
}
65-
668
implicit class IterableOnceDeco[T](val iterable: IterableOnce[T]) extends AnyVal {
679
@deprecated(
68-
"please use `loneElement` instead, which has a better name and will throw if the iterable has more than one element (rather than just log.warn)",
10+
"please use `.loneElement` from flatgraph (mixed into the generated `language` packages) instead, which has a better name and will throw if the iterable has more than one element (rather than just log.warn)",
6911
since = "1.7.42 (July 2025)"
7012
)
7113
def onlyChecked: T = {

codepropertygraph/src/test/scala/io/shiftleft/ImplicitsTests.scala

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)