live local search

todos

improve local search
This commit is contained in:
Mguy13 2022-12-23 20:45:30 +01:00
parent 4ade7f1682
commit a0ed894016
9 changed files with 151 additions and 42 deletions

View file

@ -1,3 +1,6 @@
extension MapExtensions<A, B> on Map<A, B> {
Map<A, B> get deepCopy => {...this};
/// Returns the values of a [Map] at given [keys] indices.
Iterable<B> valuesByKeys({required Iterable<A> keys}) => keys.map((final key) => this[key]!);
}

View file

@ -0,0 +1,8 @@
extension ObjectExtensions on Object? {
E asType<E>() => this as E;
E? asNullableType<E>() => this as E?;
}
extension AsCallback<T extends Object> on T {
T Function() get asCallback => () => this;
}

View file

@ -0,0 +1,14 @@
extension StringExtensions on String {
/// Returns true if given word contains atleast all the characters in [targetChars], and `false` otherwise
///
/// Very efficient `O(n)` instead of naive `O(n*m)`
bool containsAllCharacters({required String targetChars}) {
final Set<String> characterSet = Set.from(targetChars.split(''));
for (final testChar in split('')) {
characterSet.remove(testChar);
if (characterSet.isEmpty) return true;
}
return false;
}
}