import Html exposing (text)
splitWith fn list =
List.foldr
(\next total ->
case total of
[] ->
if fn next then
[]
else
[next] :: total
first :: rest ->
if fn next then
[] :: total
else
(next :: first) :: rest
)
[]
list
main =
[1,2,3]
|> splitWith ((==) 2)
|> toString
|> text
Hey! Just wanted to post my solution (let me know if there is a bug!).
Thanks for the fun problem :)
On Saturday, November 12, 2016 at 5:46:53 PM UTC-8, Laurence Roberts 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.