I have a function that takes a random Generator and turns it into a
LazyList. The reason for this is so that I can combine random streams
together with other lazy streams that I have using the Lazy.List library.
The function uses the exposed Lazy.List.LazyListView type, which I would
rather avoid if it makes sense to:
generate : Generator a -> Seed -> LazyList a
generate generator seed =
let
( value, newSeed ) =
Random.step generator seed
in
lazy <|
\() ->
Cons value (generate generator newSeed)
This version uses iterate on a (a, Seed) -> (a, Seed) function, but then
requires a map on the tuple to extract just the random items:
generate2 : Generator a -> Seed -> LazyList a
generate2 generator seed =
let
firstValueSeed =
Random.step generator seed
step ( value, seed ) =
Random.step generator seed
in
LL.iterate step firstValueSeed
|> LL.map first
Is there some obvious way of doing this without the extra map operation? or
perhaps that will compile down efficiently anyway.
Does there perhaps need to be a variation on the Lazy.List.cons constructor
that takes a '() -> LazyList a' argument to allow the cons operation to be
passed as a continuation?
Rupert
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.