Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
82 lines (70 sloc) 1.62 KB
from webidl`core` import Error as NativeError
/**
* Tuple represents a simple tuple of two values.
*/
@•typealias('tuple')
class Tuple<T, Q> {
/**
* First is the first value in the tuple.
*/
var First T? = null
/**
* Second is the second value in the tuple.
*/
var Second Q? = null
/**
* Build constructs a tuple of the `first` and `second` values.
*/
constructor Build(first T?, second Q?) {
var tuple = Tuple<T, Q>.new()
tuple.First = first
tuple.Second = second
return tuple
}
}
/**
* IntStream represents a stream of integers.
*/
@•typealias('$intstream')
class IntStream {
var start int
var end int
var current int
/**
* OverRange returns a stream over the range of integers found between `start` and `end`, **inclusive**.
*/
constructor OverRange(start int, end int) {
return IntStream{start: start, end: end, current: start}
}
function Next() Tuple<int, bool> {
if this.current <= this.end {
var t = Tuple<int, bool>.Build(this.current, true)
this.current = this.current + 1
return t
}
return Tuple<int, bool>.Build(this.current, false)
}
}
/**
* SimpleError defines an error that merely wraps a string message.
*/
type SimpleError : string {
constructor WithMessage(message string) {
return SimpleError(message)
}
property Message string {
get { return string(this) }
}
}
/**
* WrappedError wraps a native error into matching the Error interface.
*/
@•typealias('wrappederror')
type WrappedError : NativeError {
constructor For(err NativeError) {
return WrappedError(err)
}
property Message string {
get { return string(NativeError(this).message) }
}
}
You can’t perform that action at this time.