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

jvmMain.it.unibo.tuprolog.serialize.WritingSerializer.kt Maven / Gradle / Ivy

The newest version!
package it.unibo.tuprolog.serialize

import java.io.StringWriter
import java.io.Writer

interface WritingSerializer : Serializer {
    fun serialize(
        writer: Writer,
        value: T,
    )

    override fun serialize(value: T): String =
        StringWriter().use {
            serialize(it, value)
            it.toString()
        }

    fun serializeMany(
        writer: Writer,
        vararg values: T,
    ) = serializeMany(writer, listOf(*values))

    fun serializeMany(
        writer: Writer,
        values: Iterable,
    )

    override fun serializeMany(values: Iterable): String =
        StringWriter().use {
            serializeMany(it, values)
            it.toString()
        }

    fun serializeMany(
        writer: Writer,
        values: Sequence,
    ) = serializeMany(writer, values.asIterable())
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy