Git Product home page Git Product logo

Comments (5)

pNre avatar pNre commented on September 26, 2024

indexOf returns nil if the element is not found or not compatible with the Array.Element type.
3 should be 3.0. This is to ensure the elements in the array implement Equatable.

from exswift.

nstepan avatar nstepan commented on September 26, 2024

indexOf uses find function which returns Optional(1), so now there is some inconsistency

from exswift.

pNre avatar pNre commented on September 26, 2024

@mijn-design We're talking about the indexOf method in ExSwift.
@nstepan What I'm trying to explain is that you can't use find on the Array unless Array.Element is Equatable, when you extend the Array class, you're extending every possible Array so you don't know if Array.Element is Equatable (and you can't extend only Equatable arrays).
To only way to search for an element despite this problem is casting the array elements to an Equatable type, the first parameter you pass. This is what (unsafeBitCast(self, [U].self) does in indexOf.
Doing this, only allows you to cast to the elements' real type (e.g. if you pass Int, casting an array of Double elements gives you [nil, nil, ...]) so it's not possible to mirror find's behavior.
indexOf is not find even if implemented using it.

from exswift.

markhamilton1 avatar markhamilton1 commented on September 26, 2024

I have been studying your code in ExSwift and am puzzled about the Element keyword. Where is it defined? What the heck does it mean? I can infer from the code what it does but how did you know about it or how to use it?

Keep up the great work! Thanks for sharing!

Mark Hamilton

from exswift.

pNre avatar pNre commented on September 26, 2024

@markhamilton1 typealias Element = T is defined in the standard library, precisely in struct Array<T> (in Xcode click on the Array keyword while pressing cmd).

from exswift.

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.