Scrivio Interview library

Functional design in Java

15 questions in 5 subtopics.

Higher-order functions

CodingFoundations6 min read
Write a higher-order function retrying(Supplier<T> action, int attempts) that returns a Supplier<T> which retries on RuntimeException. Show how it is used.
DesignIntermediate7 min read
Your team builds a small pipeline framework where steps are Function<Context, Context>. Discuss the benefits and the problems this design causes in a large codebase.
LeadershipAdvanced6 min read
Some teams in your organisation write heavily functional Java with Vavr, monads and point-free style; others write plain imperative Java. Hiring and code moves between teams suffer. What guidance do you set?
LeadershipPrincipal7 min read
Functional programming ideas have moved into mainstream Java over twenty years. Which of them have proven their value in large Java codebases, which have not, and what would you encourage or discourage in your organisation's standards?

Function composition

CodingFoundations5 min read
Show how to compose functions with Function.andThen and compose, and predicates with and, or and negate. What is the difference between f.andThen(g) and f.compose(g)?
DesignIntermediate6 min read
Design a validation component where rules can be combined, for example Rule<Order> = notEmpty.and(maxItems(50)).and(validAddress), and the result lists all failures, not only the first. How would you model it?

Immutability and pure functions

ConceptFoundations6 min read
What is a pure function? Which of these are pure and why: Math.max, a method that reads LocalDate.now(), a method that adds to a list parameter, String.toUpperCase().
ScenarioIntermediate7 min read
You want to make the pricing logic of an order service easier to test and reason about. How would you apply functional core, imperative shell?
LeadershipPrincipal6 min read
Java started as an object-oriented language and has added lambdas, records, sealed types and pattern matching. How do you see the balance between object-oriented and functional styles in Java over the next decade, and what do you standardise?

Currying in Java

CodingIntermediate6 min read
Show how to write a curried function in Java for add(a, b, c) and how to partially apply a BiFunction. When is this useful in real code?
DesignAdvanced6 min read
A library author wants to expose curried APIs such as Function<Config, Function<Request, Response>> in a shared framework. What would you advise?

Functional error handling

ConceptFoundations6 min read
What are the options for handling errors in a functional style in Java, instead of throwing exceptions from inside lambdas?
CodingIntermediate7 min read
Write a minimal Result<T> type using a sealed interface and records, with map and a way to handle both cases using a switch.
LeadershipAdvanced6 min read
Teams disagree on whether service-layer code should use exceptions or Result types for business errors such as insufficient funds. What standard do you choose for a large Spring codebase?
LeadershipPrincipal6 min read
Java now has sealed interfaces, records and pattern matching, which make Result-style error handling practical without a library. Over the next decade, how would you guide error handling style across a large codebase that is built on exceptions?