-
public interface DataClassSetDslWhen a lambda has a receiver that extends this class it can make use of this special DSL syntax for changing properties on a data class. This syntax makes it easier to change deeply nested properties.
Example: mavericksState.set { ::listing { ::host { ::name } } }.with { "Elena" }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classDataClassSetDsl.SetterHelper to copy a nested class and update a property on it.
public classDataClassSetDsl.NestedPropertyRepresents two properties that are associated by a nested object hierarchy.
-
Method Summary
Modifier and Type Method Description <DataClass extends Any, Type extends Any> DataClassSetDsl.Setter<DataClass, Type>set(DataClass $self, Function1<DataClass, KProperty0<Type>> block)A small utility function to help copy kotlin data classes when changing a single property, especially where there is deep nesting. <DataClass extends Any, Type extends Any> DataClasssetNull(DataClass $self, Function1<DataClass, KProperty0<Type>> block)A shortcut to setting a property to null, instead of "data.set { ::property }.with { null }". <DataClass extends Any> DataClasssetTrue(DataClass $self, Function1<DataClass, KProperty0<Boolean>> block)Shortcut to set a Boolean property to true. <DataClass extends Any> DataClasssetFalse(DataClass $self, Function1<DataClass, KProperty0<Boolean>> block)Shortcut to set a Boolean property to false. <DataClass extends Any> DataClasssetZero(DataClass $self, Function1<DataClass, KProperty0<Number>> block)Shortcut to set a numeric property to zero. <DataClass extends Any, T extends Any> DataClasssetEmpty(DataClass $self, Function1<DataClass, KProperty0<List<T>>> block)Shortcut to set a List property to an empty list. <DataClass extends Any, Type extends Async<AsyncType>, AsyncType extends Any> DataClasssetLoading(DataClass $self, Function1<DataClass, KProperty0<Type>> block)A shortcut to setting an Async property to Loading, instead of "data.set { ::property }.with { Loading() }". <DataClass extends Any, Type extends Async<AsyncType>, AsyncType extends Any> DataClasssetNetworkFailure(DataClass $self, Function1<DataClass, KProperty0<Type>> block)A shortcut to setting an Async property to Fail, instead of "data.set { ::property }.with { Fail() }". <Type1 extends Any, Type2 extends Any> KProperty0<Type2>invoke(KProperty0<Type1> $self, Function1<Type1, KProperty0<Type2>> block)<T extends Any, Type extends Any> KProperty0<Type>success(Async<T> $self, Function1<T, KProperty0<Type>> block)Use this to update the property value of an Async's type when it is in the Success state. <PropertyType extends Any, DataClass extends Any> DataClasswith(DataClassSetDsl.Setter<DataClass, PropertyType> $self, Function1<PropertyType, PropertyType> block)Provide the new value to update your property to. -
-
Method Detail
-
set
<DataClass extends Any, Type extends Any> DataClassSetDsl.Setter<DataClass, Type> set(DataClass $self, Function1<DataClass, KProperty0<Type>> block)
A small utility function to help copy kotlin data classes when changing a single property, especially where there is deep nesting. This is heavy on reflection, so isn't intended for high performance use cases.
This can only be called on Kotlin Data classes, and all nested objects that are modified must also be data classes.
-
setNull
<DataClass extends Any, Type extends Any> DataClass setNull(DataClass $self, Function1<DataClass, KProperty0<Type>> block)
A shortcut to setting a property to null, instead of "data.set { ::property }.with { null }".
-
setTrue
<DataClass extends Any> DataClass setTrue(DataClass $self, Function1<DataClass, KProperty0<Boolean>> block)
Shortcut to set a Boolean property to true.
-
setFalse
<DataClass extends Any> DataClass setFalse(DataClass $self, Function1<DataClass, KProperty0<Boolean>> block)
Shortcut to set a Boolean property to false.
-
setZero
<DataClass extends Any> DataClass setZero(DataClass $self, Function1<DataClass, KProperty0<Number>> block)
Shortcut to set a numeric property to zero.
-
setEmpty
<DataClass extends Any, T extends Any> DataClass setEmpty(DataClass $self, Function1<DataClass, KProperty0<List<T>>> block)
Shortcut to set a List property to an empty list.
-
setLoading
<DataClass extends Any, Type extends Async<AsyncType>, AsyncType extends Any> DataClass setLoading(DataClass $self, Function1<DataClass, KProperty0<Type>> block)
A shortcut to setting an Async property to Loading, instead of "data.set { ::property }.with { Loading() }".
-
setNetworkFailure
<DataClass extends Any, Type extends Async<AsyncType>, AsyncType extends Any> DataClass setNetworkFailure(DataClass $self, Function1<DataClass, KProperty0<Type>> block)
A shortcut to setting an Async property to Fail, instead of "data.set { ::property }.with { Fail() }".
-
invoke
<Type1 extends Any, Type2 extends Any> KProperty0<Type2> invoke(KProperty0<Type1> $self, Function1<Type1, KProperty0<Type2>> block)
-
success
<T extends Any, Type extends Any> KProperty0<Type> success(Async<T> $self, Function1<T, KProperty0<Type>> block)
Use this to update the property value of an Async's type when it is in the Success state. This will throw an exception if the Async it is used on is not Success.
Example: state.set { ::myAsync { success { ::text } } }.with { "hello" }
If you would like to replace the whole value of the Success object you can instead do state.set { ::myAsync }.with { Success(MyClass(text = "hello")) }
-
with
<PropertyType extends Any, DataClass extends Any> DataClass with(DataClassSetDsl.Setter<DataClass, PropertyType> $self, Function1<PropertyType, PropertyType> block)
Provide the new value to update your property to. "it" in the lambda is the lambda is the current value, and you should return the new value.
-
-
-
-