Skip to content

Instantly share code, notes, and snippets.

@wyattbiker
Created May 8, 2019 15:02
Show Gist options
  • Save wyattbiker/5062f063ecb7724a244b73fa58413c66 to your computer and use it in GitHub Desktop.
Save wyattbiker/5062f063ecb7724a244b73fa58413c66 to your computer and use it in GitHub Desktop.
yield examples
import 'dart:math' as m;
class Animal {
void chase(Animal x) {
print("Animal $x");
}
}
class Mouse extends Animal {}
class Cat extends Mouse {
int _x = 5;
set x(int m) {
_x = m;
}
int get x {
return _x;
}
void chase(Animal x) {
print("x: ${x}");
}
}
class Person {
String firstName;
Person.fromJson(Map data) {
firstName = data['first'];
print('in Person $firstName');
}
}
class Employee extends Person {
// Person does not have a default constructor;
// you must call super.fromJson(data).
int x;
int y;
Employee.fromJson(Map data)
: x = 10,
y = 20,
super.fromJson(data) {
print(this.x);
print('in Employee $firstName');
}
}
add(a, b) {
print(a + b);
}
Stream<int> naturalsTo(List<int> list) async* {
for (int s in list) {
s++;
yield s;
}
}
void main() async {
var x = naturalsTo([1, 2, 3, 4]);
print(x.toList());
// var emp = new Employee.fromJson({'first':'Me'});
// print(emp.x);
// print(emp.y);
// print("1234".substring(0,2));
// emp.firstName='John';
// // Prints:
// // in Person
// // in Employee
// if (emp is Person) {
// // Type check
// emp.firstName = 'Bob';
// }
// emp.firstName = 'Bob';
// add(1,2);
// var c = Cat();
// var m = Mouse();
// c.chase(m);
// print(int.parse('0x10abc'));
// print(10.toString());
// var calc = 17.7;
// print(calc);
// print(calc % 5);
// print(calc.remainder(5));
// double amount=calc + 3.0;
// print(amount.runtimeType);
// amount = 10.2;
// print(amount.runtimeType);
// int quantity=(10.2).floor();
// print(quantity);
// var myText = "Hello Text";
// print(myText);
// print("The power of calc is: ${calc}");
// print("The power of calc is: ${10}");
// var s1="Hello";
// var s2="World";
// print(s1+" "+s2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment