Created
May 23, 2016 01:09
Elm: Split List into a List of Lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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