J. Garrett Morris wrote:
More generally, that's unfoldr:

Prelude> :t Data.List.unfoldr
Data.List.unfoldr :: (b -> Maybe (a, b)) -> b -> [a]

unfoldr represents the end of the unfold explicitly (using Nothing)
instead of implicitly (using the empty list).

Duh... of course it does. :-S

Silly thing is, I use unfoldr all the time - for converting integers to bits. *sigh*

Of course, that solves the problem of just wanting to chop the input into chunks. It works less well if you want to do complicated recursive stuff. But IIRC the Parsec library supports parsing of arbitrary tokens (although presumably they have to be in Eq?) so maybe I should revise that...

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to