Skip to content

Commit

Permalink
✨ JsExport: enable for list and set
Browse files Browse the repository at this point in the history
  • Loading branch information
mgropp committed May 6, 2024
1 parent 1195e71 commit 4594838
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.quickbirdstudios.nonEmptyCollection.list

import com.quickbirdstudios.nonEmptyCollection.NonEmptyCollection
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport

@OptIn(ExperimentalJsExport::class)
@JsExport
class NonEmptyList<out T> internal constructor(
internal val full: List<T>
) : List<T> by full, NonEmptyCollection<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

package com.quickbirdstudios.nonEmptyCollection.list

import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport

@OptIn(ExperimentalJsExport::class)
@JsExport
fun <T> nonEmptyListOf(value: T, vararg values: T) = nonEmptyListOf(value, values.asList())

fun <T> nonEmptyListOf(value: T, values: List<T>) = NonEmptyList(value, values)

@OptIn(ExperimentalJsExport::class)
@JsExport
fun <T : Any> nonEmptyListOfNotNull(
value: T,
vararg values: T?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.quickbirdstudios.nonEmptyCollection.set

import com.quickbirdstudios.nonEmptyCollection.NonEmptyCollection
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport

@OptIn(ExperimentalJsExport::class)
@JsExport
class NonEmptySet<out T> internal constructor(
internal val full: Set<T>
) : Set<T> by full, NonEmptyCollection<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

package com.quickbirdstudios.nonEmptyCollection.set

import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport

@OptIn(ExperimentalJsExport::class)
@JsExport
fun <T> nonEmptySetOf(value: T, vararg values: T) = nonEmptySetOf(value, values.toSet())

fun <T> nonEmptySetOf(value: T, values: Set<T>): NonEmptySet<T> = NonEmptySet(value, values)

@OptIn(ExperimentalJsExport::class)
@JsExport
fun <T : Any> nonEmptySetOfNotNull(
value: T,
vararg values: T?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@ import com.quickbirdstudios.nonEmptyCollection.unsafe.UnsafeNonEmptyCollectionAp
import com.quickbirdstudios.nonEmptyCollection.unsafe.toNonEmptyList
import com.quickbirdstudios.nonEmptyCollection.unsafe.toNonEmptyMap
import com.quickbirdstudios.nonEmptyCollection.unsafe.toNonEmptySet
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport

fun <T> List<T>.toNonEmptyListOrNull() = if (isEmpty()) null else toNonEmptyList()

fun <T> Set<T>.toNonEmptySetOrNull() = if (isEmpty()) null else toNonEmptySet()

fun <K, V> Map<K, V>.toNonEmptyMapOrNull() = if (isEmpty()) null else toNonEmptyMap()

@OptIn(ExperimentalJsExport::class)
@JsExport
fun <T> Array<T>.toNonEmptyListOrNull() = toList().toNonEmptyListOrNull()

@OptIn(ExperimentalJsExport::class)
@JsExport
fun <T> Array<T>.toNonEmptySetOrNull() = toSet().toNonEmptySetOrNull()

0 comments on commit 4594838

Please sign in to comment.