package travesty

  1. Overview
  2. Docs
Monadically traversable containers

Install

Dune Dependency

Authors

Maintainers

Sources

travesty-v0.3.0.tbz
sha256=40ada5c475cfeba7d933eec133294d1b5ef5da6ce864c9746b2ce4ce49b5e3a4
md5=dc818d6b232f13edb388d25781cd99a2

doc/src/travesty/t_monad.ml.html

Source file t_monad.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
(* This file is part of 'travesty'.

   Copyright (c) 2018 by Matt Windsor

   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 Base

module type Extensions = sig
  type 'a t

  val when_m   : bool -> f:(unit -> unit t) -> unit t
  val unless_m : bool -> f:(unit -> unit t) -> unit t
  val tee_m    : 'a   -> f:('a   -> unit t) -> 'a   t
end

module Extend (M : Monad.S) : Extensions with type 'a t := 'a M.t = struct
  let when_m predicate ~f = if predicate then f () else M.return ()
  let unless_m predicate ~f = if predicate then M.return () else f ()
  let tee_m x ~f = M.(f x >>| Fn.const x)
end

module To_mappable (M : Monad.S)
  : Mappable.S1 with type 'a t := 'a M.t = struct
  let map = M.map
end

module S2_to_S (M : Monad.S2) (B : T)
  : Monad.S with type 'a t := ('a, B.t) M.t =
  Monad.Make (struct
    type 'a t = ('a, B.t) M.t
    let map = `Custom M.map
    let return = M.return
    let bind = M.bind
  end)
;;
OCaml

Innovation. Community. Security.