From 18423073f692480fb3f61d759bdd46d4f1461561 Mon Sep 17 00:00:00 2001 From: Mike Zornek Date: Sat, 31 Aug 2024 14:23:39 -0400 Subject: [PATCH] Update `String.split/2` into `String.split/3` There is no `String.split/2`, best I can tell. https://hexdocs.pm/elixir/String.html#split/3 But `String.split/3` does behave as the blog post explains. ``` iex(1)> String.split("") [] iex(2)> String.split("", ",") [""] ``` --- _posts/2024-08-28-typing-lists-and-tuples.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/2024-08-28-typing-lists-and-tuples.markdown b/_posts/2024-08-28-typing-lists-and-tuples.markdown index c0998bf86..b6ca81f6c 100644 --- a/_posts/2024-08-28-typing-lists-and-tuples.markdown +++ b/_posts/2024-08-28-typing-lists-and-tuples.markdown @@ -97,7 +97,7 @@ While different developers will prefer certain idioms over others, I am not conv ### What about Elixir? -Thanks to set-theoretic types, we will most likely distinguish between empty lists and non-empty lists in Elixir's type system, since pattern matching on them is a common language idiom. Furthermore, several functions in Elixir, such as `String.split/2` are guaranteed to return non-empty lists, which can then be nicely encoded into a function's return type. +Thanks to set-theoretic types, we will most likely distinguish between empty lists and non-empty lists in Elixir's type system, since pattern matching on them is a common language idiom. Furthermore, several functions in Elixir, such as `String.split/3` are guaranteed to return non-empty lists, which can then be nicely encoded into a function's return type. Elixir also has the functions `hd` (for head) and `tl` (for tail) inherited from Erlang, which are [valid guards](https://hexdocs.pm/elixir/patterns-and-guards.html). They only accept non-empty lists as arguments, which will now be enforced by the type system too.