This file contains 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 '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"); |
This file contains 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 '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"), |
This file contains 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 '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( |
This file contains 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
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 -> { |
This file contains 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
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")) | |
} |
This file contains 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
fun main(args: Array<String>) { | |
val basicScreenState = BasicScreenState.ERROR | |
setBasicScreenState(basicScreenState) | |
} | |
enum class BasicScreenState { | |
ERROR, | |
LOADING, | |
DATA | |
} | |
fun setBasicScreenState(basicScreenState: BasicScreenState) { |
This file contains 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
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}" |
This file contains 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
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}" |
This file contains 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
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) | |
} |
This file contains 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 '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); | |
}, |
NewerOlder