OSDN Git Service

Chaining with andThen works but is ugly.
authorsforman <sforman@hushmail.com>
Sat, 2 Sep 2023 16:38:15 +0000 (09:38 -0700)
committersforman <sforman@hushmail.com>
Sat, 2 Sep 2023 16:38:15 +0000 (09:38 -0700)
It's lees clear to me what's going on, and I wrote it.

implementations/Elm/src/Joy.elm

index 0099016..3a67534 100644 (file)
@@ -507,17 +507,7 @@ joy_swaack stack expression =
 
 joy_swap : JoyFunction
 joy_swap stack expression =
-    case pop_any stack of
-        Ok ( a, s0 ) ->
-            case pop_any s0 of
-                Ok ( b, s1 ) ->
-                    Ok ( b :: a :: s1, expression )
-
-                Err msg ->
-                    Err msg
-
-        Err msg ->
-            Err msg
+    pop_any stack |> andThen (\(a, s0) -> (pop_any s0 |> andThen (\( b, s1 ) -> Ok ( b :: a :: s1, expression ))))
 
 
 joy_truthy : JoyFunction