Generating Candidates

Let’s see, we’re generating and filtering, right? So let’s consider the operation that generates potential words for later filtering. Type-wise, we want generate_candidates :: String -> [String], so that from a given word we get all possible next steps.

It’s always good to start with some concrete examples, especially if the operation doesn’t seem obvious.

From generate_candidates "", we expect no candidates, since there’s no way to change a single character in an empty string.

From generate_candidates "a", we expect ["b", "c", ... "z"], because we change the character to every other character except "a".

From generate_candidates "ba", we expect ["aa", "ca", "da", ... "za", "bb", "bc", ... "bz" ], which is the list ...

Get Functional Programming: A PragPub Anthology now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.