Last active
June 9, 2020 04:50
-
-
Save ha-yi/6eadae81bead7f31c004d4f508833ee7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:test/test.dart'; | |
extension ListExt<T> on List<T> { | |
/// Remove an object from | |
operator -(T other) async { | |
this.remove(other); | |
return this; | |
} | |
/// Remove all objects in array | |
operator ~/(List<T> other) { | |
other.forEach((e) => this.remove(e)); | |
return this; | |
} | |
bool all(bool Function(T) varificator) { | |
for(T data in this) { | |
if (!varificator.call(data)) return false; | |
} | |
return true; | |
} | |
} | |
void main() { | |
test("Test minus operator", () { | |
List<String> data = ["A" , "B", "C", "D"]; | |
var newlist = data - "A"; | |
assert(!newlist.contains("A")); | |
}); | |
test("Test Remove all object", () { | |
List<String> data = ["A" , "B", "C", "D"]; | |
var newlist = data ~/ ["A", "B"]; | |
assert(!newlist.contains("A")); | |
assert(!newlist.contains("B")); | |
}); | |
test("Test all method", (){ | |
List<String> data = ["A" , "B", "C", "D"]; | |
var allSingleChar = data.all((e) => e.length == 1); | |
assert(allSingleChar); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment