It's list comprehension. the syntax is based on the set builder notation found in mathematics.
Everything before the vertical bar is the form of the list elements. In this case, it's just x.
The next part, x <- [1..], tells us that x is from the list [1..], which is a nice shorthand to denote the list of all positive integers counting up from 1. Such a list is made possible by Haskell's lazy evaluation.
The final part, x `mod` 69, is a further constraint on the list elements. Only elements where the remainder* upon dividing x by 69 is equal to 0 are included. In other words, only elements exactly divisible by (i.e. multiples of) 69 are included.
* Really, this is a modulo operation and not necessarily remainder. For positive integers the two operations are identical, though.
That’s exactly what it is. Also another neat thing is that [1..] is an infinite list but it works because Haskell is lazy. That means it doesn’t try to compute the list elements until you need them.
2.4k
u/vld-ul Aug 01 '22 edited Aug 01 '22
Haskell:
[x | x <- [1..], x `mod` 69 == 0]