mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
List.keepOks and List.keepErrs
This commit is contained in:
parent
45edb12b22
commit
3fe80b1a1e
12 changed files with 339 additions and 44 deletions
|
@ -86,3 +86,22 @@ pub fn allocateWithRefcount(
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub const RocResult = extern struct {
|
||||
bytes: ?[*]u8,
|
||||
|
||||
pub fn isOk(self: RocResult) bool {
|
||||
// assumptions
|
||||
//
|
||||
// - the tag is the first field
|
||||
// - the tag is usize bytes wide
|
||||
// - Ok has tag_id 1, because Err < Ok
|
||||
const usizes: [*]usize = @ptrCast([*]usize, @alignCast(8, self.bytes));
|
||||
|
||||
return usizes[0] == 1;
|
||||
}
|
||||
|
||||
pub fn isErr(self: RocResult) bool {
|
||||
return !self.isOk();
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue