SplittingConverter

Models partial, asymmetrical conversion between a type F and a type T, where some condition internal to the converter splits the possible pathways data make take through conversion logic. One of these branches will be more complex and involve converting types F and T to types F2 and T2 (respectively). The remaining conversion between F2 and T2 will typically be delegated to another converter.

Because they are partial and asymmetrical, SplittingConverter instances are typically not very useful on their own. Most often they are combined with another Converter via the mergeBy extension method, forming a complete, symmetrical converter between F and T.

Splitting converters use the Either type to denote values which may follow the simple branch (Either.Left) or the complex branch (Either.Right).

Parameters

F

The overall type being converted from

F2

The intermediate type being converted from on the complex branch

T2

The intermediate type being converted to on the complex branch

T

The overall type being converted to

Inherited functions

Link copied to clipboard

Chains this converter with another converter, yielding a new converter which performs a two-stage conversion. (Note that these two "stages" are conceptual. Each of these stages may consist of multiple logical steps in their actual implementation.)

Link copied to clipboard

Chains this converter with another converter, yielding a new converter which performs a two-stage conversion. (Note that these two "stages" are conceptual. Each of these stages may consist of multiple logical steps in their actual implementation.)

Link copied to clipboard
abstract fun convertFrom(to: T): Either<F, T2>

Converts a single value from type T to type F

Link copied to clipboard
abstract fun convertTo(from: F): Either<T, F2>

Converts a single value from type F to type T

Link copied to clipboard
fun <F, T> ConvertsTo<F, T>.firstValidatingFrom(validate: (F) -> Unit): ConvertsTo<F, T>

Adds validation before a conversion by running validate on F values before converting them to type T. Validators are expected to throw an exception if the expected condition is not met.

Link copied to clipboard
fun <F, T> ConvertsFrom<F, T>.firstValidatingTo(validate: (T) -> Unit): ConvertsFrom<F, T>

Adds validation before a conversion by running validate on T values before converting them to type F. Validators are expected to throw an exception if the expected condition is not met.

Link copied to clipboard
fun <F, F2, T> ConvertsFrom<List<F>, T>.mapConvertsFrom(elementConverter: ConvertsFrom<F2, F>): ConvertsFrom<List<F2>, T>

Chains this list converter with an element converter, yielding a new converter which performs a two-stage mapping conversion. (Note that these two "stages" are conceptual. Each of these stages may consist of multiple logical steps in their actual implementation.)

Chains this map converter with an entry converter, yielding a new converter which performs a two stage mapping conversion. (Note that these two "stages" are conceptual. Each of these stages may consist of multiple logical steps in their actual implementation.)

fun <F, F2, T> ConvertsFrom<Set<F>, T>.mapConvertsFrom(elementConverter: ConvertsFrom<F2, F>): ConvertsFrom<Set<F2>, T>

Chains this set converter with an element converter, yielding a new converter which performs a two-stage mapping conversion. (Note that these two "stages" are conceptual. Each of these stages may consist of multiple logical steps in their actual implementation.)

Link copied to clipboard

Chains this map converter with a key converter, yielding a new converter which performs a two-stage mapping conversion. (Note that these two "stages" are conceptual. Each of these stages may consist of multiple logical steps in their actual implementation.)

Link copied to clipboard
fun <F, TK, TK2, V> ConvertsTo<F, Map<TK, V>>.mapConvertsKeysTo(keyConverter: ConvertsTo<TK, TK2>): ConvertsTo<F, Map<TK2, V>>

Chains this map converter with a key converter, yielding a new converter which performs a two-stage mapping conversion. (Note that these two "stages" are conceptual. Each of these stages may consist of multiple logical steps in their actual implementation.)

Link copied to clipboard
fun <F, T, T2> ConvertsTo<F, List<T>>.mapConvertsTo(elementConverter: ConvertsTo<T, T2>): ConvertsTo<F, List<T2>>

Chains this list converter with an element converter, yielding a new converter which performs a two-stage mapping conversion. (Note that these two "stages" are conceptual. Each of these stages may consist of multiple logical steps in their actual implementation.)

fun <F, TK, TV, TK2, TV2> ConvertsTo<F, Map<TK, TV>>.mapConvertsTo(entryConverter: ConvertsTo<Pair<TK, TV>, Pair<TK2, TV2>>): ConvertsTo<F, Map<TK2, TV2>>

Chains this map converter with an entry converter, yielding a new converter which performs a two-stage mapping conversion. (Note that these two "stages" are conceptual. Each of these stages may consist of multiple logical steps in their actual implementation.)

fun <F, T, T2> ConvertsTo<F, Set<T>>.mapConvertsTo(elementConverter: ConvertsTo<T, T2>): ConvertsTo<F, Set<T2>>

Chains this set converter with an element converter, yielding a new converter which performs a two-stage mapping conversion. (Note that these two "stages" are conceptual. Each of these stages may consist of multiple logical steps in their actual implementation.)

Link copied to clipboard

Chains this map converter with a value converter, yielding a new converter which performs a two-stage mapping conversion. (Note that these two "stages" are conceptual. Each of these stages may consist of multiple logical steps in their actual implementation.)

Link copied to clipboard
fun <F, K, TV, TV2> ConvertsTo<F, Map<K, TV>>.mapConvertsValuesTo(valueConverter: ConvertsTo<TV, TV2>): ConvertsTo<F, Map<K, TV2>>

Chains this map converter with a value converter, yielding a new converter which performs a two-stage mapping conversion. (Note that these two "stages" are conceptual. Each of these stages may consist of multiple logical steps in their actual implementation.)

Link copied to clipboard
fun <F, F2 : F, T, T2 : T> SplittingConverter<F, F2, T2, T>.mergeBy(converter: Converter<F2, T2>): Converter<F, T>

Merges this SplittingConverter by delegating to a Converter instance that converts between types F2 and T2. After the merge, a new Converter will be returned which fully converts between types F and T.