-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from Kotlin/seq-of
[Feature] Seq of functions
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
kotlin-spark-api/src/main/kotlin/org/jetbrains/kotlinx/spark/api/Seq.kt
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.jetbrains.kotlinx.spark.api | ||
|
||
import scala.collection.immutable.`Seq$`.`MODULE$` as Seq | ||
import scala.collection.immutable.Seq as Seq | ||
import scala.collection.mutable.`Seq$`.`MODULE$` as MutableSeq | ||
import scala.collection.mutable.Seq as MutableSeq | ||
|
||
/** | ||
* Returns a new empty immutable Seq. | ||
*/ | ||
fun <T> emptySeq(): Seq<T> = Seq.empty<T>() as Seq<T> | ||
|
||
/** | ||
* Returns a new immutable Seq with the given elements. | ||
*/ | ||
fun <T> seqOf(vararg elements: T): Seq<T> = | ||
if (elements.isEmpty()) | ||
emptySeq() | ||
else | ||
Seq.newBuilder<T>().apply { | ||
for (it in elements) | ||
`$plus$eq`(it) | ||
}.result() as Seq<T> | ||
|
||
/** | ||
* Returns a new mutable Seq with the given elements. | ||
*/ | ||
fun <T> emptyMutableSeq(): MutableSeq<T> = MutableSeq.empty<T>() as MutableSeq<T> | ||
|
||
/** | ||
* Returns a new mutable Seq with the given elements. | ||
*/ | ||
fun <T> mutableSeqOf(vararg elements: T): MutableSeq<T> = | ||
if (elements.isEmpty()) | ||
emptyMutableSeq() | ||
else | ||
MutableSeq.newBuilder<T>().apply { | ||
for (it in elements) | ||
`$plus$eq`(it) | ||
}.result() as MutableSeq<T> |
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