I need to process a string like "46a12b159c" into ["46", "a", "12", "b", "159", "c"]. Functions like (split) which split on a character eliminate that character from the result, and filtering on (isAlpha) or (isDigit) would give me "4612159" or "abc" instead. I could write this function myself, but I'm hoping that there's a pre-existing function -- presumably a more general one which, in this case, would take (isAlpha) and/or (isDigit) as inputs. Presumably something with type String -> (char -> Bool) -> [String], or String -> (char-> Bool) -> (Char -> Bool) -> [String]. (This is to be mapped over a list of strings, and each resulting list of strings is to have another function mapped over it. Not that this has anything to do with what the function I'm asking about needs to be.) Thanks.
BTW, when I tried sending this as e-mail I got the bounce notice "We're writing to let you know that the group you tried to contact (bahaskell) may not exist, or you may not have permission to post messages to the group." What gives?
If you have only digits and alphas, groupBy will do it:
Prelude> :m +Data.List
Prelude Data.List> s
"46a12b159c"
Prelude Data.List> :m +Char
Prelude Data.List Char> groupBy (\a b -> isDigit a == isDigit b) s
["46","a","12","b","159","c"]
On Tue, Jun 26, 2012 at 3:03 PM, Dudley Brooks <dudley...@gmail.com> wrote:
> I need to process a string like "46a12b159c" into ["46", "a", "12", "b",
> "159", "c"]. Functions like (split) which split on a character eliminate
> that character from the result, and filtering on (isAlpha) or (isDigit)
> would give me "4612159" or "abc" instead. I could write this function
> myself, but I'm hoping that there's a pre-existing function -- presumably a
> more general one which, in this case, would take (isAlpha) and/or (isDigit)
> as inputs. Presumably something with type String -> (char -> Bool) ->
> [String], or String -> (char-> Bool) -> (Char -> Bool) -> [String].
> (This is to be mapped over a list of strings, and each resulting list of
> strings is to have another function mapped over it. Not that this has
> anything to do with what the function I'm asking about needs to be.)
Thanks, Nathan, Aaron, and Richard, that's exactly what I'm looking for. If I had thought up possible names better, I would have searched on "group..." rather than "split...". ;^)
And now ... what do I have to do to be able to post here by e-mail? I keep getting bounce notices.
-- Dudley
On Tue, Jun 26, 2012 at 4:01 PM, Dudley Brooks wrote:
> And now ... what do I have to do to be able to post here by e-mail? I keep
> getting bounce notices.
My guess is your email client is sending from an address other than
the one you are subscribed under.
--
You received this message because you are subscribed to the Google Groups "Bay Area Haskell Users Group" group.
To view this discussion on the web visit https://groups.google.com/d/msg/bahaskell/-/tyKAK6r2WY0J.