- Apply FP principles on a real life example
Complete the sentences below:
- ... holds one of two values
Left
orRight
. - ... is a monadic container which represents a computation that may either throw an exception or successfully completes.
- ... don't refer to any global state -> same inputs will always return the same output.
- ... is a type safe alternative to null values.
- ... is the
using
to rule them all. - ... is any type that defines how map works.
Correction
Either
holds one of two valuesLeft
orRight
.Try
is a monadic container which represents a computation that may either throw an exception or successfully completes.Pure Functions
don't refer to any global state -> same inputs will always return the same output.Option
is a type safe alternative to null values.using static LanguageExt.Prelude
is theusing
to rule them all- A
functor
is any type that defines how map works.
You already know what you need to use those concepts in your code base. So today let's focus only on practicing.
Open RealLifeExample
and refactor the code in a more readable / functional way.
We propose to follow those steps:
- Understand what is implemented
- Define the pipeline you would like to design
- What are the ins / outs?
- Then refactor to tend to this pipeline
Step-by-step solution available here
Let's compare our refactored code with the original one.
- How do you rate the readability of those 2?
- Can you spot any remaining code smells?
- How good is the test coverage?