meilisearch-swift
meilisearch-swift copied to clipboard
Make generics usage consistent
Generics are sometimes mandatory, sometimes not used, and on certain they have both.
For example, addDocuments has the following prototypes:
public func addDocuments<T>(...)
and
public func addDocuments(..)
Meaning it can both be used with generic and without.
On the contrary, for example, updateDocuments has no generics and getDocument can only be used with a generic.
This may be complex, I don't think Swift supports this type of overload but I might be wrong.
The code already does this kind of overload in some places:
func add(
_ UID: String,
_ document: Data,
_ primaryKey: String?,
_ completion: @escaping (Result<Update, Swift.Error>) -> Void) {
// ...
}
func add<T>(
_ UID: String,
_ documents: [T],
_ encoder: JSONEncoder? = nil,
_ primaryKey: String?,
_ completion: @escaping (Result<Update, Swift.Error>) -> Void) where T: Encodable {
// ...
}
I believe we could have only one add method instead.
In any case, I don't think this is a problem because the example sent about the add method mentions two different methods that serve a similar purpose but handle data differently.