liveBook · Manning

Developer productivity

As explained in Functional Programming in Scala, Second Edition

Productivity is the property that each finite portion of a potentially infinite result can be computed in finite time.

Productivity means that every finite portion of a potentially infinite result can be computed in finite time. Corecursive functions produce data rather than consume it; unlike ordinary recursion, they need not terminate when each further result remains computable. For LazyList, unfold is productive when its generating function terminates for each requested element. section 5.4 section 5.4

An infinite stream that remains usable

The definition val ones: LazyList[Int] = LazyList.cons(1, ones) does not finish constructing a list. It remains productive because finite demands can be answered: taking five elements yields List(1, 1, 1, 1, 1), and exists can stop after finding an odd element. section 5.4

Practice productivity by:

  • Defining fibs, from, continually, and ones with unfold. section 5.4
  • Implementing map, take, takeWhile, zipWith, zipAll, startsWith, and hasSubsequence for LazyList. section 5.4

How Functional Programming in Scala, Second Edition covers it

How deep it goes
Defines productivity, contrasts recursion with corecursion, and explains unfold's generation condition without developing deeper theory.
Examples
Demonstrates productivity with ones, finite prefixes, exists, unfold-based generators, and LazyList transformations.
What you can do after
Build it from scratch by implementing productive LazyList generators and transformations with unfold.
How it connects
Connects productivity with LazyList, corecursion, guarded recursion, unfold, and recursive functions.

Also explained in

Compare how 4 books explain developer productivity →

Related concepts

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.