Skip to content

Instantly share code, notes, and snippets.

@chrisbuttery
Created May 23, 2016 01:09
Show Gist options
  • Save chrisbuttery/f878a8984ab4c9e7977d85a4acc8f35e to your computer and use it in GitHub Desktop.
Save chrisbuttery/f878a8984ab4c9e7977d85a4acc8f35e to your computer and use it in GitHub Desktop.
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