So, to be clear, you want to remove, and split on, any element that
satisfies the predicate?
How's this?
splitWith : (a -> Bool) -> List a -> List (List a)
splitWith =
let
helper accum current f lst =
case lst of
[] ->
accum
(first :: rest) ->
if (f first) then
helper (accum ++ [current]) [] f rest
else
helper accum (current ++ [first]) f rest
in
helper [] []
On Sat, Nov 12, 2016 at 5:46 PM, Laurence Roberts <[email protected]>
wrote:
> How would you write this function:
>
> splitWith : (a -> Bool) -> List a -> List (List a)
>
> such that this is true:
>
> splitWith (\x -> x == 2) [1,2,3,4,2,5,6,7] == [[1],[3,4],[5,6,7]]
>
> It's clear how to would do it in non-FP but I'm struggling to visualise it
> in FP, it's been a little while since I've done any.
>
> --
> 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.
>
--
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.