Mapper

interface Mapper<in F, out T>

A generic interface for mapping an object of type F (from) to an object of type T (to).

This interface uses an operator function invoke, allowing instances to be called like functions.

Example usage:

class StringToIntMapper : Mapper<String, Int> {
override fun invoke(from: String): Int {
return from.toIntOrNull() ?: 0
}
}

val mapper = StringToIntMapper()
val result = mapper("123") // result is 123

Type Parameters

F

The source type to map from. The in variance modifier indicates that F can only be consumed (used as a parameter).

T

The target type to map to. The out variance modifier indicates that T can only be produced (used as a return type).

Functions

Link copied to clipboard
abstract operator fun invoke(from: F): T