Bird
0
0

Given the function type (Int) -> (Int) -> Int, what does this type represent in Swift?

hard📝 Application Q15 of 15
Swift - Functions
Given the function type (Int) -> (Int) -> Int, what does this type represent in Swift?
AA function that takes an Int and returns an Int array.
BA function that takes an Int and returns another function that takes an Int and returns an Int.
CA function that takes two Ints and returns an Int.
DA function that takes no parameters and returns an Int.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the nested function type

    The type (Int) -> (Int) -> Int means the function takes one Int and returns another function.
  2. Step 2: Understand the returned function

    The returned function itself takes an Int and returns an Int.
  3. Final Answer:

    A function that takes an Int and returns another function that takes an Int and returns an Int. -> Option B
  4. Quick Check:

    Curried function type = A function that takes an Int and returns another function that takes an Int and returns an Int. [OK]
Quick Trick: Read from left to right: input then output, output can be a function [OK]
Common Mistakes:
  • Confusing nested function types with multiple parameters
  • Assuming it returns an array
  • Ignoring that return type can be a function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes