44 ------------------------------------------------------------------------------
55 The MIT License (MIT)
66
7- Copyright (c) 2023-2024 Aarno Labs LLC
7+ Copyright (c) 2023-2025 Aarno Labs LLC
88
99 Permission is hereby granted, free of charge, to any person obtaining a copy
1010 of this software and associated documentation files (the "Software"), to deal
@@ -61,6 +61,25 @@ let tmap2
6161 | Error e1 , Error e2 -> Error (msg1 :: msg2 :: (e1 @ e2))
6262
6363
64+ let tmap3
65+ ?(msg1 =" " )
66+ ?(msg2 =" " )
67+ ?(msg3 =" " )
68+ (f : 'a -> 'b -> 'c -> 'd )
69+ (r1 : 'a traceresult )
70+ (r2 : 'b traceresult )
71+ (r3 : 'c traceresult ): 'd traceresult =
72+ match r1, r2, r3 with
73+ | Ok v1 , Ok v2 , Ok v3 -> Ok (f v1 v2 v3)
74+ | Error e1 , Ok _ , Ok _ -> Error (msg1 :: e1)
75+ | Ok _ , Error e2 , Ok _ -> Error (msg2 :: e2)
76+ | Ok _ , Ok _ , Error e3 -> Error (msg3 :: e3)
77+ | Error e1 , Error e2 , Ok _ -> Error (msg1 :: msg2 :: (e1 @ e2))
78+ | Error e1 , Ok _ , Error e3 -> Error (msg1 :: msg3 :: (e1 @ e3))
79+ | Ok _ , Error e2 , Error e3 -> Error (msg2 :: msg3 :: (e2 @ e3))
80+ | Error e1 , Error e2 , Error e3 -> Error (msg1 :: msg2 :: msg3 :: (e1 @ e2 @ e3))
81+
82+
6483let tbind ?(msg =" " ) (f : 'a -> 'c traceresult ) (r : 'a traceresult ) =
6584 match r with
6685 | Ok v -> f v
@@ -86,7 +105,13 @@ let tprop (r: 'a traceresult) (msg: string): 'a traceresult =
86105 | Error e -> Error (msg :: e)
87106
88107
89- let titer (f : 'a -> unit ) (r : 'a traceresult ) =
108+ let titer ~(ok :'a -> unit ) ~(error : string list -> unit ) (r : 'a traceresult ) =
109+ match r with
110+ | Ok v -> ok v
111+ | Error e -> error e
112+
113+
114+ let titer_default (f : 'a -> unit ) (r : 'a traceresult ) =
90115 match r with
91116 | Ok v -> f v
92117 | Error _ -> ()
0 commit comments