From fea0260a7a85f50546cf0e22146e3e8673906db1 Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Fri, 6 Jan 2023 15:38:49 +0100 Subject: [PATCH] Get List.filter and List.init ready for long Lists --- .../Base/0.0.0-dev/src/Data/List.enso | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/List.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/List.enso index 6069d72cdda81..4b7a9545a93e1 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/List.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/List.enso @@ -290,7 +290,16 @@ type List take_start : Integer -> List take_start self count = if count <= 0 then Nil else case self of Nil -> Nil - Cons a b -> Cons a (b.take_start count-1) + Cons a b -> + go c l fill = if c <= 0 then fill Nil else case l of + Nil -> fill Nil + Cons a b -> + res = Meta.atom_with_hole (e -> Cons a e) + fill res.value + @Tail_Call go c-1 b res.fill + res = Meta.atom_with_hole (e -> Cons a e) + go count-1 b res.fill + res.value ## Get the first element from the list. @@ -328,12 +337,21 @@ type List example_init = Examples.list.init init : List ! Empty_Error init self = - init_fn x y = case y of - Nil -> Nil - Cons a b -> Cons x (init_fn a b) case self of Nil -> Error.throw Empty_Error - Cons a b -> init_fn a b + Cons a Nil -> Nil + Cons a b -> + go l fill = case l of + Cons x xs -> case xs of + Nil -> fill Nil + Cons y z -> + res = Meta.atom_with_hole (e -> Cons y e) + fill res.value + @Tail_Call go xs res.fill + + res = Meta.atom_with_hole (e -> Cons a e) + go b res.fill + res.value ## Get the last element of the list.