Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Elm: Split List into a List of Lists
import Html exposing (..)
import List
split : Int -> List a -> List (List a)
split i list =
case List.take i list of
[] -> []
listHead ->
-- [1,2] (listHead)
-- [3,4,5]
-- [3,4] (listHead)
-- [5]
-- [5] (listHead)
-- [5] -> []
-- [3,4] -> [[5]]
-- [1,2] -> [[3,4], [5]]
-- [[1,2], [3,4], [5]]
listHead :: split i (List.drop i list)
test : List number
test =
[1,2,3,4,5]
main =
Html.text (toString (split 2 test))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment