All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.lancom.openapi.field.FieldSet.kt Maven / Gradle / Ivy

Go to download

This open-source project provides an OpenAPI 3.0 Parser implemented in Kotlin, utilizing immutable data classes

There is a newer version: 2.1.1
Show newest version
package de.lancom.openapi.field

internal fun  setField(value: T): Field {
    return FieldSet(value)
}

fun  List>.getFields(): List {
    return filterIsInstance>().map(FieldSet::value)
}

fun  Map>.getFields(): Map {
    return mapNotNull { (key, field) ->
        if (field is FieldSet) {
            key to field.value
        } else {
            null
        }
    }.toMap()
}

private data class FieldSet(
    val value: T
) : Field {
    @Suppress("UNCHECKED_CAST")
    override val optional: Field = this as Field

    override val isDefined: Boolean = true

    override val orNull: T
        get() = value

    override fun getOrError(): T {
        return value
    }

    override fun getOrElse(default: () -> T): T {
        return value
    }

    override fun orDefault(default: () -> T): Field {
        return this
    }

    override fun orElse(fallback: () -> Field): Field {
        return this
    }

    override fun  map(mapper: (T) -> E): Field {
        return Field(mapper(value))
    }

    override fun  flatMap(mapper: (T) -> Field): Field {
        return mapper(value)
    }

    override fun  mapField(mapper: (Field) -> E): Field {
        return Field(mapper(this))
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy