From abfd08731f5b5bb70da4ce4a6cfbffef2a24bd2d Mon Sep 17 00:00:00 2001 From: Dull Bananas Date: Wed, 22 Apr 2020 21:05:03 -0700 Subject: [PATCH 1/3] Add String.split example to show that it always returns at least one list item even if the string is empty --- src/String.elm | 1 + 1 file changed, 1 insertion(+) diff --git a/src/String.elm b/src/String.elm index 0e60bdd6..caa3db2e 100644 --- a/src/String.elm +++ b/src/String.elm @@ -184,6 +184,7 @@ concat strings = split "," "cat,dog,cow" == ["cat","dog","cow"] split "/" "home/evan/Desktop/" == ["home","evan","Desktop", ""] + split "," "" == [""] -} split : String -> String -> List String From 04ce85caa9bc9974f391a1b405b209357a7b2a11 Mon Sep 17 00:00:00 2001 From: Dull Bananas Date: Sun, 26 Jul 2020 06:51:04 +0000 Subject: [PATCH 2/3] Revert "Add String.split example" This reverts commit abfd08731f5b5bb70da4ce4a6cfbffef2a24bd2d. --- src/String.elm | 1 - 1 file changed, 1 deletion(-) diff --git a/src/String.elm b/src/String.elm index caa3db2e..0e60bdd6 100644 --- a/src/String.elm +++ b/src/String.elm @@ -184,7 +184,6 @@ concat strings = split "," "cat,dog,cow" == ["cat","dog","cow"] split "/" "home/evan/Desktop/" == ["home","evan","Desktop", ""] - split "," "" == [""] -} split : String -> String -> List String From c57a14e79ca421fba2297c9f351c9a36fa729d73 Mon Sep 17 00:00:00 2001 From: Dull Bananas Date: Sun, 26 Jul 2020 07:10:33 +0000 Subject: [PATCH 3/3] Improve List.length performance --- src/List.elm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/List.elm b/src/List.elm index 83f411c0..d4979002 100644 --- a/src/List.elm +++ b/src/List.elm @@ -249,7 +249,17 @@ maybeCons f mx xs = -} length : List a -> Int length xs = - foldl (\_ i -> i + 1) 0 xs + lengthHelp xs 0 + + +lengthHelp : List a -> Int -> Int +lengthHelp list acc = + case list of + [] -> + acc + + _ :: xs -> + lengthHelp xs (acc + 1) {-| Reverse a list.