Created
September 21, 2019 10:02
-
-
Save boombang/c65abe035f592dc944fd05c676c1c7e2 to your computer and use it in GitHub Desktop.
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
list = | |
[ 1, 2, 3, 4 ] | |
push = | |
list ++ [ 5 ] | |
unshift = | |
0 :: list | |
-- [0] ++ list | |
removeByIndex = | |
let | |
-- take : Int -> List a -> List a | |
before = | |
List.take 1 list | |
-- drop : Int -> List a -> List a | |
after = | |
List.drop 2 list | |
in | |
before ++ after | |
-- [ 1, 3, 4 ] | |
filter = | |
-- filter : (a -> Bool) -> List a -> List a | |
List.filter (\n -> n > 2) list | |
reduce = | |
-- foldl : (a -> b -> b) -> b -> List a -> b | |
List.foldl (\x q -> x + q) 0 [ 1, 2, 3, 4 ] | |
reducePlusOperator = | |
List.foldl (+) 0 [ 1, 2, 3, 4 ] | |
f = | |
-- List number -> number | |
List.sum [ 1, 2, 3, 4 ] | |
isEvil name = | |
-- member : a -> List a -> Bool | |
List.member name [ "Joffrey", "Ramsay" ] | |
partition = | |
-- partition : (a -> Bool) -> List a -> ( List a, List a ) | |
List.partition isEvil [ "Samwell", "Joffrey", "Hodor", "Ramsay" ] | |
-- (["Joffrey","Ramsay"],["Samwell","Hodor"]) | |
b = | |
-- unzip : List ( a, b ) -> ( List a, List b ) | |
List.unzip [ ( "Andy", True ), ( "Hadley", False ), ( "Red", True ) ] | |
-- (["Andy","Hadley","Red"],[True,False,True]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment