vault backup: 2025-02-24 20:34:05
This commit is contained in:
parent
1896846e77
commit
3c9a5311cd
@ -119,6 +119,21 @@ take 10 [2, 4..]
|
|||||||
-- will only yield even numbers greater than 12 in the first 10 elements of the set
|
-- 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']]
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
@ -18,3 +18,6 @@ schtankyList x = [ x*y | x <- [2,5,10], y <- [8,10,11]]
|
|||||||
length' xs = sum [1 | _ <- xs]
|
length' xs = sum [1 | _ <- xs]
|
||||||
-- use dummy variable _, draw an element from a list and replace it with 1. Sum all of those.
|
-- 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']]
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user