https://kotlinlang.org logo
#announcements
Title
# announcements
x

xenoterracide

07/11/2019, 5:40 PM
Copy code
internal inline fun <reified T: BaseResource> find( criteria: (query: IQuery<Bundle>) -> IQuery<Bundle>): T? {
        val forResource = client.search<Bundle>().forResource(T::class.java)

        val entities = criteria.invoke(forResource).execute()

        if ( entities.isEmpty ) {
            <http://log.info|log.info>("entity {} was not found", T::class.simpleName)
            return null
        }
        if ( entities.total > 1 ) {
            <http://log.info|log.info>("too many {} found", T::class.simpleName)
            return null
        }

        return entities.entryFirstRep.resource as? T
    }
    internal fun findLocation(name: String): Location? {
        return find {it.where(Location.NAME.matches().value(name)) }
    }
is there a method signature where I can just call
where
instead of
it.where
?
d

Drew Hamilton

07/11/2019, 6:09 PM
replace
criteria: (query: IQuery<Bundle>) -> IQuery<Bundle>
with
criteria: IQuery<Bundle>.() -> IQuery<Bundle>
… I think. I can’t tell for sure what all your types are but
A.() -> B
is generally the notation for having
A
as the receiver in a lambda that returns
B
x

xenoterracide

07/11/2019, 6:41 PM
ah thanks
2 Views