Skip to content

Commit

Permalink
Add the mapi function
Browse files Browse the repository at this point in the history
I'm unsure if we can add this to a trait or not
  • Loading branch information
mariari committed Nov 8, 2024
1 parent ecfb567 commit 79f5c75
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Stdlib/Data/List/Base.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ listMap {A B} (fun : A -> B) : (list : List A) -> List B
| nil := nil
| (h :: hs) := fun h :: listMap fun hs;

--- 𝒪(𝓃). Maps a function over each element of a ;List; with an index.
{-# specialize: [1] #-}
mapi {A B} : (fun : Nat -> A -> B) -> List A -> List B
| fun xs :=
let
go : Nat -> List A -> List B
| _ nil := nil
| n (x :: xs) := fun n x :: go (suc n) xs;
in go zero xs;

syntax iterator filter {init := 0; range := 1};

--- 𝒪(𝓃). Filters a ;List; according to a given predicate, i.e.,
Expand Down

0 comments on commit 79f5c75

Please sign in to comment.