Skip to content

Instantly share code, notes, and snippets.

Avatar

Myanmar Links myanmarlinks

View GitHub Profile
View stream_transformers.dart
import 'dart:async';
main(List<String> arguments) {
var controller = StreamController<String>.broadcast();
var streamTransformer = StreamTransformer<String, String>.fromHandlers(
handleData: (String data, EventSink sink) {
switch(data) {
case "fool":
sink.add("You $data");
View broadcast_streamcontroller.dart
import 'dart:async';
void main() {
var streamController = StreamController<String>.broadcast(
onListen: () => print('onListen'),
onCancel: () => print("onCancel"),
);
StreamSubscription sub = streamController.stream.listen(
(data) => print('Got $data'),
onError: (err) => print("Got $err"),
View stream_controller.dart
import 'dart:async';
void main() {
var streamController = StreamController<String>(
onListen: () => print('onListen'),
onCancel: () => print("onCancel"),
onPause: () => print("onPause"),
onResume: () => print("onResume")
);
StreamSubscription sub = streamController.stream.listen(
View sealed_classes_5.kt
fun main(args: Array<String>) {
val screenState = ScreenState.Data(SomeData(1, "Hello World"))
setScreenState(screenState)
}
fun setScreenState(screenState: ScreenState) {
when(screenState) {
is ScreenState.Error -> println("Error")
is ScreenState.Loading -> println("Loading")
is ScreenState.Data -> {
View sealed_classes_4.kt
data class SomeData(val id: Int, val name: String)
enum class ScreenStateField(val someData: SomeData) {
ERROR(SomeData(1, "some data 1")),
LOADING(SomeData(2, "some data 2")),
DATA(SomeData(3, "some data 3"))
}
View sealed_classes_3.kt
fun main(args: Array<String>) {
val basicScreenState = BasicScreenState.ERROR
setBasicScreenState(basicScreenState)
}
enum class BasicScreenState {
ERROR,
LOADING,
DATA
}
fun setBasicScreenState(basicScreenState: BasicScreenState) {
View sealed_classes_2.kt
fun main(args: Array<String>) {
val mammal: Human = Human("John Doe","CEO")
println(greetMammal(mammal))
val cat = Cat("Shwe War")
println(greetMammal(cat))
}
fun greetMammal(mammal: Mammal): String {
when(mammal) {
is Human -> return "Hello ${mammal.name}; You're working as a ${mammal.job}"
@myanmarlinks
myanmarlinks / sealed_classes.kt
Created Jul 8, 2019
Bridge to Kotlin Part 8
View sealed_classes.kt
fun main(args: Array<String>) {
val mammal: Human = Human("John Doe","CEO")
println(greetMammal(mammal))
val cat = Cat("Shwe War")
println(greetMammal(cat))
}
fun greetMammal(mammal: Mammal): String {
when(mammal) {
is Human -> return "Hello ${mammal.name}; You're working as a ${mammal.job}"
@myanmarlinks
myanmarlinks / enum_class.kt
Created Jul 8, 2019
Bridge to Kotlin Part 8
View enum_class.kt
fun main(args: Array<String>) {
val myToday = MyDays.SUN
when(myToday) {
MyDays.SUN -> println(myToday)
}
val today = Days.SAT
when(today) {
Days.SAT -> println(Days.SAT.value)
}
View main.dart
import 'dart:async';
void main() {
var controller = StreamController<num>();
// Create StreamTransformer with transformer closure
var streamTransformer = StreamTransformer<num, num>.fromHandlers(
handleData: (num data, EventSink sink) {
sink.add(data * 2);
},