amazon-ion / ion-element-kotlin

IonElement is an immutable in-memory representation of the Ion data format. IonElement's API is idiomatic to Kotlin.
Apache License 2.0
8 stars 7 forks source link

Consider adding `ElementType` to replace IonJava's `IonType` #13

Closed dlurton closed 4 years ago

dlurton commented 4 years ago

Problems with IonType:

It might be better to have ElementType, something like:

enum class ElementType(
    val isText: Boolean, 
    val isSequence: Boolean, 
    val isBinary: Boolean
) {
    NULL(false false false),
    BOOL(false, false false),
    INT(false, false false)
    FLOAT(false, false false)
    DECIMAL(false, false false)
    TIMESTAMP(false, false false)
    SYMBOL(true false false)
    STRING(true, false false),
    CLOB(false, false, true),
    BLOB(false, false, true),
    LIST(false, true, false,
    SEXP(false, true, false),
    STRUCT(false, true, false);

    /** Converts this [ElementType] to [IonType]. */
    fun toIonType(type: IonType) = when(this) { ... } 
}

/** Converts this [IonType] to [ElementType]. */
fun IonType.toElementType() = when(this) { ... } 

Then instead of:

if(IonType.isText(element.type)) { ... }

We can:

if(element.type.isText) { ... }