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 maybe utils #658

Open
wants to merge 1 commit into
base: dev
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
10 changes: 8 additions & 2 deletions lib/std/core/maybe.kk
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ pub fun default( m : maybe<a>, nothing : a ) : a
Just(x) -> x

// Get the value of the `Just` constructor or raise an exception
pub fun unjust( m : maybe<a> ) : exn a
pub fun unjust( m : maybe<a>, ?kk-file-line: string) : exn a
match m
Just(x) -> x
Nothing -> throw("unexpected Nothing in std/core/maybe/unjust")
Nothing -> throw("unexpected Nothing in " ++ ?kk-file-line)

// Get the value of the `Just` constructor or raise an exception with `error-msg`
pub fun expect( m : maybe<a>, error-msg: string) : exn a
match m
Just(x) -> x
Nothing -> throw(error-msg)

pub fun map( m : maybe<a>, f : a -> e b ) : e maybe<b>
match m
Expand Down
10 changes: 8 additions & 2 deletions lib/std/core/maybe2.kk
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ pub fun default( m : maybe2<a,b>, nothing : (a,b) ) : (a,b)
Just2(x,y) -> (x,y)

// Get the value of the `Just` constructor or raise an exception
pub fun unjust2( m : maybe2<a,b> ) : exn (a,b)
pub fun unjust( m : maybe2<a,b>, ?kk-file-line: string) : exn (a,b)
match m
Just2(x,y) -> (x,y)
Nothing2 -> throw("unexpected Nothing2 in std/core/maybe/unjust2")
Nothing2 -> throw("unexpected Nothing2 in " ++ ?kk-file-line)

// Get the value of the `Just` constructor or raise an exception
pub fun expect( m : maybe2<a,b>, error-msg: string) : exn (a,b)
match m
Just2(x,y) -> (x,y)
Nothing2 -> throw(error-msg)

pub fun map( m : maybe2<a,b>, f : (a,b) -> e (c,d) ) : e maybe2<c,d>
match m
Expand Down