package tezos-lwt-result-stdlib
Tezos: error-aware stdlib replacement
Install
Dune Dependency
Authors
Maintainers
Sources
tezos-v12.3.tar.bz2
sha256=296bb5674bc6050afe6330326fbdd0dfc2255d414bfd6b79cc7666ac6b39316d
sha512=c061cd300a9410300851158d77bf8e56ca3c568b0b1161b38305e5b2efdcd9c746d391f832fdb2826f9a1d6babce10a9b764a4b04f5df42699f7314b9863123a
doc/src/bare_structs/seq_es.ml.html
Source file seq_es.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
(*****************************************************************************) (* *) (* Open Source License *) (* Copyright (c) 2021 Nomadic Labs <contact@nomadic-labs.com> *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) (* to deal in the Software without restriction, including without limitation *) (* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) (* and/or sell copies of the Software, and to permit persons to whom the *) (* Software is furnished to do so, subject to the following conditions: *) (* *) (* The above copyright notice and this permission notice shall be included *) (* in all copies or substantial portions of the Software. *) (* *) (* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) (* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) (* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) (* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) (* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) (* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) (* DEALINGS IN THE SOFTWARE. *) (* *) (*****************************************************************************) open Monad (* This module is about sequences mixed in with Lwt+result, the most common monad here is the combined Lwt-Result monad, we open its syntax module for the whole file (and shadow it when needed. *) open Lwt_result_syntax type (+'a, 'e) node = Nil | Cons of 'a * ('a, 'e) t and ('a, 'e) t = unit -> (('a, 'e) node, 'e) result Lwt.t let protect seq () = Lwt.apply seq () let nil = Nil let nil_e = Ok Nil let nil_es = Lwt.return nil_e let empty () = nil_es (* we define [return] at the end of the file to avoid shadowing the opened Lwt_result_syntax *) let return_e r () = let*? x = r in return (Cons (x, empty)) let return_s p () = let open Lwt_syntax in let* x = p in return_ok (Cons (x, empty)) let return_es p () = let* x = p in return (Cons (x, empty)) let interrupted e () = Lwt.return (Error e) let interrupted_s p () = Lwt_syntax.( let* ) p Lwt.return_error let cons item t () = return (Cons (item, t)) let cons_e item t () = match item with | Error _ as e -> Lwt.return e | Ok item -> return (Cons (item, t)) let cons_s item t () = let open Lwt_syntax in let* item = item in return_ok (Cons (item, t)) let cons_es item t () = let* item = item in return (Cons (item, t)) let rec append ta tb () = let* n = ta () in match n with | Nil -> tb () | Cons (item, ta) -> return (Cons (item, append ta tb)) let first s = let open Lwt_syntax in let* n_r = s () in match n_r with | Ok Nil -> return_none | Ok (Cons (x, _)) -> return_some (Ok x) | Error _ as error -> return_some error let rec fold_left f acc seq = let* n = seq () in match n with | Nil -> return acc | Cons (item, seq) -> fold_left f (f acc item) seq let fold_left f acc seq = fold_left f acc @@ protect seq let rec fold_left_e f acc seq = let* n = seq () in match n with | Nil -> return acc | Cons (item, seq) -> let*? acc = f acc item in fold_left_e f acc seq let fold_left_e f acc seq = fold_left_e f acc @@ protect seq let rec fold_left_s f acc seq = let* n = seq () in match n with | Nil -> return acc | Cons (item, seq) -> let*! acc = f acc item in fold_left_s f acc seq let fold_left_s f acc seq = fold_left_s f acc @@ protect seq let rec fold_left_es f acc seq = let* n = seq () in match n with | Nil -> return acc | Cons (item, seq) -> let* acc = f acc item in fold_left_es f acc seq let fold_left_es f acc seq = fold_left_es f acc @@ protect seq let rec iter f seq = let* n = seq () in match n with | Nil -> return_unit | Cons (item, seq) -> f item ; iter f seq let iter f seq = iter f @@ protect seq let rec iter_e f seq = let* n = seq () in match n with | Nil -> return_unit | Cons (item, seq) -> let*? () = f item in iter_e f seq let iter_e f seq = iter_e f @@ protect seq let rec iter_s f seq = let* n = seq () in match n with | Nil -> Lwt_result_syntax.return_unit | Cons (item, seq) -> let*! () = f item in iter_s f seq let iter_s f seq = iter_s f @@ protect seq let rec iter_es f seq = let* n = seq () in match n with | Nil -> Lwt_result_syntax.return_unit | Cons (item, seq) -> let* () = f item in iter_es f seq let iter_es f seq = iter_es f @@ protect seq let rec map f seq () = let* n = seq () in match n with | Nil -> nil_es | Cons (item, seq) -> return (Cons (f item, map f seq)) let map f seq = map f @@ protect seq let rec map_e f seq () = let* n = seq () in match n with | Nil -> nil_es | Cons (item, seq) -> let*? item = f item in return (Cons (item, map_e f seq)) let map_e f seq = map_e f @@ protect seq let rec map_s f seq () = let* n = seq () in match n with | Nil -> nil_es | Cons (item, seq) -> let*! item = f item in return (Cons (item, map_s f seq)) let map_s f seq = map_s f @@ protect seq let rec map_es f seq () = let* n = seq () in match n with | Nil -> nil_es | Cons (item, seq) -> let* item = f item in return (Cons (item, map_es f seq)) let map_es f seq = map_es f @@ protect seq let rec map_error f seq () = let open Lwt_syntax in let* n_r = seq () in match n_r with | Ok Nil -> nil_es | Ok (Cons (item, seq)) -> return_ok (Cons (item, map_error f seq)) | Error e -> return_error (f e) let map_error f seq = map_error f @@ protect seq let rec map_error_s f seq () = let open Lwt_syntax in let* n_r = seq () in match n_r with | Ok Nil -> nil_es | Ok (Cons (item, seq)) -> return_ok (Cons (item, map_error_s f seq)) | Error e -> let* e = f e in return_error e let rec filter f seq () = let* n = seq () in match n with | Nil -> nil_es | Cons (item, seq) -> if f item then return (Cons (item, seq)) else filter f seq () let filter f seq = filter f @@ protect seq let rec filter_e f seq () = let* n = seq () in match n with | Nil -> nil_es | Cons (item, seq) -> let*? b = f item in if b then return (Cons (item, filter_e f seq)) else filter_e f seq () let filter_e f seq = filter_e f @@ protect seq let rec filter_s f seq () = let* n = seq () in match n with | Nil -> nil_es | Cons (item, seq) -> let*! b = f item in if b then return (Cons (item, filter_s f seq)) else filter_s f seq () let filter_s f seq = filter_s f @@ protect seq let rec filter_es f seq () = let* n = seq () in match n with | Nil -> nil_es | Cons (item, seq) -> let* b = f item in if b then return (Cons (item, filter_es f seq)) else filter_es f seq () let filter_es f seq = filter_es f @@ protect seq let rec filter_map f seq () = let* n = seq () in match n with | Nil -> nil_es | Cons (item, seq) -> ( match f item with | None -> filter_map f seq () | Some item -> return (Cons (item, filter_map f seq))) let filter_map f seq = filter_map f @@ protect seq let rec filter_map_e f seq () = let* n = seq () in match n with | Nil -> nil_es | Cons (item, seq) -> ( let*? o = f item in match o with | None -> filter_map_e f seq () | Some item -> return (Cons (item, filter_map_e f seq))) let filter_map_e f seq = filter_map_e f @@ protect seq let rec filter_map_s f seq () = let* n = seq () in match n with | Nil -> nil_es | Cons (item, seq) -> ( let*! o = f item in match o with | None -> filter_map_s f seq () | Some item -> return (Cons (item, filter_map_s f seq))) let filter_map_s f seq = filter_map_s f @@ protect seq let rec filter_map_es f seq () = let* n = seq () in match n with | Nil -> nil_es | Cons (item, seq) -> ( let* o = f item in match o with | None -> filter_map_es f seq () | Some item -> return (Cons (item, filter_map_es f seq))) let filter_map_es f seq = filter_map_es f @@ protect seq let rec unfold f a () = match f a with | None -> nil_es | Some (item, a) -> return (Cons (item, unfold f a)) let rec unfold_s f a () = let open Lwt_syntax in let* cont = f a in match cont with | None -> nil_es | Some (item, a) -> return_ok (Cons (item, unfold_s f a)) let rec unfold_e f a () = match f a with | Error _ as e -> Lwt.return e | Ok None -> nil_es | Ok (Some (item, a)) -> return (Cons (item, unfold_e f a)) let rec unfold_es f a () = let* n = f a in match n with | None -> nil_es | Some (item, a) -> return (Cons (item, unfold_es f a)) let rec of_seq seq () = match seq () with | Stdlib.Seq.Nil -> nil_es | Stdlib.Seq.Cons (e, seq) -> return (Cons (e, of_seq seq)) let rec of_seq_e seq () = match seq () with | Stdlib.Seq.Nil -> nil_es | Stdlib.Seq.Cons (Ok e, seq) -> return (Cons (e, of_seq_e seq)) | Stdlib.Seq.Cons ((Error _ as e), _) -> Lwt.return e let rec of_seqe seq () = match seq () with | Ok Seq_e.Nil -> nil_es | Ok (Seq_e.Cons (item, seq)) -> return (Cons (item, of_seqe seq)) | Error _ as e -> Lwt.return e let rec of_seq_s seq () = match seq () with | Stdlib.Seq.Nil -> nil_es | Stdlib.Seq.Cons (p, seq) -> let open Lwt_syntax in let* e = p in return_ok (Cons (e, of_seq_s seq)) let rec of_seqs seq () = let open Lwt_syntax in let* n = seq () in match n with | Seq_s.Nil -> nil_es | Seq_s.Cons (e, seq) -> return_ok (Cons (e, of_seqs seq)) let rec of_seq_es seq () = match seq () with | Stdlib.Seq.Nil -> nil_es | Stdlib.Seq.Cons (p, seq) -> let* e = p in return (Cons (e, of_seq_es seq)) let return x () = return (Cons (x, empty))
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>