Created
March 8, 2023 10:45
-
-
Save svsq/2251b37af7c345da91780244865c0073 to your computer and use it in GitHub Desktop.
Base abstract mapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Mapper<F, T> { | |
abstract fun map(from: F): T | |
abstract fun reverse(to: T): F | |
fun map(fromList: List<F>): List<T> = | |
ArrayList<T>(fromList.size).apply { | |
fromList.forEach { | |
add(map(it)) | |
} | |
} | |
fun reverse(toList: List<T>): List<F> = | |
ArrayList<F>(toList.size).apply { | |
toList.forEach { | |
add(reverse(it)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment