3 ms·
I don't know, I hear this argument a lot, but it does not make any sense to me. With `foldl1 (||) (map ($x) tests)`, my guess is that I am folding an operation
by lahvak 5y ago
I don't know, I hear this argument a lot, but it does not make any sense to me. With `foldl1 (||) (map ($x) tests)`, my guess is that I am folding an operation denoted by || (my guess is or?) over some sort of collection that was obtained by mapping some function denoted by $x over what must be another collection called tests. I have been staring at the javascript example for like 5 minutes and I think I know what it does, but I am still confused by it.
- linkdd 5y ago`every()` returns true if every item in a collection verify a predicate (this is the `foldl1 (||)` part of the example). `map()` applies a function to every item in a collection and returns a new collection. What I confuses me about the Haskell example is `$x`. Where does it come from? why isn't it referenced anywhere afterwards? Is the `$` an operator of some sort that names a variable in the later block? Why is it `tests` and not `$tests` then?
- tome 5y ago`($x)` could equivalently have been written `\f -> f x`, which would have been a bit clearer. In general in Haskell if you have an infix operator `OP` then `(OP x)` means the same thing as `\y -> y OP x`. (Additionally in this case you need to know that `$` is defined by `f $ x = f x`.)
- linkdd 5y agoThank you for your clarification. And I just re-read my example in JS and I've made a TERRIBLE mistake ^^ `.every()` would be `foldl1 (&&)`, I would need `.some()` instead to have the correct behavior.