Computer scienceProgramming languagesScalaTypes and data structuresSpecial types

Unified types

Anyone can be there

Report a typo

Write a function doubleValue that takes a parameter value of type AnyVal and returns a new value that is twice the original value. Implement the function to handle different types of AnyVal inputs and perform the doubling operation accordingly.

Double the value based on its type: for numeric types (for simplicity, Int and Double), perform the multiplication by 2; for Char, make a string with two chars.

Sample Input 1:

a

Sample Output 1:

aa
Write a program in Scala 3
def doubleValue(value: AnyVal): Any =
??? // Write your code here
___

Create a free account to access the full topic