From 61e7cd7ccf8511558b79d8d0eceb6fa782c10d6b Mon Sep 17 00:00:00 2001 From: Lukasz Czajka Date: Wed, 6 Nov 2024 18:23:35 +0100 Subject: [PATCH 1/3] add new modules to index.juvix --- index.juvix | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/index.juvix b/index.juvix index b5d09be2..7b307b9a 100644 --- a/index.juvix +++ b/index.juvix @@ -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; From a567cf1722488a441dad94230e7aac7e53353e6e Mon Sep 17 00:00:00 2001 From: mariari Date: Thu, 7 Nov 2024 13:17:35 +0800 Subject: [PATCH 2/3] Add a maybe head function The naming on this is probably bad, I'd assume `head` would return Maybe, and you'd have a headDefault or something for a default head --- Stdlib/Data/List/Base.juvix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Stdlib/Data/List/Base.juvix b/Stdlib/Data/List/Base.juvix index bc8d0900..589836ff 100644 --- a/Stdlib/Data/List/Base.juvix +++ b/Stdlib/Data/List/Base.juvix @@ -165,6 +165,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. From 386b38e483b4bc8d9d543fc4b8a16f2e66fdad12 Mon Sep 17 00:00:00 2001 From: mariari Date: Thu, 7 Nov 2024 15:18:59 +0800 Subject: [PATCH 3/3] Write the nth function --- Stdlib/Data/List/Base.juvix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Stdlib/Data/List/Base.juvix b/Stdlib/Data/List/Base.juvix index 589836ff..4ea06ecd 100644 --- a/Stdlib/Data/List/Base.juvix +++ b/Stdlib/Data/List/Base.juvix @@ -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 + | 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;.