Skip to content

[Dispatch][gardening] Use Optional.map over flatMap where appropriate #15142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stdlib/public/SDK/Dispatch/IO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public extension DispatchIO {

public class func write(toFileDescriptor: Int32, data: DispatchData, runningHandlerOn queue: DispatchQueue, handler: @escaping (_ data: DispatchData?, _ error: Int32) -> Void) {
__dispatch_write(toFileDescriptor, data as __DispatchData, queue) { (data: __DispatchData?, error: Int32) in
handler(data.flatMap { DispatchData(data: $0) }, error)
handler(data.map { DispatchData(data: $0) }, error)
}
}

Expand Down Expand Up @@ -88,13 +88,13 @@ public extension DispatchIO {

public func read(offset: off_t, length: Int, queue: DispatchQueue, ioHandler: @escaping (_ done: Bool, _ data: DispatchData?, _ error: Int32) -> Void) {
__dispatch_io_read(self, offset, length, queue) { (done: Bool, data: __DispatchData?, error: Int32) in
ioHandler(done, data.flatMap { DispatchData(data: $0) }, error)
ioHandler(done, data.map { DispatchData(data: $0) }, error)
}
}

public func write(offset: off_t, data: DispatchData, queue: DispatchQueue, ioHandler: @escaping (_ done: Bool, _ data: DispatchData?, _ error: Int32) -> Void) {
__dispatch_io_write(self, offset, data as __DispatchData, queue) { (done: Bool, data: __DispatchData?, error: Int32) in
ioHandler(done, data.flatMap { DispatchData(data: $0) }, error)
ioHandler(done, data.map { DispatchData(data: $0) }, error)
}
}

Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/SDK/Dispatch/Queue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ public extension DispatchQueue {

public func setSpecific<T>(key: DispatchSpecificKey<T>, value: T?) {
let k = Unmanaged.passUnretained(key).toOpaque()
let v = value.flatMap { _DispatchSpecificValue(value: $0) }
let p = v.flatMap { Unmanaged.passRetained($0).toOpaque() }
let v = value.map { _DispatchSpecificValue(value: $0) }
let p = v.map { Unmanaged.passRetained($0).toOpaque() }
__dispatch_queue_set_specific(self, k, p, _destructDispatchSpecificValue)
}
}
Expand Down