multiplatform-settings icon indicating copy to clipboard operation
multiplatform-settings copied to clipboard

Add generic versions for getting Flow (and probably for adding listeners as well)

Open dalewking opened this issue 7 months ago • 1 comments

You have nice inline generic version for get/set that will choose the correct implementation based on the generic type. It would be nice to have inline generic versions like:

public inline fun <reified: T> ObservableSettings.getFlow() : Flow<T>
public inline fun <reified: T> ObservableSettings.getNullableFlow() : Flow<T>

although those could be computed extension properties instead.

I'm not using it but you would probably want something similar for adding listeners

public inline fun <reified: T> ObservableSettings.addListener(listener: (T) -> Unit) : SettingsListener
public inline fun <reified: T> ObservableSettings.addNullableListener(listener: (T?) -> Unit) : SettingsListener

dalewking avatar May 24 '25 04:05 dalewking

I'm not a fan of generic APIs that throw when the type parameter is invalid, because it becomes a footgun when the wrong type accidentally gets inferred. The only reason they exist for the operator functions is because there would be issues with conflicting overloads otherwise.

It's not hard to write these extensions yourself if you really want them.

russhwolf avatar May 24 '25 15:05 russhwolf