Skip to content

Instantly share code, notes, and snippets.

@RileySeaburg
Created August 12, 2022 04:10
Show Gist options
  • Save RileySeaburg/e530228d68ea8a33e188bbc65b630413 to your computer and use it in GitHub Desktop.
Save RileySeaburg/e530228d68ea8a33e188bbc65b630413 to your computer and use it in GitHub Desktop.
Stream 'Take' and 'Where' Functions in Dart
<form>
<h4>Guess the Word<h4>
<input/>
<button>Guess</button>
</form>
import 'dart:html';
void main() {
final ButtonElement button = querySelector('button') as ButtonElement;
final InputElement input = querySelector('input') as InputElement;
button.onClick
/// Stream Method Take https://api.dart.dev/stable/2.17.6/dart-async/Stream/take.html
.take(4)
/// Where Method
/// Example
/// ```dart
/// final stream =
/// Stream<int>.periodic(const Duration(seconds: 1), (count) => count)
/// .take(10);
/// final customStream = stream.where((event) => event > 3 && event <= 6);
/// customStream.listen(print); // Outputs event values: 4,5,6.
/// ```
/// https://api.dart.dev/stable/2.17.6/dart-async/Stream/where.html
.where((event) => input.value == "balloon")
/// Listen Method
/// API Documentation:
/// https://api.dart.dev/stable/2.17.6/dart-async/Stream/listen.html
.listen(
(event) => print("This is sparta!, JK You guessed it!"),
onDone: () => print("You Lost!")
);
}
h4 {
color: white;
}
form{
display: flex;
flex-direction: column;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment