Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Nth function #144

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Stdlib/Data/List/Base.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ drop {A} : (elemsNum : Nat) -> (list : List A) -> List A
| (suc n) (x :: xs) := drop n xs
| _ xs := xs;

--- Take the nth value of a ;List;
nth {A} : Nat -> List A -> Maybe A

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the named syntax to allow people using it in case the want to?

| n := drop n >> headMaybe;

--- 𝒪(𝓃). Returns a tuple where first element is the
--- prefix of the given list of length prefixLength and second element is the
--- remainder of the ;List;.
Expand Down Expand Up @@ -165,6 +169,11 @@ head {A} (defaultValue : A) (list : List A) : A :=
| x :: _ := x
| nil := defaultValue;

--- 𝒪(1). Grabs the first element of a ;List;
headMaybe {A} : List A -> Maybe A
| (x :: _) := just x
| nil := nothing;

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

--- 𝒪(𝓃). Returns ;true; if at least one element of the ;List; satisfies the predicate.
Expand Down
16 changes: 13 additions & 3 deletions index.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ Compiler: http://github.com/anoma/juvix
module index;

import Stdlib.Prelude;
import Stdlib.Data.Nat.Ord;
import Stdlib.Data.Int.Ord;
import Stdlib.Data.String.Ord;

import Stdlib.Data.BinaryTree;
import Stdlib.Data.Set;
import Stdlib.Data.Map;
import Stdlib.Data.UnbalancedSet;
import Stdlib.Data.Queue;
import Stdlib.Data.Tree;

import Stdlib.Cairo.Ec;
import Stdlib.Cairo.Poseidon;
import Stdlib.Cairo.Pedersen;

import Stdlib.Debug;

import Stdlib.Extra.Gcd;
Loading