object MyBlog {
def main(args: Array[String]): Unit = {
composeExample()
}
def composeExample(): Unit = {
def appendCharAB = (input: Int) => { println("Executing function appendCharAB"); input + "AB" }
def appendCharXY = (input: String) => { println("Executing function appendCharAB"); input + "XY" }
val composeAnonymousFunction: Int => String = appendCharXY compose(appendCharAB)
val res = composeAnonymousFunction(999)
println(res) //999ABXY
}
}
Saturday, 7 May 2022
Scala Function - Compose
Scala compose creates an anonymous function which execute the function from right hand side and pass output to left hand side function as input.
Subscribe to:
Post Comments (Atom)
-
Distinct - It creates a copy of a given collection without duplicated elements DistinctBy - It also creates a copy given collection by kee...
-
Java is impatient, So it does things eagerly, Doing lazy things with Java is not straightforward! Let's first understand What do we m...
-
MongoDB is NoSQL Open Source database. It's document based database. Let's take an example to store cricket bat object: Cricket...
-
Eclipse Idea Usage F3 ctrl + b go to declaration (e.g. go to method) ctrl + l ctrl + g go to line ctrl + y ctrl + shift + z red...
-
Scala Collection - Combinations combinations creates the list of all the possible combinations from given collection by taking "n...
-
RDD stands for resilient (restore in case of failure) distributed dataset. RDD is an immutable structure/collection. RDD divide the data in...
-
Scala Collection - aggregateExample Use with Par function - It will split input in multiple collection and execute them parallel into 2 step...
-
Shuffle operation is the most expensive operation in Spark as takes a lot of I/O, networks calls. Why we need shuffle operation: While ru...
-
apply and unapply are the special methods in Scala. The apply method works like a constructor. Unapply uses to extract the object. The ...
-
The corresponds checks two collection indexes by index using the given predicate. Here isEven is a predicate that checks whether input numb...
No comments:
Post a Comment