liveBook · Manning

Thin effect layer

As explained in Functional Programming in Scala, Second Edition

A small outer program layer responsible for performing or handling effects excluded from the pure core.

A thin effect layer keeps the program’s core pure while an outer layer performs or handles effects. Instead of submitting a charge while constructing it, code can create a Charge as a value and defer its processing to the boundary. section 1.1.2

Coffee purchase

A coffee operation returns both Coffee and Charge. The core computes these values without processing payment; an outer layer later submits the Charge to an external system. Similar structure can contain local mutation or file writes when surrounding code cannot observe them. section 1.1.2

class Cafe:
  def buyCoffee(cc: CreditCard): (Coffee, Charge) =    #1
    val cup = Coffee()
    (cup, Charge(cc, cup.price))                       #2

Inspect the coffee example that separates purchase construction from charge handling. section 1.1.2

How Functional Programming in Scala, Second Edition covers it

How deep it goes
Explains the architectural pattern and observable-effect boundary, while deferring broader functional analogues and implementation details.
Examples
Uses coffee purchasing, Charge creation, payment submission, local mutation, and file writing as examples.
What you can do after
Apply it by returning effect descriptions from pure code and performing effects only in an outer layer.
How it connects
Connects pure functions, side effects, mutation, external systems, and functional analogues.

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in Scala, Second Edition. The section links point to the parts of the book it draws on.