Hello elm folks, I have a beginner question about Random.list:
Without access to the Generator type constructor, how can one build totally novel kinds of list-based generators? For example, suppose you want to construct a list generator that terminates not after an integer number of iterations (i.e. Random.list), but after a condition determined by inspecting one or more items in the list? Example: *Generate a list of integers between 0 and 10 until the last one is 5*. It seems like this class of generators requires a version of Random.list that accepts a function in place of the integer argument, which is passed say, the last generated element of the list and returns a Bool indicating whether the list is complete. It could look something like this: list : (Maybe a -> Bool) -> Generator a -> Generator (List a) list pred (Generator generate) = Generator <| \seed -> listHelp [] pred generate seed listHelp : List a -> (Maybe a -> Bool) -> (Seed -> (a,Seed)) -> Seed -> ( List a, Seed) listHelp list pred generate seed = if pred <| head list then (List.reverse list, seed) else let (value, newSeed) = generate seed in listHelp (value :: list) pred generate newSeed Is it possible to construct this generator using only the primitives currently exposed by Random? And if it can be done, why isn’t Random.list itself implemented using those same primitives? Thanks, Matt -- 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 elm-discuss+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.