val sourceBucketName = "source-bucket"
val fileName = "fileA"
val targetBucketName = "target-bucket"
val awsClient = AmazonS3ClientBuilder.standard().build()
def pureBusinessProcess(content: String): String = ???
def program = {
val content = awsClient.getObject(sourceBucketName, fileName)
val result = pureBusinessProcess(content)
awsClient.putObject(targetBucketName, fileName)
}
// ^ val define a name for a constant, type is auto infer by compiler
// not implemented yet v
// ^ def will define a method ^ ^
// ^ parameter type annotation
// parameter type annotation ^
// ^ a block: value of last expression will be returned
But there’s no such thing called “Design Pattern” in Functional Programming
There is only one Design Principle in FP
Remove all side effectsTo achieve that, you have the ultimate
BatmanCategory Theory utility beltA Simple Program
val sourceBucketName = "source-bucket"
val fileName = "fileA"
val targetBucketName = "target-bucket"
val awsClient = AmazonS3ClientBuilder.standard().build()
def pureBusinessProcess(content: String): String = ???
def program = {
val content = awsClient.getObject(sourceBucketName, fileName)
val result = pureBusinessProcess(content)
awsClient.putObject(targetBucketName, fileName)
}
Scala 101
val sourceBucketName = "source-bucket"
// ^ val define a name for a constant, type is auto infer by compiler
val fileName = "fileA"
val targetBucketName = "target-bucket"
val awsClient = AmazonS3ClientBuilder.standard().build()
// not implemented yet v
def pureBusinessProcess(content: String): String = ???
// ^ def will define a method ^ ^
// ^ parameter type annotation
// parameter type annotation ^
def program = {
// ^ a block: value of last expression will be returned
val content = awsClient.getObject(sourceBucketName, fileName)
val result = pureBusinessProcess(content)
awsClient.putObject(targetBucketName, fileName)
}
It’s very clean and readable code, isn’t it
but readable doesn’t change the fact that
It’s a shitty piece of code on production