From e124c13a9a61b54ec28f5787c6ebe083be2d9ae9 Mon Sep 17 00:00:00 2001 From: mariari Date: Thu, 7 Nov 2024 13:17:35 +0800 Subject: [PATCH] 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.