work in progress on examples
This commit is contained in:
@@ -1,15 +1,15 @@
|
|||||||
open class IEquality {
|
trait IEquality {
|
||||||
fun equals(other : Any) : Boolean
|
fun equals(other : Any) : Boolean
|
||||||
= (this as java.lang.Object).equals(other as java.lang.Object)
|
= (this as java.lang.Object).equals(other as java.lang.Object)
|
||||||
}
|
}
|
||||||
|
|
||||||
open class IHashable : IEquality {
|
trait IHashable : IEquality {
|
||||||
val hashCode : Integer
|
val hashCode : Integer
|
||||||
get() = (this as java.lang.Object).hashCode()
|
get() = (this as java.lang.Object).hashCode()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open class IMap<K, V> {
|
trait IMap<K : IHashable, V> {
|
||||||
fun get(key : K) : V
|
fun get(key : K) : V
|
||||||
fun set(key : K, value : V) : V
|
fun set(key : K, value : V) : V
|
||||||
fun remove(key : K) : V
|
fun remove(key : K) : V
|
||||||
@@ -21,7 +21,7 @@ class HashableWrapper wraps (val obj : Any) : IHashable
|
|||||||
|
|
||||||
[inline] fun Any.hashable() : HashableWrapper = new HashableWrapper(this)
|
[inline] fun Any.hashable() : HashableWrapper = new HashableWrapper(this)
|
||||||
|
|
||||||
open class IHashingStrategy<K> {
|
trait IHashingStrategy<K : IHashable> {
|
||||||
fun equals(a : K, b : K) : Boolean
|
fun equals(a : K, b : K) : Boolean
|
||||||
fun hashCode(a : K) : Integer
|
fun hashCode(a : K) : Integer
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
open class IIterable<out T> {
|
|
||||||
fun iterator() : IIterator<T>
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace jet.collections.iterable
|
||||||
|
|
||||||
|
import jet.collections.iterator.IIterator
|
||||||
|
|
||||||
|
trait IIterable<out T> {
|
||||||
|
fun iterator() : IIterator<T>
|
||||||
|
|
||||||
|
inline fun foreach(operation: fun(element: T) : Unit) = iterator() foreach operation
|
||||||
|
}
|
||||||
@@ -1,7 +1,21 @@
|
|||||||
open class IIterator<out T> {
|
namespace jet.collections.iterator
|
||||||
|
|
||||||
|
trait IIterator<out T> {
|
||||||
fun next() : T
|
fun next() : T
|
||||||
val hasNext : Boolean
|
val hasNext : Boolean
|
||||||
|
|
||||||
|
inline fun foreach(operation: fun(element: T) : Unit) = while(hasNext) operation(next())
|
||||||
|
|
||||||
|
inline fun <R> map(transform: fun(element: T) : R) : IIterator<R> {
|
||||||
|
val that = this
|
||||||
|
return object : IIterator<R> {
|
||||||
|
override fun next() : R = transform(that.next())
|
||||||
|
|
||||||
|
override val hasNext : Boolean
|
||||||
|
get() = that.hasNext
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
fun toArray(buffer : MutableArray<in T>) : Int { // T is still an in-parameter
|
fun toArray(buffer : MutableArray<in T>) : Int { // T is still an in-parameter
|
||||||
return fillBuffer(buffer, 0, buffer.size)
|
return fillBuffer(buffer, 0, buffer.size)
|
||||||
}
|
}
|
||||||
@@ -22,4 +36,5 @@ open class IIterator<out T> {
|
|||||||
}
|
}
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
open class IList<out T> : IIterable<T>, ISized {
|
|
||||||
[operator] fun get(index : Int) : T
|
|
||||||
val isEmpty : Boolean
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
trait IList<out T> : IIterable<T>, ISized {
|
||||||
|
fun get(index : Int) : T
|
||||||
|
}
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
open class ISet<T> : IIterable<T>, ISized {
|
|
||||||
fun contains(item : T) : Boolean
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace jet.collections.set
|
||||||
|
|
||||||
|
import jet.collections.sized.ISized
|
||||||
|
import jet.collections.iterable.IIterable
|
||||||
|
|
||||||
|
trait ISet<T> : IIterable<T>, ISized {
|
||||||
|
fun contains(item : T) : Boolean
|
||||||
|
}
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
open class ISized {
|
|
||||||
val size : Int
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,11 @@
|
|||||||
|
namespace jet.collections.sized
|
||||||
|
|
||||||
trait ISized {
|
trait ISized {
|
||||||
val size : Int
|
val size : Int
|
||||||
|
|
||||||
|
val isEmpty : Boolean
|
||||||
|
get() = size == 0
|
||||||
|
|
||||||
|
val isNonEmpty : Boolean
|
||||||
|
get() = size != 0
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user