Skip to content

Instantly share code, notes, and snippets.

@AlistairB
Created April 22, 2017 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlistairB/e20f2a5a3b35e170e68d6eac58cfd211 to your computer and use it in GitHub Desktop.
Save AlistairB/e20f2a5a3b35e170e68d6eac58cfd211 to your computer and use it in GitHub Desktop.
I found it surprising how this worked :) But it helped me understand monads and do
twiceWhenEven :: [Integer] -> [Integer]
twiceWhenEven xs = do
x <- xs
if even x
then [x*x, x*x]
else [x*x]
-- Prelude> twiceWhenEven [1..3]
-- [1,4,4,9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment