Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:async
  3. Stream<T>
  4. map<S> method
map
description

map<S> method

Stream<S>map<S>(
  1. Sconvert(
    1. Tevent
    )
)

Transforms each element of this stream into a new stream event.

Creates a new stream that converts each element of this streamto a new value using theconvert function, and emits the result.

For each data event,o, in this stream, the returned streamprovides a data event with the valueconvert(o).Ifconvert throws, the returned stream reports it as an errorevent instead.

Error and done events are passed through unchanged to the returned stream.

The returned stream is a broadcast stream if this stream is.Theconvert function is called once per data event per listener.If a broadcast stream is listened to more than once, each subscriptionwill individually callconvert on each data event.

Unliketransform, this method does not treat the stream aschunks of a single value. Instead each event is converted independentlyof the previous and following events, which may not always be correct.For example, UTF-8 encoding, or decoding, will give wrong resultsif a surrogate pair, or a multibyte UTF-8 encoding, is split intoseparate events, and those events are attempted encoded or decodedindependently.

Example:

final stream =    Stream<int>.periodic(const Duration(seconds: 1), (count) => count)        .take(5);final calculationStream =    stream.map<String>((event) => 'Square: ${event * event}');calculationStream.forEach(print);// Square: 0// Square: 1// Square: 4// Square: 9// Square: 16

Implementation

Stream<S> map<S>(S convert(T event)) {  return _MapStream<T, S>(this, convert);}
  1. Dart
  2. dart:async
  3. Stream<T>
  4. map<S> method
Stream class

[8]ページ先頭

©2009-2025 Movatter.jp