stdlib: Add Result and Option types
Since the type checker sucks less now, we can think about maybe adding some features to the language. ...At some point I'd like to have the type checker clean up the index map.
This commit is contained in:
21
stdlib/std/option.cl
Normal file
21
stdlib/std/option.cl
Normal file
@@ -0,0 +1,21 @@
|
||||
//! The optional type, representing the presence or absence of a thing.
|
||||
|
||||
pub enum Option<T> {
|
||||
Some(T),
|
||||
None,
|
||||
}
|
||||
|
||||
impl Option {
|
||||
pub fn is_some(self: &Self) -> bool {
|
||||
match self {
|
||||
Some(_) => true,
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
pub fn is_none(self: &Self) -> bool {
|
||||
match self {
|
||||
Some(_) => false,
|
||||
None => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user