aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2023-04-02 22:40:29 +0200
committerAndreas Grois <andi@grois.info>2023-04-02 22:40:29 +0200
commit7d1acb295b0dc9ebde45f6828d01baa8c6dce023 (patch)
tree719be8654b94d7a775eb90d31c35ff919a44f023
parent073c5319f4f2bfddd2bb4070b9f4ce346c407a2e (diff)
Example: Fix inconsistency in cashier handling.
-rw-r--r--examples/text-adventure/logic.rs7
-rw-r--r--src/lib.rs7
2 files changed, 10 insertions, 4 deletions
diff --git a/examples/text-adventure/logic.rs b/examples/text-adventure/logic.rs
index 3f05555..87ea8bb 100644
--- a/examples/text-adventure/logic.rs
+++ b/examples/text-adventure/logic.rs
@@ -217,7 +217,12 @@ fn handle_checkout<'a, 's: 'a>(
0 => { FreeSausageRoll::pure((Location::Shelves, inventory.clone())) },
1 => {
run!{
- r <= try_pay(inventory.clone());
+ r <= if inventory.items.is_empty() {
+ let inventory = inventory.clone();
+ exposition("You didn't take anything in the store, so you just walk past the cashier.").bind(move |_| FreeSausageRoll::pure(Ok(inventory.clone()))) as FreeSausageRoll<Result<Inventory, Inventory>>
+ } else {
+ try_pay(inventory.clone())
+ };
match r {
Ok(inventory) => {
run!{
diff --git a/src/lib.rs b/src/lib.rs
index e15d7cc..233153e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -59,7 +59,8 @@
//! There is work ongoing to [add explicit clone support to higher](https://github.com/bodil/higher/issues/6) though, so this might no longer be an issue with
//! later higher versions.
-#[doc(hidden)] //that this is re-exported is an implementation detail. Users should import directly from higher imho.
+#[doc(hidden)]
+//that this is re-exported is an implementation detail. Users should import directly from higher imho.
pub extern crate higher;
/// The macro that generates a Free [`Monad`][higher::Monad] type for a given [`Functor`][higher::Functor].
@@ -746,14 +747,14 @@ mod free_monad_tests {
let left = (m.0)(7u32);
match left {
FreeConti::Pure(v) => {
- assert_nearly_equal!(v, 5f64 * 23f64, f64::EPSILON)
+ assert_nearly_equal!(v, 5f64 * 23f64, f64::EPSILON);
}
FreeConti::Free(_) => unreachable!(),
}
let right = (m.1)(7u32);
match right {
FreeConti::Pure(v) => {
- assert_nearly_equal!(v, 5f64 * 45f64, f64::EPSILON)
+ assert_nearly_equal!(v, 5f64 * 45f64, f64::EPSILON);
}
FreeConti::Free(_) => unreachable!(),
}