Created
October 17, 2021 06:19
-
-
Save meki/89be289fe87784a9d6bc73256920eb30 to your computer and use it in GitHub Desktop.
BLoK example
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
// forked from https://qiita.com/kabochapo/items/8738223894fb74f952d3 | |
import 'dart:async'; | |
void main() { | |
final data = {'イチゴ': '苺', 'イチジク': '無花果', 'リンゴ': '林檎'}; | |
final controller = StreamController<String>(); | |
controller.sink.add('イチゴ'); | |
controller.sink.add('ドラゴンフルーツ'); | |
controller.sink.add('イチジク'); | |
controller.sink.add('リンゴ'); | |
controller.sink.add('オレンジ'); | |
final toKanji = StreamTransformer<String, String>.fromHandlers( | |
handleData: (value, sink) { | |
if (data.containsKey(value) && (data[value] != null)) { | |
sink.add(data[value]!); | |
} else { | |
sink.addError('$value の漢字は不明です'); | |
} | |
} | |
); | |
controller.stream | |
.transform(toKanji) | |
.listen( | |
(value) { print(value); }, | |
onError: (err) { print('[エラー] $err'); } | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment