package profunctor

  1. Overview
  2. Docs

A module used to traverse each field of a record performing some action using a specific profunctor.

You can construct a record builder for a given profunctor using Record_builder.

This is based on the library Record_builder (which provides traversal with an applicative) and adds the contravariant mapping of each field.

type t = {
  name : string;
  age : int;
} [@@deriving fields]

module F : Profunctor.S = "your module here"
module F_of_record = Profunctor.Record_builder(F)

let for_string : (string, string) F.t = "your code here"
let for_int : (int, int) F.t = "your code here"

let example : (t, t) F.t =
  F_of_record.(build_for_record (
    Fields.make_creator
      ~name:(field for_string)
      ~age:(field for_int)))

This is equivalent to:

let example : (t, t) F.t =
  let name = F.contra_map ~f:name for_string
  and age = F.contra_map ~f:age for_int
  in
  F.map (F.both name age) ~f:(fun (name, age) ->
    { name; age; })
;;
type ('b, 'a) profunctor
type 'a profunctor_term

A term of the profunctor where the input and output type are the same.

Although this module must use the type parameters separately internally all terms supplied as arguments or returned will have both type parameters equal. This type alias is used to allow automatically converting with some other type in some cases e.g. Of_conv_based.

val prj : ('a, 'a) profunctor -> 'a profunctor_term
val inj : 'a profunctor_term -> ('a, 'a) profunctor
module Bare : Record_builder.S2 with type ('b, 'a) applicative = ('b, 'a) profunctor

The underlying applicative record builder, which does not perform the contravariant mapping.

val field : 'field profunctor_term -> ('record, 'field) Base.Field.t -> ('field, _, _, 'record) Bare.Make_creator_types.handle_one_field

Supply the term for one field.

The type of this function is designed to match up with Fields.make_creator (see the example).

val build_for_record : ('record, _, 'record) Bare.Make_creator_types.handle_all_fields -> 'record profunctor_term

Build the overarching profunctor for the whole record.

This takes a partial application of Fields.make_creator as its argument, which should supply no initial value but use field to supply a term for every field of the record.

The type of this is designed to match up with Fields.make_creator (see the example).