Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
99 lines (89 sloc) 2.24 KB
from helpertypes import Tuple
/**
* Stringable marks a type as being convertable into a string.
*/
@•typealias('stringable')
interface Stringable {
/**
* String returns the string form of the instance.
*/
function String() string
}
/**
* MapStream runs a mapping function over a `stream`, returning a stream of the values transformed
* by the `mapper` function.
*/
function MapStream<T, Q>(stream T*, mapper function<Q>(T)) Q* {
for item in stream {
yield mapper(item)
}
}
/**
* Stream defines a stream of values of a type.
*/
@•typealias('stream')
interface Stream<T> {
/**
* Next returns a Tuple containing the next value in the stream (if any). If none, the boolean
* of the tuple is false.
*/
function Next() Tuple<T, bool>
}
/**
* Streamable marks a type as supporting being convertable into a stream.
*/
@•typealias('streamable')
interface Streamable<T> {
/**
* Stream returns the stream form of the instance.
*/
function Stream() Stream<T>
}
/**
* Mappable marks a type as supporting being used as a key in a Map.
*/
@•typealias('mappable')
interface Mappable {
/**
* MapKey returns the stringable mapping key for this type. This key should be unique
* for instances that are the same.
*/
property MapKey Stringable { get }
}
/**
* Awaitable defines an interface for awaiting the result of an async operation.
*/
@•typealias('awaitable')
interface Awaitable<T> {
/**
* Then registers a `callback` to invoked with the async result once the operation
* completes successfully.
*/
function Then(callback function<void>(T)) Awaitable<T>
/**
* Catch registers a `callback` to invoked with the error if the operation
* fails to complete successfully.
*/
function Catch(callback function<void>(error)) Awaitable<T>
}
/**
* Error defines an error raised by a promise or a reject keyword.
*/
@•typealias('error')
interface Error {
/**
* Message defines the error's human-readable message.
*/
property Message string { get }
}
/**
* Releasable defines an interface for a type that can be used via a 'with' keyword.
*/
@•typealias('releasable')
interface Releasable {
/**
* Release defines the function invoked once the resource has left the scope of the
* with block.
*/
function Release()
}
You can’t perform that action at this time.