Skip to content

Commit

Permalink
Add findIndex to Vector
Browse files Browse the repository at this point in the history
  • Loading branch information
Gene Pavlovsky committed Feb 26, 2024
1 parent c4ea063 commit bd3c8d3
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/tink/pure/Vector.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,25 @@ abstract Vector<T>(Array<T>) to Vectorlike<T> to Iterable<T> {
a.sort(compare);
return new Vector(a);
}

public inline function slice(pos, end)
return new Vector(this.slice(pos, end));

public inline function count(f)
return Lambda.count(this, f);

public inline function exists(f)
return Lambda.exists(this, f);

public inline function find(f)
return Lambda.find(this, f);


public inline function findIndex(f)
return Lambda.findIndex(this, f);

public inline function fold<R>(f:(v:T, result:R)->R, init:R)
return Lambda.fold(this, f, init);

public inline function with(index:Int, value:T):Vector<T> {
final arr = this.copy();
arr[index] = value;
Expand All @@ -62,7 +65,7 @@ abstract Vector<T>(Array<T>) to Vectorlike<T> to Iterable<T> {
@:op(a & b)
static inline function lconcat<T>(a:Vectorlike<T>, b:Vector<T>)
return new Vector(a.concat(b.unwrap()));

static public inline function empty<T>():Vector<T> {
return new Vector<T>([]);
}
Expand Down Expand Up @@ -103,7 +106,7 @@ abstract Vector<T>(Array<T>) to Vectorlike<T> to Iterable<T> {
typed = typeExpr(e);
stored = storeTypedExpr(typed);
}

return switch typed.expr {
case TArrayDecl(_) | TNew(_.get() => {pack: [], name: 'Array'}, [_], []):
macro @:pos(e.pos) @:privateAccess new tink.pure.Vector($stored);
Expand Down

0 comments on commit bd3c8d3

Please sign in to comment.