Skip to content

Commit e124c13

Browse files
mariarilukaszcz
authored andcommitted
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
1 parent b50851a commit e124c13

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Stdlib/Data/List/Base.juvix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ head {A} (defaultValue : A) (list : List A) : A :=
165165
| x :: _ := x
166166
| nil := defaultValue;
167167

168+
--- 𝒪(1). Grabs the first element of a ;List;
169+
headMaybe {A} : List A -> Maybe A
170+
| (x :: _) := just x
171+
| nil := nothing;
172+
168173
syntax iterator any {init := 0; range := 1};
169174

170175
--- 𝒪(𝓃). Returns ;true; if at least one element of the ;List; satisfies the predicate.

0 commit comments

Comments
 (0)