Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0320ac959b | |||
| dcef89b486 | |||
| 4957d01e9e | |||
| 9d76e6186a |
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Added
|
### Added
|
||||||
|
- `Option.force_msg`
|
||||||
### Changed
|
### Changed
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
|||||||
+14
-4
@@ -362,7 +362,7 @@ namespace Chain =
|
|||||||
|
|
||||||
#### tx_hash
|
#### tx_hash
|
||||||
```
|
```
|
||||||
Auth.tx_hash : option(Chain.tx)
|
Auth.tx_hash : option(hash)
|
||||||
```
|
```
|
||||||
|
|
||||||
Gets the transaction hash during authentication.
|
Gets the transaction hash during authentication.
|
||||||
@@ -824,7 +824,7 @@ payable contract Auction =
|
|||||||
stateful entrypoint sell(amount) =
|
stateful entrypoint sell(amount) =
|
||||||
require(amount >= 0, "negative_amount")
|
require(amount >= 0, "negative_amount")
|
||||||
...
|
...
|
||||||
|
|
||||||
main contract Market =
|
main contract Market =
|
||||||
type state = list(Auction)
|
type state = list(Auction)
|
||||||
entrypoint init() = []
|
entrypoint init() = []
|
||||||
@@ -876,7 +876,7 @@ payable contract interface Auction =
|
|||||||
entrypoint init : (int, string) => void
|
entrypoint init : (int, string) => void
|
||||||
stateful payable entrypoint buy : (int) => ()
|
stateful payable entrypoint buy : (int) => ()
|
||||||
stateful entrypoint sell : (int) => ()
|
stateful entrypoint sell : (int) => ()
|
||||||
|
|
||||||
main contract Market =
|
main contract Market =
|
||||||
type state = list(Auction)
|
type state = list(Auction)
|
||||||
entrypoint init() = []
|
entrypoint init() = []
|
||||||
@@ -1293,7 +1293,17 @@ Escapes `option` wrapping by providing default value for `None`.
|
|||||||
Option.force(o : option('a)) : 'a
|
Option.force(o : option('a)) : 'a
|
||||||
```
|
```
|
||||||
|
|
||||||
Forcefully escapes `option` wrapping assuming it is `Some`. Throws error on `None`.
|
Forcefully escapes the `option` wrapping assuming it is `Some`.
|
||||||
|
Aborts on `None`.
|
||||||
|
|
||||||
|
|
||||||
|
#### force_msg
|
||||||
|
```
|
||||||
|
Option.force_msg(o : option('a), err : string) : 'a
|
||||||
|
```
|
||||||
|
|
||||||
|
Forcefully escapes the `option` wrapping assuming it is `Some`.
|
||||||
|
Aborts with `err` error message on `None`.
|
||||||
|
|
||||||
|
|
||||||
#### contains
|
#### contains
|
||||||
|
|||||||
@@ -26,6 +26,12 @@ namespace Option =
|
|||||||
None => abort("Forced None value")
|
None => abort("Forced None value")
|
||||||
Some(x) => x
|
Some(x) => x
|
||||||
|
|
||||||
|
/** Assume it is `Some` with custom error message
|
||||||
|
*/
|
||||||
|
function force_msg(o : option('a), err : string) : 'a = switch(o)
|
||||||
|
None => abort(err)
|
||||||
|
Some(x) => x
|
||||||
|
|
||||||
function contains(e : 'a, o : option('a)) = o == Some(e)
|
function contains(e : 'a, o : option('a)) = o == Some(e)
|
||||||
|
|
||||||
function on_elem(o : option('a), f : 'a => unit) : unit = match((), f, o)
|
function on_elem(o : option('a), f : 'a => unit) : unit = match((), f, o)
|
||||||
|
|||||||
Reference in New Issue
Block a user