diff --git a/3-99 Research/Haskell/Chapter 2 - Starting Out.md b/3-99 Research/Haskell/Chapter 2 - Starting Out.md index 9c696bce..a5cabc23 100644 --- a/3-99 Research/Haskell/Chapter 2 - Starting Out.md +++ b/3-99 Research/Haskell/Chapter 2 - Starting Out.md @@ -119,6 +119,21 @@ take 10 [2, 4..] -- will only yield even numbers greater than 12 in the first 10 elements of the set ``` -I made it to boomBangs and stopped. I'm outta gas :) +boomBangs is an interesting one. We can write code that does a function as the function, while also incorporating predicates. +An easy way to remember: [Function | Set, Predicate, (predicate 2),...] +Fucking Stupid Predicates + +We can also use multiple lists. If multiple lists are given (one for each variable), then all combinations of the two lists are used. + +Strings are just lists. We can apply list comprehensions to them! +Here's a couple of useful examples: +```haskell +-- Now Writing our own custom list function +length' xs = sum [1 | _ <- xs] +-- use dummy variable _, draw an element from a list and replace it with 1. Sum all of those. + +--- Strings are lists! We can use list comprehensions on them. +removeNonUppercase st = [ c | c <- st, c `elem` ['A'..'Z']] +``` diff --git a/3-99 Research/Haskell/baby.hs b/3-99 Research/Haskell/baby.hs index 821dcc81..548bcc1d 100644 --- a/3-99 Research/Haskell/baby.hs +++ b/3-99 Research/Haskell/baby.hs @@ -18,3 +18,6 @@ schtankyList x = [ x*y | x <- [2,5,10], y <- [8,10,11]] length' xs = sum [1 | _ <- xs] -- use dummy variable _, draw an element from a list and replace it with 1. Sum all of those. +--- Strings are lists! We can use list comprehensions on them. +removeNonUppercase st = [ c | c <- st, c `elem` ['A'..'Z']] +