4 ms·
I wish they'd taken it just a little further and made surrounding brackets optional (using indentation instead). I.e. def greetABunchOfPeople(List<String> pe
by rapind 15y ago
I wish they'd taken it just a little further and made surrounding brackets optional (using indentation instead). I.e.
def greetABunchOfPeople(List<String> people)
people.forEach
println(sayHello)
- im3w1l 15y agoFurther! greetABunchOfPeople List<String> people pers:people println pers.sayHello
- masklinn 15y agoYou still have a dot in there! greetABunchOfPeople List<String> people people do _ sayHello println
- willurd 15y agoYou left a type in there! greetABunchOfPeople people people do _ sayHello println
- meric 15y agoWhile we're at it, let's switch to haskell (delete the unnecessary people argument): greetABunchOfPeople = mapM_ (putStrLn . sayHello) Explanation: mapM_ is a function that takes two arguments. mapM_ lambda list It calls lambda on each element on list. In the greetABunchOfPeople definition, notice we only gave mapM_ 1 argument instead of 2. That means greetABunchOfPeople would have to take an extra argument for the call to execute. greetABunchOfPeople $MISSING$ = mapM_ (putStrLn . sayHello) $MISSING$
- Periodic 15y agoYou beat me to it. What I love about the Haskell version is it says only exactly what needs to be said. sayHello - get the hello message for something. putStrLn - send something to stdout mapM_ - Do these things in sequence, I don't care about the result. Together they say take a list of people, get their greeting strings and print them to stdout in order. It's hard to say it more succinctly without making things confusingly implicit.