Lenses for the Mere Mortal: PureScript Edition
Free!
With Membership
$10.00
Suggested price

Lenses for the Mere Mortal: PureScript Edition

About the Book

Three things about this book make it a novelty among lens tutorials:

  1. Explanations are driven not by lens types, but by the types of data you want to use lenses on. Consider Maps. Most lens tutorials don't cover them. (I'm not sure I've found any that do.) Once you've learned lenses well, it's relatively easy to deduce how to use them with Maps. But if you try to use lenses on Maps before then, you will suffer. Which seems wrong, given how common Maps are in code. So this book covers them in chapter 2.
  2. I wrote the book as I was learning lenses and applying them to my own code. That gives me a better idea of what novices will stumble over (Maps! Error messages!) and allows me to introduce topics in something like a "just in time" order. To the best of my ability, the book represents what I'd have wished my learning experience to be: answers coming just as I was getting puzzled, answers that don't overwhelm me with completeness or detail I'm unprepared for, and so on. This isn't the first time I've written in this style, and it turns out that my ideal learning journey works for other people.
  3. It's a book. That means it can take its time. It doesn't have to leave things for you to figure out from API documentation.

There are other differences, but I'll leave them to the Introduction.

The book uses a PureScript version of lenses because I happened to be learning PureScript when I got the idea of writing it. I hope it's still useful for people wanting to learn the Haskell version. (The two APIs are very similar, though the underlying implementations differ in some important ways.)

I assume only shallow knowledge of PureScript, roughly equivalent to the three post-Elm introductory chapters in An Outsider's Guide to Statically Typed Functional Programming.

About the Author

Brian Marick
Brian Marick

Brian Marick was first exposed to the functional style in 1983, when the accident of knowing a little bit of Lisp tossed him into the job of technical lead on a project to port Common Lisp to a now-defunct computer architecture. That led him to a reading spree about all things Lisp, the language from which the functional style arguably originated. He’s been a language geek ever since, despite making most of his living as a software process consultant. He’s the author of the popular Midje testing library for Clojure and has written books (Everyday Scripting with Ruby, Programming Cocoa with Ruby, and Functional Programming for the Object-Oriented Programmer). The two books in progress are An Outsider's Guide to Statically Typed Functional Programming and Lenses for the Mere Mortal.

Table of Contents

  •  
    • Introduction
      • Optics are useful
      • Why are optics notoriously confusing?
      • This book’s approach
      • Why PureScript?
      • Getting ready
      • About the cover
      • Your problems and questions
      • Change log
      • Thanks for the help
    • 1. Tuples and records (lenses for product types)
      • 1.1 Tuples
      • 1.2 Records
      • 1.3 Composing lenses
      • 1.4 Composition exercise
      • 1.5 Types
      • 1.6 Composition exercise two
      • 1.7 Lens laws
      • 1.8 Law exercise
      • 1.9 What now?
    • 2. Maps (At lenses)
      • 2.1 A custom implementation
      • 2.2 At.at
      • 2.3 Types
      • 2.4 Composing At lenses
      • 2.5 What now?
    • 3. Optics and refactoring (optional)
      • 3.1 Architecture
      • 3.2 Optics
      • 3.3 Exercise
      • 3.4 My solution
      • 3.5 What now?
    • 4. Operating on whole collections (Traversal, part 1)
      • 4.1 Working with all the values
      • 4.2 view
      • 4.3 Focusing on individual values
      • 4.4 preview
      • 4.5 Composing traversals
      • 4.6 A sort of base class
      • 4.7 What now?
    • 5. Single elements in arrays and fixed-size maps (Index)
      • 5.1 ix, at, and Map
      • 5.2 Array
      • 5.3 Types
      • 5.4 Composition
      • 5.5 What now?
    • 6. Sum types (prisms)
      • 6.1 Using prisms
      • 6.2 Making a prism
      • 6.3 Prism laws
      • 6.4 Value constructors with more than one argument
      • 6.5 Types
      • 6.6 Composing prisms
      • 6.7 Prisms aren’t just for sum types (exercises)
      • 6.8 What now?
    • 7. Miscellaneous other optics
  • Appendices
    • A cheat sheet for the optic types
      • Lens
      • class At
      • Traversal
      • class Index
      • Prism
    • A catalog of compositions
      • Lens <<< optic
      • Prism <<< optic
      • Traversal <<< optic
      • At lens <<< optic
      • Index optic <<< optic
    • Identifying an optic from type spewage
      • I see Choice
      • I see Strong alone
      • I see Strong and Choice
      • I see Strong and At
      • I see Index and Wander
      • I see Wander alone
  • Notes

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub