Stack at searcher
This commit is contained in:
132
lib/tester.dart
Normal file
132
lib/tester.dart
Normal file
@@ -0,0 +1,132 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dartsunfish/src/extentions.dart';
|
||||
|
||||
class MyItem {
|
||||
int id;
|
||||
String name;
|
||||
MyItem({
|
||||
required this.id,
|
||||
required this.name,
|
||||
});
|
||||
|
||||
MyItem copyWith({
|
||||
int? id,
|
||||
String? name,
|
||||
}) {
|
||||
return MyItem(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
};
|
||||
}
|
||||
|
||||
factory MyItem.fromMap(Map<String, dynamic> map) {
|
||||
return MyItem(
|
||||
id: map['id'],
|
||||
name: map['name'],
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory MyItem.fromJson(String source) => MyItem.fromMap(json.decode(source));
|
||||
|
||||
@override
|
||||
String toString() => 'MyItem(id: $id, name: $name)';
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is MyItem && other.id == id && other.name == name;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => id.hashCode ^ name.hashCode;
|
||||
}
|
||||
|
||||
void main(List<String> args) {
|
||||
final someList = List.generate(
|
||||
10,
|
||||
(i) => {
|
||||
{i, 's'}: 'See item $i'
|
||||
});
|
||||
|
||||
bool root = true;
|
||||
|
||||
final someSet = Set.from(List<MyItem>.generate(10, (index) => MyItem(id: index, name: 'name $index')).toSet());
|
||||
|
||||
print(someSet.contains(MyItem(id: 2, name: 'name 2')) && !root);
|
||||
|
||||
print(someList);
|
||||
final first = someList[0].get({0, 's'});
|
||||
print('I found $first');
|
||||
|
||||
final someMap = {
|
||||
{1, 'S1'}: 'See item 1',
|
||||
{2, 'S2'}: 'See item 1'
|
||||
};
|
||||
|
||||
var s1 = {
|
||||
1,
|
||||
'S1',
|
||||
22.23,
|
||||
['q', 12]
|
||||
};
|
||||
var s2 = {
|
||||
1,
|
||||
'S1',
|
||||
22.23,
|
||||
['q', 12]
|
||||
};
|
||||
|
||||
var s3 = {
|
||||
1: 'S1',
|
||||
22.23: ['q', 12]
|
||||
};
|
||||
var s4 = {
|
||||
1: 'S1',
|
||||
22.23: ['q', 12]
|
||||
};
|
||||
|
||||
print('Equality test gives ${s1.isEqual(s2)}');
|
||||
print('Equality test gives ${s3.isEqual(s4)}');
|
||||
|
||||
print(someMap.get({1, 'S2'}, or: 'Oops'));
|
||||
|
||||
var ff = someList.firstWhere((element) => element.get({1, 's'}) != null, orElse: () => someList[0]);
|
||||
// print('In map ${someMap.entries.toList()}');
|
||||
print('In map $ff');
|
||||
|
||||
for (var i in List.generate(10, (index) => index + 1)) {
|
||||
print('III = $i');
|
||||
}
|
||||
|
||||
Iterator<String> getStringIterator(String s) => s.runes.map((r) => String.fromCharCode(r)).iterator;
|
||||
|
||||
final str = 'Hello, World';
|
||||
|
||||
final strList = str.split('');
|
||||
|
||||
strList.forEachIndexed((e, i) {
|
||||
if (e != 'o') {
|
||||
print('See $e');
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
final strIter = getStringIterator(str);
|
||||
for (var i = 0; i < str.runes.length; i++) {
|
||||
strIter.moveNext();
|
||||
print('In map ${strIter.current}');
|
||||
print('And ${String.fromCharCode(str.runes.elementAt(i))}');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user