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

Add (Mapper)WithMap #110

Closed
LartyHD opened this issue Jun 2, 2019 · 2 comments

Comments

@LartyHD
Copy link
Member

commented Jun 2, 2019

class WithMap<M, O>(private val entries: MutableMap<M, O> = mutableMapOf()) {

    operator fun getValue(input: M, property: KProperty<*>): O? = entries[input]

    operator fun setValue(input: M, property: KProperty<*>, value: O) {
        if (value == null) entries.remove(input) else entries[input] = value
    }

}

class MapperWithMap<I, M, O>(
        private val entries: MutableMap<M, O> = mutableMapOf(),
        private val mapped: I.() -> M
) {

    operator fun getValue(input: I, property: KProperty<*>): O? = entries[input.mapped()]

    operator fun setValue(input: I, property: KProperty<*>, value: O) {
        if (value == null) entries.remove(input.mapped()) else entries[input.mapped()] = value
    }

}
@issue-label-bot

This comment has been minimized.

Copy link

commented Jun 2, 2019

Issue-Label Bot is automatically applying the label feature_request to this issue, with a confidence of 0.95. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@LartyHD

This comment has been minimized.

Copy link
Member Author

commented Jun 4, 2019

Done in 4.0.0

@LartyHD LartyHD closed this Jun 4, 2019

LartyHD added a commit that referenced this issue Jun 4, 2019

@LartyHD LartyHD self-assigned this Jun 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.