Comments (5)
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.
indexOf uses find function which returns Optional(1), so now there is some inconsistency
from exswift.
@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.
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.
@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)
- NSDate extension can't support iOS7 HOT 2
- Added support for adding single elements to an array HOT 1
- Why is there a custom old interval operator? HOT 1
- Compile error caused by param mismatch for addMinutes method of NSDate HOT 2
- Dictionary merge not implemented HOT 1
- Method parameter name in groupBy
- Protocol Extensions!
- UIKit support HOT 1
- make closures parameters as @noescape when possible HOT 4
- Xcode 7 bate3 many error HOT 6
- ExSwift needs a new major version HOT 4
- Doesn't Swift-1.2 exist anymore?
- Array<any> breaks with .remove() HOT 1
- How to install it? HOT 3
- Swift 2 update issue HOT 6
- Suggestion for Boolean Extension methods(Smalltalk style conditionals) HOT 1
- This repo is not maintained anymore!!! HOT 1
- Issue with Ayn's fork HOT 4
- Swift 3 vs ExSwift.swift HOT 5
- Any plans to support swift3? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from exswift.