coreLib and Java collections utilities
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.util
|
||||
|
||||
fun Boolean.iif<T>(then: T, _else: T): T = if (this) then else _else
|
||||
|
||||
// These two functions are needed in conjunction with iif:
|
||||
// foo.eq(bar).iif(a, b)
|
||||
fun <T> T.eq(eq: T): Boolean = this == eq
|
||||
fun <T> T.neq(eq: T): Boolean = this != eq
|
||||
@@ -0,0 +1,10 @@
|
||||
package org.jetbrains.jet.utils
|
||||
|
||||
import java.util.Collections
|
||||
|
||||
public fun <T> emptyList(): MutableList<T> = Collections.emptyList<T>() as MutableList
|
||||
public fun <T: Any> emptyOrSingletonList(item: T?): MutableList<T> = if (item == null) emptyList() else Collections.singletonList(item) as MutableList
|
||||
|
||||
public fun <T> emptySet(): MutableSet<T> = Collections.emptySet<T>() as MutableSet
|
||||
public fun <K, V> emptyMap(): MutableMap<K, V> = Collections.emptyMap<K, V>() as MutableMap
|
||||
|
||||
Reference in New Issue
Block a user