Skip to content

Commit

Permalink
Merge pull request #277 from CohenArthur/stdlib/maybe
Browse files Browse the repository at this point in the history
Add Maybe_int type
  • Loading branch information
CohenArthur authored Oct 14, 2021
2 parents 4fa56ab + 44e289c commit 80f1807
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions stdlib/lib.jk
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
incl pair
incl string
incl maybe
22 changes: 22 additions & 0 deletions stdlib/maybe.jk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// type Nothing;
// type Some_int(inner: int);

// TODO: Implement Maybe<T> once generics are implemented
// TODO: Implement Maybe<T> as multi-type once they are implemented
type Maybe_int(inner: int, is_some: bool)

func is_some(m: Maybe_int) -> bool {
m.is_some
}

func nothing() -> Maybe_int {
Maybe_int { inner = 0, is_some = false }
}

func some(value: int) -> Maybe_int {
Maybe_int { inner = value, is_some = true }
}

func unpack(m: Maybe_int) -> int {
m.inner
}
5 changes: 5 additions & 0 deletions tests/ft/stdlib/maybe.jk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
m_manual = Maybe_int { inner = 14, is_nothing = false };
m_some = some(15);
m_nothing = nothing();

a = m_some.unpack();
4 changes: 4 additions & 0 deletions tests/ft/stdlib/stdlib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ tests:
args:
- "tests/ft/stdlib/string/concat.jk"
stdout: "jinko.jk"
- name: "Test Maybe is a valid type"
binary: "target/debug/jinko"
args:
- "tests/ft/stdlib/maybe.jk"

0 comments on commit 80f1807

Please sign in to comment.