Last active
March 6, 2020 13:37
-
-
Save glureau-betclic/7f9cca939adee6afe89efc5f7fac230c to your computer and use it in GitHub Desktop.
Kotlin code challenge @sellmair
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
fun main() { | |
val transformation = Transformation.TransformationComposite(listOf(Transformation.NoOpTransformation())) | |
println("Res: ${transformation(Shape())}") | |
} | |
class Shape | |
sealed class Transformation { | |
class NoOpTransformation : Transformation() | |
class TransformationComposite(val transformations: List<Transformation>) : Transformation() | |
} | |
inline operator fun Transformation.invoke(shape: Shape): Shape = | |
when (this) { | |
is Transformation.NoOpTransformation -> shape | |
is Transformation.TransformationComposite -> transformations.fold(shape) { acc, transformation -> | |
transformation(acc) // This is calling the invoke method recursively | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment