Giter VIP home page Giter VIP logo

Comments (7)

LucianoPAlmeida avatar LucianoPAlmeida commented on June 8, 2024

Couldn't repro this, did this have another detail for the repro?

from swift-algorithms.

domkm avatar domkm commented on June 8, 2024

Odd. It's still happening for me. I copied AdjacentPairsTests.swift and TestUtilities.swift into my project and updated the testThreeElementSequence() test.

  func testThreeElementSequence() {
    let pairs = (0...).prefix(3).adjacentPairs()
    XCTAssertEqualSequences(pairs, [(0, 1), (1, 2)], by: ==)
+   let pairs2 = [0, 1, 2].adjacentPairs().map {x in x}
+   XCTAssertEqualSequences(pairs2, [(0, 1), (1, 2)], by: ==)
  }

The second assertion fails:
Screenshot 2023-11-18 at 7 53 24 PM

Perhaps related, [0, 1, 2].adjacentPairs() without the .map {x in x} fails to type check with Ambiguous use of 'adjacentPairs()'.

Any suggestions?

from swift-algorithms.

LucianoPAlmeida avatar LucianoPAlmeida commented on June 8, 2024

Wait, do the "ambiguos" diagnostic notes point to the candidates it found, it looks like maybe you would have to versions of "adjacentPairs" and the one being pick for array is incorrect. You can also click in Xcode and see where it takes you.

from swift-algorithms.

domkm avatar domkm commented on June 8, 2024

You're right! I'm new to Swift but should have checked this first anyway, sorry. It looks like SwifterSwift defines a different version of adjacentPairs. I haven't yet narrowed down how the two implementations are causing incorrect results though.

from swift-algorithms.

LucianoPAlmeida avatar LucianoPAlmeida commented on June 8, 2024

Coincidently I happen to be a maintainer of SwifterSwift so I can take a look on the implementation there and see if this is indeed a bug there. Thank you for the report :)

from swift-algorithms.

jshier avatar jshier commented on June 8, 2024

Seems to be the intended behavior:

/// SwifterSwift: Unique pair of elements in a collection.
///
///        let array = [1, 2, 3]
///        for (first, second) in array.adjacentPairs() {
///            print(first, second) // print: (1, 2) (1, 3) (2, 3)
///        }
///
///

Seems to be what swift-algorithms calls permutations.

from swift-algorithms.

LucianoPAlmeida avatar LucianoPAlmeida commented on June 8, 2024

Seems to be what swift-algorithms calls permutations.

Yeah, this is actually something I've missed on review

from swift-algorithms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.