InputChannel

interface InputChannel<T : Any> : Channel<T>

A Channel a it.unibo.tuprolog.solve.Solver reads T-typed elements from, e.g. backing Prolog's read/1 or a solver's standard input.

Build one via the companion's stdIn (platform default standard input), of (wrapping a generator function or a fixed String).

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val available: Boolean

Whether an element is currently available to be read without blocking (implementation-dependent; may throw if the channel is closed, see it.unibo.tuprolog.solve.channel.impl.AbstractInputChannel).

Link copied to clipboard
abstract val isClosed: Boolean

Whether this channel has been closed.

Link copied to clipboard
abstract val isOver: Boolean

Whether this channel is exhausted, i.e. the next read would return null.

Link copied to clipboard
abstract val streamTerm: Struct

The Prolog $stream(Direction, Id)-like Struct term identifying this channel, e.g. for current_output/1.

Functions

Link copied to clipboard
abstract fun addListener(listener: Listener<T?>)

Registers listener to be invoked with every element subsequently transiting this channel.

Link copied to clipboard
abstract fun clearListeners()

Unregisters every currently-registered Listener.

Link copied to clipboard
abstract fun close()

Closes this channel; further reads/writes on it are expected to fail.

Link copied to clipboard
abstract fun peek(): T?

Reads, without consuming, the next element from this channel, or null if isOver.

Link copied to clipboard
abstract fun read(): T?

Reads and consumes the next element from this channel, or null if isOver.

Link copied to clipboard
abstract fun removeListener(listener: Listener<T?>)

Unregisters listener, previously added via addListener.

Link copied to clipboard
open fun <R> use(function: InputChannel<T>.() -> R): R

Runs function against this channel, closeing it once function returns normally (not on exceptions).