Skip to content

Commit

Permalink
Use .iterator.isEmpty and .iterator.msString instead .isEmpty a…
Browse files Browse the repository at this point in the history
…nd `.mkString` as suggested

Fixes the warnings (4, each repeated twice):
```
[warn] /home/runner/work/kaitai_struct_compiler/kaitai_struct_compiler/compiler/shared/src/main/scala/io/kaitai/struct/Utils.scala:113:14: method isEmpty in class IterableOnceExtensionMethods is deprecated (since 2.13.0): Use .iterator.isEmpty instead
[warn]     if (coll.isEmpty) "" else coll.mkString(start, sep, end)
[warn]              ^
[warn] /home/runner/work/kaitai_struct_compiler/kaitai_struct_compiler/compiler/shared/src/main/scala/io/kaitai/struct/Utils.scala:113:36: method mkString in class IterableOnceExtensionMethods is deprecated (since 2.13.0): Use .iterator.mkString instead
[warn]     if (coll.isEmpty) "" else coll.mkString(start, sep, end)
[warn]                                    ^
```
  • Loading branch information
Mingun committed Mar 9, 2024
1 parent 7857b84 commit 05d0221
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions shared/src/main/scala/io/kaitai/struct/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ object Utils {
* @return If the collection is empty, returns empty string, otherwise returns `start`,
* then elements of the collection, every pair separated with `sep`, then `end`.
*/
def join[T](coll: IterableOnce[T], start: String, sep: String, end: String): String =
if (coll.isEmpty) "" else coll.mkString(start, sep, end)
def join[T](coll: IterableOnce[T], start: String, sep: String, end: String): String = {
val it = coll.iterator
if (it.isEmpty) "" else it.mkString(start, sep, end)
}

/**
* Converts byte array (Seq[Byte]) into hex-escaped C-style literal characters
Expand Down

0 comments on commit 05d0221

Please sign in to comment.