meilisearch-swift icon indicating copy to clipboard operation
meilisearch-swift copied to clipboard

Make generics usage consistent

Open bidoubiwa opened this issue 4 years ago • 2 comments
trafficstars

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.

bidoubiwa avatar Jun 09 '21 12:06 bidoubiwa

This may be complex, I don't think Swift supports this type of overload but I might be wrong.

ppamorim avatar Jun 29 '21 18:06 ppamorim

The code already does this kind of overload in some places:

see here

    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 {
// ...
    }

bidoubiwa avatar Jul 01 '21 14:07 bidoubiwa

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.

brunoocasali avatar Sep 28 '22 08:09 brunoocasali