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

Why is array and dictionary + generic when other operators are not? #16

Open
sodiboo opened this issue Aug 8, 2021 · 0 comments
Open

Comments

@sodiboo
Copy link

sodiboo commented Aug 8, 2021

public static func + <T>(lhs: [T], rhs: [T]) -> [T] {
var result = lhs
for i in rhs.GetSequence() {
result.append(i)
}
return result
}
public static func + <T>(lhs: Array<T>, rhs: ISequence<T>) -> Array<T> {
var result = lhs
for i in rhs {
result.append(i)
}
return result
}

These two definitions for + are generic, but the other operators are not. The other operators can still use the generic type parameter from the array type itself, why does the + use its own generic type parameter? Same thing for Dictionary.

public static func + <T>(lhs: [Key:Value], rhs: [Key:Value]) -> [Key:Value] {
var result = lhs
for k in rhs.keys {
result[k] = rhs[k]
}
return result
}

@sodiboo sodiboo changed the title Why is array and dictionary + generic, but other methods are not? Why is array and dictionary + generic when other operators are not? Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant