diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/Featured.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/Featured.kt index 648b6376f..be1c8380c 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/Featured.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/Featured.kt @@ -16,13 +16,14 @@ public interface Featured { public typealias FeatureKey = KClass -public interface Feature> { +public interface Feature> { /** * A key used for extraction */ @Suppress("UNCHECKED_CAST") - public val key: FeatureKey get() = this::class as FeatureKey + public val key: FeatureKey + get() = this::class as FeatureKey } /** @@ -30,7 +31,7 @@ public interface Feature> { */ public class FeatureSet> private constructor(public val features: Map, F>) : Featured { @Suppress("UNCHECKED_CAST") - override fun getFeature(type: FeatureKey): T? = features[type] as? T + override fun getFeature(type: FeatureKey): T? = features[type]?.let { it as T } public inline fun getFeature(): T? = getFeature(T::class) @@ -49,6 +50,7 @@ public class FeatureSet> private constructor(public val features: public companion object { public fun > of(vararg features: F): FeatureSet = FeatureSet(features.associateBy { it.key }) - public fun > of(features: Iterable): FeatureSet = FeatureSet(features.associateBy { it.key }) + public fun > of(features: Iterable): FeatureSet = + FeatureSet(features.associateBy { it.key }) } }