diff --git a/src/utils/datastructures/LinkedList.ts b/src/utils/datastructures/LinkedList.ts index 46a2fb3..37c193e 100644 --- a/src/utils/datastructures/LinkedList.ts +++ b/src/utils/datastructures/LinkedList.ts @@ -48,6 +48,15 @@ class LinkedList { this.linkToTail(entity); } + find(predicate: (entity: T) => boolean): T | null { + for (const entity of this) { + if (predicate(entity)) { + return entity; + } + } + return null; + } + isLinked(entity: T) { return this.linkFor(entity).isLinked; } @@ -98,6 +107,14 @@ class LinkedList { } } + toString(callback: (entity: T) => string) { + const result = []; + for (const entity of this) { + result.push(callback(entity)); + } + return `[${result.join(', ')}]`; + } + unlink(entity: T) { return this.linkFor(entity).unlink(); }