Documentation / dataflow / com.femastudios.dataflow / Field / then
Go to reference


open fun <O> then(transform: (T) -> Field<O>): Field<O>

Returns a new Field<O> that mirrors the Field returned by transform applied to the value of this Field.

When the value of this Field, or the Field returned by transform changes, the value of the returned Field will change as well.

This function is very similar to transform, but more flexible, since transform returns a Field.

For example:

class User(val id : Int, val username : MutableField<String>)

val currentUser = mutableFieldOf(User(6, mutableFieldOf("Tom")))
val currentUsername /* : Field<String> */= currentUser.then { user.username }

currentUsername.value //Yields "Tom"

//Changing current user
val seven = User(7, mutableFieldOf("Dick"))
currentUser.value = seven
currentUsername.value //Yields "Dick"

//Changing username of current user
seven.username.value = "Harry"
currentUsername.value //Yields "Harry"