Skip to content

Instantly share code, notes, and snippets.

@glureau-betclic
Last active March 6, 2020 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glureau-betclic/7f9cca939adee6afe89efc5f7fac230c to your computer and use it in GitHub Desktop.
Save glureau-betclic/7f9cca939adee6afe89efc5f7fac230c to your computer and use it in GitHub Desktop.
Kotlin code challenge @sellmair
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