1 2

01: Scala Functional Programming basics – pure functions, referential transparency & side effects

Q1. What is a pure function?
A1. A pure function is a function where the following conditions are met:

1) The Input solely determines the output.

2) The function does not change its input.

3) The function does not do anything else except computing the output.… Read more ...

02: Scala FP basics: First-class function, higher order function, statements Vs expressions, immutability & recursion

Q1. What is a first-class function?
A1. A first-class function is a function that can be treated like a value.

1) Can be assigned to a variable as a value can be assigned to a variable.… Read more ...

02B: Scala FP basics: Explain the below Scala code

Q. Can you explain the concepts used in the below code?

03: Q1 – Q6 Scala interview Q&As on Functional Programming

100+ FAQ Scala interview questions answered with code. Learn more about FP – 6 tips to transforming your thinking from OOP/imperative programming to functional programming (i.e. FP). Scala is very popular in Apache Spark programming to process Big Data. 70+ FAQ Bigdata & Hadoop interview questions & answers with diagrams…

Tags:

04: Currying, partial application & functional composition in Scala

Let’s see how we can wire up functions with & without currying, and then touch on functional composition. Without currying Here are simple functions example that add, add10, multiply and multiplyBy10 without currying.

04: Q6 – Q12 Scala FP currying, closures & partial functions interview Q&As

This extends Q1 – Q5 Scala Functional Programming basics interview questions & answers Q6. What is a curried function in Scala? A6. Currying is the technique of transforming a function with multiple arguments into a function with just one argument, and the other arguments are curried.… Read more ...

05: Q13 – Q18 Scala FP combinators interview questions & answers

Q13. What are the different approaches in Scala to solve the following task?

Given numbers 1 to 6, and you need to extract out the odd numbers and double them, and finally print the result.

A13. There are 3 ways to solve the problem.… Read more ...

05: Q27 – Q32 Scala idioms Q&As on Option-Some-None, Try-Success-Failure and Either-Left-Right

Java has idioms like Try-Catch-Finally, Scala has idioms like 1) “Option-Some-None”, 2) Either-Left-Right 3) Try-Success-Failure. Q27. How does Scala try to solve the problem of getting rid of null values & the “NullPointerException”? A27. Scala provides its own type for representing optional values with “Option[A]”, which is a trait.… Read more ...

06: Scala Class Vs. Object and Companion object interview Q&As

Q1. Given the below Person.scala file with Person.calss, what will be the output?

06C: Q33 – Q40 Scala Futures and Promises Interview Q&As

Q33. What is a “Future” object in Scala? Is it an immutable object? A33. A Future is a holder object that holds a value (i.e. success scenario) or an exception (i.e. failure) which may become available at some point. Future represents the result of an asynchronous computation.… Read more ...

07: Q41 – Q48 Scala Async and Actor System Interview Q&As

Q41. What is the purpose of the “async” macro in Scala? A41. The 2.11 and later versions of Scala include the ability to transform code during compilation by using macros. The “async” macro is one of them, which transforms sequential code that uses “Futures” into asynchronous code during compilation by…

07: Scala Factory Method Pattern & Trait Vs Abstract classes

This extends the Scala Class Vs. Object and Companion object interview Q&As to implement the factory method.

Q1. What is a factory method pattern?
A1. It is an Object Oriented Programming design pattern to instantiate objects. For example, if a “Person” is an abstract class where a person can be an “Employee” or a “Customer”, we can implement the factory method as shown below:

08: Q19 – Q26 Scala Data Structures basics interview questions & answers

Q19. What is the use of Tuples in Scala? A19. A Tuple is an immutable collection that can hold objects of different types. In other words, it groups together logical collections of items without using a class. There are 22 Tuple class in Scala from Tuple1, Tuple2, Tuple3, etc up…

08: Q49 – Q58 Scala Implicits Interview Q&As

Q49A. What are implicits in Scals? A49A. Implicits in Scala has two related features. 1) Implicit Parameters 2) Implicit Conversions. In both cases the Scala compiler implicitly provides extra information to prevent compile errors. 1. Implicit Parameters The code without implicits:

The code with implicit parameters: Implicit parameters are…

09: Q59 – Q65 Higher Order Functions in Scala Interview Q&As

Q59. What is a higher order function, and what is the purpose of higher order functions? A59. Higher-order functions are functions that take functions as parameters. This gives you opportunities to condense and simplify code. The most used methods in the entire Collection API like map, flatMap, filter, and foreach…

10: Q66 – Q70 Pattern matching in Scala Interview Q&As

Q66. What is the purpose of pattern matching in Scala? A66. It is for the “flow control”. Most imperative languages support “if-then-else”, case statements, and loops like while, for, foreach, etc. Scala does support some of these, but the most often used “conditional expression” is based on pattern matching.… Read more ...

11A: Scala values, proper types, first order types & higher kinded types

Q1. What is a proper type in Scala? A1. String, List[Int], List[String], Person, etc are proper types in Scala. The below diagram will become clearer at the end.

11B: Q71 – Q72 – Scala type parameterization & variance interview Q&As

Q71. Does Scala have type erasure as in Java?
A71. Yes. Scala parametrized types loose the type information after compilation in the same way as Java does.

Q72a. What are different type parameter modifiers in Scala?
A72a.

 Cage[T] T is of any type Invariance Cage[T <: Animal] T is sub type of an Animal upper bound, which means T can be a Lion, Elephant, etc.

11C: Q73 – Q77 – Scala type parameterization & variance interview Q&As

This extends the type parameters basics at 11B: Q71 – Q72 – Scala type parameterization & variance interview Q&As. Cage[T] T is of any type Invariance Cage[T <: Animal] T is sub type of an Animal upper bound, which means T can be a Lion, Elephant, etc.… Read more ...

11D: Scala existential type interview Q&As

Q01. What are existential types? A01. Existential types are a way of abstracting over types. They let you assert that some type “exists” without specifying exactly what it is as you don’t care what it is in the current context. For example, counting the number of elements in a list….… Read more ...

1 2
Don't be overwhelmed by the number of Q&As & tech stacks as nobody knows everything, and often key Q&As at the right moment makes a difference.