Skip to content
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

[SR-7523] flatMap should be compact map in specific case #50065

Open
swift-ci opened this issue Apr 24, 2018 · 4 comments
Open

[SR-7523] flatMap should be compact map in specific case #50065

swift-ci opened this issue Apr 24, 2018 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-7523
Radar None
Original Reporter plivesey (JIRA User)
Type Bug
Environment

Version 9.3 (9E145)

Swift 4.1

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee @moiseev
Priority Medium

md5: 465ff5325f60aedb3bcc1562fda22cee

Issue Description:

In this code:

let lc = [1, nil].lazy

let fm = Array(lc.flatMap({ _ in return true }))

There is no warning in Swift 4.1. It seems like this should be a compactMap, not a flatMap.

It seems like the problem is with:

extension LazyCollectionProtocol where Self.Elements : BidirectionalCollection {
    public func flatMap<ElementOfResult>(_ transform: @escaping (Self.Elements.Element) -> ElementOfResult?) -> LazyMapCollection<LazyFilterCollection<LazyMapCollection<Self.Elements, ElementOfResult?>>, ElementOfResult>
}

I think this function should be deprecated and replaced with compactMap

@belkadan
Copy link
Contributor

belkadan commented May 1, 2018

cc @moiseev

@moiseev
Copy link
Mannequin

moiseev mannequin commented May 3, 2018

plivesey (JIRA User) I.. can't find this definition in the codebase. All the wrong instances of flatMap(_: ) seem to be annotated appropriately.

@moiseev
Copy link
Mannequin

moiseev mannequin commented May 4, 2018

Ahh.. Found it! https://github.com/apple/swift/blob/swift-4.1-branch/stdlib/public/core/FlatMap.swift#L173-L182
For some reason the availability attribute did not make it into the swift-4.1-branch and slipped into the release.
Fixed in master and in swift-4.2-branch.

@swift-ci
Copy link
Collaborator Author

swift-ci commented May 4, 2018

Comment by Peter Livesey (JIRA)

Ah, great. Thanks for the info.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants