elm-community / list-extra

Convenience functions for working with List.
http://package.elm-lang.org/packages/elm-community/list-extra/latest
MIT License
135 stars 59 forks source link

Add count #73

Closed pzp1997 closed 7 years ago

pzp1997 commented 7 years ago

count is a simple but useful function for checking how many things in a list satisfy some predicate. It is great for when you don't care about the particulars of those things but only their quantity. An example of a good real-world use case is if you are accepting text input from the user and you want to know how many of the words/sentences they used have a particular property.

Suppose we give our students an activity to make complex sentences. A parameter that we might use to check a sentence is seeing if it contains more than one clause, which we can approximate by checking if it contains a , character and is adequately long. In order to determine if a student is successful, we simply want to know how many of their sentences satisfy our complexity rule. We can easily do this using count!

Chadtech commented 7 years ago

Cool, that all makes sense to me.