Skip to content

Instantly share code, notes, and snippets.

@Sfshaza
Sfshaza / index.html
Last active June 27, 2018 16:22
portmanteaux
<!DOCTYPE html>
<!--
Copyright (c) 2012, the Dart project authors.
Please see the AUTHORS file for details.
All rights reserved. Use of this source code
is governed by a BSD-style license that can be
found in the LICENSE file.
-->
@Sfshaza
Sfshaza / index.html
Last active June 27, 2018 15:08
portmanteaux_simple
<!DOCTYPE html>
<!--
Copyright (c) 2012, the Dart project authors.
Please see the AUTHORS file for details.
All rights reserved. Use of this source code
is governed by a BSD-style license that can be
found in the LICENSE file.
-->
@Sfshaza
Sfshaza / index.html
Last active June 26, 2018 13:13
its_all_about_you
<!DOCTYPE html>
<!--
Copyright (c) 2012, the Dart project authors.
Please see the AUTHORS file for details.
All rights reserved. Use of this source code
is governed by a BSD-style license that can be
found in the LICENSE file.
-->
@Sfshaza
Sfshaza / main.dart
Last active May 3, 2018 23:57
Java-to-Dart codelab: Scream example - functional code using Iterables
String scream(int length) {
return "A${'a' * length}h!";
}
main() {
var values = [1, 2, 3, 5, 10, 50];
values.skip(1).take(3).map(scream).forEach(print);
}
@Sfshaza
Sfshaza / main.dart
Last active May 3, 2018 23:51
Java-to-Dart codelab: Scream example - functional code
String scream(int length) {
return "A${'a' * length}h!";
}
main() {
var values = [1, 2, 3, 5, 10, 50];
values.map(scream).forEach(print);
}
@Sfshaza
Sfshaza / main.dart
Last active May 3, 2018 23:48
Java-to-Dart codelab: Scream example - imperative code
String scream(int length) {
return "A${'a' * length}h!";
}
main() {
var values = [1, 2, 3, 5, 10, 50];
for (var length in values) {
print(scream(length));
}
}
@Sfshaza
Sfshaza / main.dart
Last active May 3, 2018 23:33
Java-to-Dart codelab: CircleMock example
import 'dart:math';
abstract class Shape {
factory Shape(String type) {
if (type == "circle") return new Circle(2);
if (type == "square") return new Square(2);
throw new ArgumentError("Can't create $type.");
}
num get area;
}
@Sfshaza
Sfshaza / main.dart
Last active May 3, 2018 23:26
Java-to-Dart codelab: Factory constructor
import 'dart:math';
abstract class Shape {
factory Shape(String type) {
if (type == 'circle') return new Circle(2);
if (type == 'square') return new Square(2);
throw 'Can\'t create $type.';
}
num get area;
}
@Sfshaza
Sfshaza / main.dart
Last active May 3, 2018 23:13
Java-to-Dart codelab: Top-level factory function
import 'dart:math';
abstract class Shape {
num get area;
}
class Circle implements Shape {
final num radius;
Circle(this.radius);
num get area => PI * pow(radius, 2);
@Sfshaza
Sfshaza / main.dart
Last active May 3, 2018 22:04
Java-to-Dart codelab: Starting Shapes example
import 'dart:math';
abstract class Shape {
num get area;
}
class Circle implements Shape {
final num radius;
Circle(this.radius);
num get area => PI * pow(radius, 2);