Skip to content

Commit e345848

Browse files
committed
std: Add a module for errors
1 parent c9d7a26 commit e345848

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

std/errors/error.pics

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
// Module: Error
3+
// Functions for creating and handling error
4+
Error :: module {
5+
6+
// Function: error
7+
// Creates a new error from the value provided
8+
//
9+
// Parameters:
10+
// err - (Any) The value that represents an error
11+
//
12+
// Returns:
13+
// Tuple - A tuple of Unit and the value provided
14+
//
15+
// Example:
16+
// --Code:
17+
// err := Error::error("This is an error")
18+
// --
19+
//
20+
error :: (err) = ((), err)
21+
22+
23+
// Function: success
24+
// Creates a new success value from the value provided
25+
//
26+
// Parameters:
27+
// value - (Any) The value that represents an error
28+
//
29+
// Returns:
30+
// Tuple - A tuple of the value provided and Unit
31+
//
32+
// Example:
33+
// --Code:
34+
// success := Error::success("This is a correct value")
35+
// --
36+
//
37+
success :: (value) = (value, ())
38+
39+
// Function: getValueOr
40+
// Gets the value of the if not an error and executes the function
41+
// passed incase of an error
42+
//
43+
// Parameters:
44+
// error - (Tuple) The value you are not sure is valid
45+
// fx - (Function) The function to execute
46+
//
47+
// Returns:
48+
// Any - The non-error value or the result of executing the function
49+
//
50+
getValueOr :: (error, fx) = error catch fx(err)
51+
}
52+

0 commit comments

Comments
 (0)