Scala - Using a match expression as the body of a method Code Example

The code for Using a match expression as the body of a method

// Function
def MyFunction(bool: Boolean): String = bool match {
    case true => "It is true"
    case false => "It is false"
}

// Call the method and then print it's result
println(MyFunction(true))
println(MyFunction(false))

/*
Output:
It is true
It is false
*/
Code by IncludeHelp, on August 8, 2022 02:14

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.