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

Can CoroutineCollection<T>.replaceOne(replacement, options) be made non reified? #408

Open
jfontsaballs opened this issue Mar 24, 2023 · 0 comments

Comments

@jfontsaballs
Copy link

I'd would like to ask why this function is reified, and whether it can be made non-reified?

suspend inline fun <reified T : Any> CoroutineCollection<T>.replaceOne(

Concretely, maybe this line can be rewritten? If using T::class can be avoided, there's no need for the function to be reified, thus allowing it to be used in non-inline generic functions.

): UpdateResult = replaceOneById(extractId(replacement, T::class), replacement, options)

// Possible rewrite:
replaceOneById(extractId(replacement, replacement::class), replacement, options)

The save function has, I believe, similar behavior if the involved class has an _id property, without it being reified.

suspend fun save(clientSession: ClientSession, document: T): UpdateResult? {

My use case is as follows: we are building a internal library where we want to write a class that handles certain operations with a MongoDB database, but the concrete type can vary between different usages of the library. It is impossible to write this class using inline functions and reified generics, so we must use non-reified functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants