Code Monkey home page Code Monkey logo

Comments (3)

matanlurey avatar matanlurey commented on June 16, 2024

I believe it is intended that the return value be the same list (just a different view of it), not a new list.

I don't think so (@leafpetersen @lrhn), even though I wish that was the case - I think .cast tries to re-use the same list, and basically invokes .retype if not possible, making this OK.

I.e. this is just a convenience for calling List.castFrom:

https://github.com/dart-lang/sdk/blob/f1ebe2bd5cfcb6b522e5b4fd406cdabb1a2d2091/sdk/lib/collection/list.dart#L332-L335

Let's look at the implementation of DoubleLinkedQueue.cast:

https://github.com/dart-lang/sdk/blob/f1ebe2bd5cfcb6b522e5b4fd406cdabb1a2d2091/sdk/lib/collection/queue.dart#L359-L362

Unfortunately there is no way in Dart to really "re-type" something, so unlike Dart 1's as List<String>, list.cast<String>() may return a new list if necessary to fulfill that cast.

from collection.

lrhn avatar lrhn commented on June 16, 2024

Both cast or retype are really intended to return a view of the original collection, one that also forwards mutating methods. The "if necessary" means that cast returns the original list if it already implements the desired interface, possibly by implementing a subtype, where retype always wraps so the return type is exact. It should not create a new collection that isn't linked to the original.

The QueueList class has the extra issue of needing to implement both List.cast and Queue.cast, so it needs to return something that is both a List and a Queue. I have a class ready for that in the private parts of the SDK, because one of the plans for Dart 2 was to make ListQueue implement List as well, but that doesn't help this package.

from collection.

matanlurey avatar matanlurey commented on June 16, 2024

Let me give this a shot, thanks @srawlins and @lrhn.

from collection.

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.