O'Reilly logo

Functional Programming: A PragPub Anthology by Michael Swaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

One Step at a Time

All right, we’re looking to construct paths, and paths contain steps, so how about starting with the step operation? We want this operation to take a word and return all of the valid words that are reachable in one step from that word. For example, from “lead” we want to get the list

 ["bead","dead","head","mead","read","load","lend","lewd",
  "leaf","leak","leal","lean","leap","lear","leas"]

and we want it to exclude non-words like “xead.”

A key idea in functional programming is to split big problems into smaller ones. We use it all the time. So how can we apply it here?

At some point we probably need to use the dictionary to filter out invalid words like “xead,” but does the filtering need to be tied into the word ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required