From d2c3486f633bd17498648557b805485c1e247a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8jberg?= Date: Tue, 13 Aug 2024 11:32:41 -0400 Subject: [PATCH] Add pipeline utility functions --- src/Lib/Util.elm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Lib/Util.elm b/src/Lib/Util.elm index 64707116..96c02013 100644 --- a/src/Lib/Util.elm +++ b/src/Lib/Util.elm @@ -66,6 +66,25 @@ decodeFailInvalid failMessage m = Decode.succeed a +pipeMaybe : (b -> a -> a) -> Maybe b -> a -> a +pipeMaybe f may a = + case may of + Just b -> + f b a + + Nothing -> + a + + +pipeIf : (a -> a) -> Bool -> a -> a +pipeIf f cond a = + if cond then + f a + + else + a + + decodeTag : Decode.Decoder String decodeTag = Decode.field "tag" Decode.string