I tried to find a code for searching prime numbers but there is hardly anything written in elm, not much in any other functional programmng language either. Maybe the primes are not an interesting topic in a language used mainly in frontend codes. Perhaps it’s piece of cake to write a code for Eratoshenes sieve in FP and it’s assumed everybody can do it for him(her)self.
There is one exception, Haskell, see Sieve of Eratosthenes but I don’t read haskell.
I wrote a little piece just for begin using elm repl…
This shall find all primes of the range 1 … 121.
The primes used in sieve [2,3,5,7,11] are dropped from beginning of the resulting list.
sieve prime integers = List.filter (\i → remainderBy prime i > 0) integers
: Int → List Int → List Int
il = List.range 1 121
sieve 2 il |> sieve 3 |> sieve 5 |> sieve 7 |> sieve 11
[1,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113]
: List Int
How about using combination of sieve function, map2 and filter or foldl or recursion and sieve?
I don’t know yet.