dave08
05/23/2023, 10:13 AM@optics data class Bar(val stateFlow: MutableStateFlow<Foo>)
val foo = Foo(...)
val foo2 = Foo(...)
val bar = Bar(MutableStateFlow(foo))
inline val <T> T.current: arrow.optics.Iso<MutableStateFlow<T>, T> inline get() = arrow.optics.Iso(
get = { stateFlow: MutableStateFlow<T> -> stateFlow.value },
reverseGet = { value: T -> MutableStateFlow(value) }
)
val baz = bar.copy {
Bar.stateFlow.current set foo2 // the IDE says that `set` needs an infix modifier in PIso
}
otherwise, am I doing this right?Alejandro Serrano Mena
05/23/2023, 11:10 AMset
is coming from in this caseBar.stateFlow.current.set(foo2)
instead, does it help?dave08
05/23/2023, 11:11 AMif you donope.. I think my problem has to do with trying to combine the generated optics with this one and my receiver is T...instead, does it help?Bar.stateFlow.current.set(foo2)
inline val <S : Any, T> arrow.optics.Lens<S, MutableStateFlow<T>>.currentOpt: arrow.optics.Iso<S, Option<T>> inline get() = this compose arrow.optics.Iso(
get = { stateFlow: MutableStateFlow<Option<T>> -> stateFlow.value },
reverseGet = { value: Option<T> -> MutableStateFlow(value) }
)
inline val <S, T> Setter<S, MutableStateFlow<Option<T>>>.value: Setter<S, Option<T>>
inline get() = this compose arrow.optics.Iso(
get = { stateFlow: MutableStateFlow<Option<T>> -> stateFlow.value },
reverseGet = { value: Option<T> -> MutableStateFlow(value) }
)
stojan
05/25/2023, 8:14 AMMutableStateFlow
as a property in a data class.... typically you have the MutableStateFlow
on the outside, and data is insidedave08
05/25/2023, 8:57 AM