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

Make number of recent values a parameter #3604

Merged
merged 2 commits into from
Dec 23, 2021

Conversation

smichel17
Copy link
Member

Allows easier experimentation for #3593. Also, I suspect that the right values are different between the building type and levels quest, so we'll want to do this later, anyway.

Allows easier experimentation for streetcomplete#3593. Also, I suspect that the right
values are different between the building type and levels quest, so
we'll want to do this later, anyway.
*/
fun <T : Any> Sequence<T?>.mostCommonWithin(target: Int, historyCount: Int): Sequence<T> {
fun <T : Any> Sequence<T?>.mostCommonWithin(target: Int, historyCount: Int, first: Int): Sequence<T> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this signature would be more understandable as

fun <T : Any> Sequence<T?>.mostCommonWithin(first: Int, top: Int, within: Int): Sequence<T> {

So instead of mostCommonWithin(6, 30, 1) you'd do mostCommonWithin(1, 5, 30).
I guess it's unintuitive in the edge case of "what if the first entry is null and we return 6 top values instead".

@smichel17
Copy link
Member Author

This only needs a cursory review, I considered just merging it immediately, but I had the idea I commented above, and @FloEdelmann you seem to like bikeshedding with me about code style :). If you don't have an opinion or don't care, feel free to just merge.

@matkoniecz
Copy link
Member

I am not convinced that it should be configurable in a normal release.

@smichel17
Copy link
Member Author

smichel17 commented Dec 23, 2021

Maybe I used the wrong word here. It's not end-user configurable. I just added a parameter to the mostCommonWithin function instead of hard coding it to the 1 most recent value. Still requires a code change, but now it's just one line of code (the call site). That lets us use different values for the building type vs levels quests.

@smichel17 smichel17 changed the title Make number of recent values configurable Make number of recent values a parameter Dec 23, 2021
@smichel17
Copy link
Member Author

On second thought, while I remain not-totally-happy with the interface here, I also don't want to spend any more time on this. It's definitely "good enough".

@smichel17 smichel17 merged commit 583da60 into streetcomplete:master Dec 23, 2021
@smichel17 smichel17 deleted the building-sort branch December 23, 2021 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants