-
-
Save patch/83d485d600e7095cca220b7fa046a2e0 to your computer and use it in GitHub Desktop.
Perl 6 One Liners
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
-- 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