From 19cad53c8ab062df7e513e16ddfe0cc883b77330 Mon Sep 17 00:00:00 2001 From: Joannis Orlandos Date: Fri, 8 Sep 2017 09:22:21 +0200 Subject: [PATCH] streams --- 3.0/docs/async/stream.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/3.0/docs/async/stream.md b/3.0/docs/async/stream.md index 9f802253..62e3232e 100644 --- a/3.0/docs/async/stream.md +++ b/3.0/docs/async/stream.md @@ -97,13 +97,13 @@ Streams support two kinds of transforms. `flatMap` and `map`. Map transforms the // `flatMap`s the data into a `String?`. If the string results in `nil`, the resulting `stringStream` does not get called. // `stringStream` is a stream outputting `String` let stringStream = tcpStream.flatMap { bytes in - return String(bytes: bytes, encoding: self.encoding) + return String(bytes: bytes, encoding: .utf8) } // `map`s the data into a `String?`. If the string results in `nil`, the resulting `optionalStringStream` emits `nil`, too. // `optionalStringStream` is a stream outputting `String?` -let optionalStringStream = tcpStream.flatMap { bytes in - return String(bytes: bytes, encoding: self.encoding) +let optionalStringStream = tcpStream.map { bytes in + return String(bytes: bytes, encoding: .utf8) } ``` @@ -112,7 +112,7 @@ As you see, you an provide a closure to do the mapping for you. If you want to r ```swift // Creates a `String` from `ByteBuffer`. This can return `nil` if the `ByteBuffer` doesn't contain valid UTF-8 func utf8String(from bytes: ByteBuffer) -> String? { - return String(bytes: bytes, encoding: self.encoding) + return String(bytes: bytes, encoding: .utf8) } // `flatMap`s the data into a `String?`. If the string results in `nil`, the resulting `stringStream` does not get called. @@ -121,5 +121,5 @@ let stringStream = tcpStream.flatMap(utf8String) // `map`s the data into a `String?`. If the string results in `nil`, the resulting `optionalStringStream` emits `nil`, too. // `optionalStringStream` is a stream outputting `String?` -let optionalStringStream = tcpStream.flatMap(utf8String) +let optionalStringStream = tcpStream.map(utf8String) ```