Skip to content

Commit

Permalink
Get List.filter and List.init ready for long Lists
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Jan 6, 2023
1 parent 9484ae0 commit fea0260
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/List.enso
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down

0 comments on commit fea0260

Please sign in to comment.