Created
September 30, 2020 11:18
-
-
Save jaspervdj/1cd04abe2f61b60e42309ec6351f756f to your computer and use it in GitHub Desktop.
It's traverse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Imagine you're trying to guess someone's PIN code, and you have limited | |
-- info on each digit, e.g. if the digit is odd or even. | |
type Predicate a = a -> Bool | |
-- This is the info we have about the PIN code. | |
info :: [Predicate Int] | |
info = [odd, even, even, odd] | |
-- A helper to produce all digits satisfying a predicate. | |
digits :: Predicate Int -> [Int] | |
digits f = filter f [0 .. 9] | |
-- It's traverse! | |
guesses :: [[Int]] | |
guesses = traverse digits info |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment