removed unused files

This commit is contained in:
Niklas Kapelle 2024-08-13 00:10:47 +02:00
parent fe16799bbb
commit be58ed1c05
Signed by: niklas
GPG Key ID: 4EB651B36D841D16
6 changed files with 0 additions and 213 deletions

View File

@ -1,69 +0,0 @@
package lib;
import haxe.Exception;
class LambdaExtender {
/**
Returns the first element if there are exectly one element present.
Throws exception if not.
**/
static public function single<T>(it:Iterable<T>):T {
var elem:T = null;
for (t in it) {
if (elem != null) {
throw new Exception("Multiple elements found");
}
elem = t;
}
if (elem == null) {
throw new Exception("No element found");
}
return elem;
}
/**
Like `single` but when no element was found return the default value.
**/
static public function singleOrDefault<T>(it:Iterable<T>, defaultValue:T):T {
var elem:T = null;
for (t in it) {
if (elem != null) {
throw new Exception("Multiple elements found");
}
elem = t;
}
if (elem == null) {
return defaultValue;
}
return elem;
}
/**
Returns the first element.
Throws execption if no first element found.
**/
static public function first<T>(it:Iterable<T>):T {
for (t in it) {
return t;
}
throw new Exception("No element found");
}
/**
Like `first` only if no first element was found it returns the defalt value.
**/
static public function firstOrDefault<T>(it:Iterable<T>, defaultValue:T):T {
var iter = it.iterator();
if (iter.hasNext()) {
return iter.next();
}
return defaultValue;
}
}

View File

@ -1,24 +0,0 @@
package lib;
class ObjMerge {
public static function merge<T>(obj1:T, obj2:T):T {
if (obj1 == null) {
return obj2;
}
if (obj2 == null) {
return obj1;
}
var rtn:T = Reflect.copy(obj1);
var fields = Reflect.fields(obj2);
for (field in fields) {
if (Reflect.getProperty(obj1, field) == null) {
Reflect.setProperty(rtn, field, Reflect.getProperty(obj2, field));
}
}
return (rtn : T);
}
}

View File

@ -1,27 +0,0 @@
package lib.observable;
using tink.CoreApi;
class DummyObservable<T> implements IObservable<T> {
private var value:T;
private function new(value:T) {
this.value = value;
}
public function set(value:T) {
throw new haxe.exceptions.NotImplementedException();
}
public function get():T {
return this.value;
}
public function subscribe(callback:Callback<T>):CallbackLink {
return null;
}
public static function dummy<T>(value:T):IObservable<T> {
return new DummyObservable<T>(value);
}
}

View File

@ -1,9 +0,0 @@
package lib.observable;
using tink.CoreApi;
interface IObservable<T> {
public function set(value:T):Void;
public function get():T;
public function subscribe(callback:Callback<T>):CallbackLink;
}

View File

@ -1,56 +0,0 @@
package lib.observable;
class ObservableArray<T> extends ObservableValue<Array<T>> {
public function new(value:Array<T>) {
super(value);
}
public function insert(pos:Int, x:T):Void {
this.value.insert(pos, x);
this.callbacks.invoke(this.value);
}
public function pop():Null<T> {
var poped = this.pop();
this.callbacks.invoke(this.value);
return poped;
}
public function push(x:T):Int {
var i = this.value.push(x);
this.callbacks.invoke(this.value);
return i;
}
public function remove(x:T):Bool {
var b = this.value.remove(x);
this.callbacks.invoke(this.value);
return b;
}
public function resize(len:Int) {
this.value.resize(len);
this.callbacks.invoke(this.value);
}
public function reverse() {
this.value.reverse();
this.callbacks.invoke(this.value);
}
public function shift():Null<T> {
var e = this.value.shift();
this.callbacks.invoke(this.value);
return e;
}
public function sort(f:(T, T) -> Int):Void {
this.value.sort(f);
this.callbacks.invoke(this.value);
}
public function unshift(x:T):Void {
this.value.unshift(x);
this.callbacks.invoke(this.value);
}
}

View File

@ -1,28 +0,0 @@
package lib.observable;
using tink.CoreApi;
class ObservableValue<T> implements IObservable<T> {
private var value:T;
private var callbacks:CallbackList<T> = new CallbackList();
public function new(value:T) {
this.value = value;
}
public function set(value:T) {
if (value != this.value) {
this.value = value;
callbacks.invoke(value);
}
}
public function get():T {
return value;
}
public function subscribe(callback:Callback<T>):CallbackLink {
callback.invoke(value);
return callbacks.add(callback);
}
}