10 Working effectively with multi-argument functions

 

This chapter covers

  • Using multi-argument functions with elevated types
  • Using LINQ syntax with any monadic type
  • Fundamentals of property-based testing

The main goal of this chapter is to teach you to use multi-argument functions in the world of effectful types, so the “effectively” in the title is also a pun! Remember from section 6.6.1, effectful types are types such as Option (which adds the effect of optionality), Exceptional (exception handling), IEnumerable (aggregation), and others. In part 3, you’ll see several more effects related to state, laziness, and asynchrony.

As you code more functionally, you’ll come to rely heavily on these effects. You probably already use IEnumerable a lot. If you embrace the fact that types like Option and some variation of Either add robustness to your programs, you’ll soon be dealing in elevated types in much of your code.

Although you’ve seen the power of core functions like Map and Bind, there’s an important technique you haven’t seen yet: how to integrate multi-argument functions in your workflows, given that Map and Bind both take unary functions.

10.1 Function application in the elevated world

10.1.1 Understanding applicatives

10.1.2 Lifting functions

10.1.3 An introduction to property-based testing

10.2 Functors, applicatives, and monads

10.3 The monad laws

10.3.1 Right identity

10.3.2 Left identity

10.3.3 Associativity

10.3.4 Using Bind with multi-argument functions

10.4 Improving readability by using LINQ with any monad

10.4.1 Using LINQ with arbitrary functors

10.4.2 Using LINQ with arbitrary monads