Skip to content

Instantly share code, notes, and snippets.

@patch
Forked from djhworld/haskell_one_liners
Last active October 27, 2017 14:05
Show Gist options
  • Save patch/83d485d600e7095cca220b7fa046a2e0 to your computer and use it in GitHub Desktop.
Save patch/83d485d600e7095cca220b7fa046a2e0 to your computer and use it in GitHub Desktop.
Perl 6 One Liners
-- Inspired by http://solog.co/47/10-scala-one-liners-to-impress-your-friends/
# Double everything in a list
(1..10).map(* * 2)
# Sum a list of numbers
(1..1000).sum
# TODO: Verify if exists in a string
#any (`elem` ["haskell", "ghc", "monads", "cabal"]) $ words "this is a piece of example text talking about haskell and ghc"
# read in a file
'file.txt'.IO.lines
# TODO: Sing happy birthday
#putStr "Who's the birthday boy then? > " >> getLine >>= (\name -> mapM_ (\i -> putStrLn $ "Happy Birthday" ++ (if (i == 3) then " dear " ++ name else " to you!")) [1..4])
# Filter/partiton a list of numbers
(49, 58, 76, 82, 88, 90).classify(* > 60)
# Fetch and Parse an XML web service
# Find a minimum or maximum in a list
(14, 35, -7, 46, 98).max
(14, 35, -7, 46, 98).min
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment