FSharpPlus


Profunctor

A bifunctor that is a contravariant in the first argument and covariant in the second.


Minimal complete definition

static member Dimap (x: 'Profunctor<'T, 'V>, f: 'U -> 'T, g: 'V -> 'W) : 'Profunctor<'U, 'W>

Other operations

static member Contramap (x: 'Profunctor<'T, 'V>, f: 'U -> 'T) : 'Profunctor<'U, 'V>
static member Map (x: 'Profunctor<'T,'V>, f: 'V -> 'W) : 'Profunctor<'T, 'W>

Rules

dimap id id = id
dimap (h' << h) (f << f') = dimap h f << dimap h' f'

Related Abstractions

Concrete implementations

From .Net/F#

From F#+

Examples

#r @"nuget: FSharpPlus"
open System
open FSharpPlus
open FSharpPlus.Data
open FSharpPlus.Math.Generic

module Predicate = let run (p: Predicate<_>) x = p.Invoke (x)

let isEven       = Predicate (fun x -> x % 2 = 0)

let resStrFalse  = dimap int string (Predicate.run isEven) 99.0


let lx x = Char.GetNumericValue x + 100.
let rx x = string (x + 100)
let kl = Kleisli (fun (y:float) -> [int y; int y * 2 ; int y * 3])

let resl = lmap lx kl
let r105n210n315 = Kleisli.run resl '5'
let resr = rmap rx kl
let r105n110n115 = Kleisli.run resr 5.0
let resd = dimap lx rx kl
let r205n310n415 = Kleisli.run resd '5'
Multiple items
module Map from Microsoft.FSharp.Collections

--------------------
type Map<'Key,'Value (requires comparison)> = interface IReadOnlyDictionary<'Key,'Value> interface IReadOnlyCollection<KeyValuePair<'Key,'Value>> interface IEnumerable interface IStructuralEquatable interface IComparable interface IEnumerable<KeyValuePair<'Key,'Value>> interface ICollection<KeyValuePair<'Key,'Value>> interface IDictionary<'Key,'Value> new: elements: ('Key * 'Value) seq -> Map<'Key,'Value> member Add: key: 'Key * value: 'Value -> Map<'Key,'Value> ...

--------------------
new: elements: ('Key * 'Value) seq -> Map<'Key,'Value>
val id: x: 'T -> 'T
namespace System
namespace FSharpPlus
namespace FSharpPlus.Data
namespace FSharpPlus.Math
module Generic from FSharpPlus.Math
<summary> Generic numbers, functions and operators. By opening this module some common operators become restricted, like (+) to 'T-&gt;'T-&gt;'T </summary>
type Predicate<'T> = new: object: obj * method: nativeint -> unit member BeginInvoke: obj: 'T * callback: AsyncCallback * object: obj -> IAsyncResult member EndInvoke: result: IAsyncResult -> bool member Invoke: obj: 'T -> bool
<summary>Represents the method that defines a set of criteria and determines whether the specified object meets those criteria.</summary>
<param name="obj">The object to compare against the criteria defined within the method represented by this delegate.</param>
<typeparam name="T">The type of the object to compare.</typeparam>
<returns><see langword="true" /> if <paramref name="obj" /> meets the criteria defined within the method represented by this delegate; otherwise, <see langword="false" />.</returns>
val run: p: Predicate<'a> -> x: 'a -> bool
val p: Predicate<'a>
val x: 'a
Predicate.Invoke(obj: 'a) : bool
val isEven: Predicate<int>
val x: int
val resStrFalse: string
val dimap: f: ('A -> 'B) -> g: ('C -> 'D) -> source: 'Profunctor<'B,'C> -> 'Profunctor<'A,'D> (requires member Dimap)
<summary> Maps over both arguments at the same time of a Profunctor. </summary>
<category index="6">Contravariant/Bifunctor/Profunctor/Invariant</category>
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int
Multiple items
val string: value: 'T -> string

--------------------
type string = String
val lx: x: char -> float
val x: char
[<Struct>] type Char = member CompareTo: value: char -> int + 1 overload member Equals: obj: char -> bool + 1 overload member GetHashCode: unit -> int member GetTypeCode: unit -> TypeCode member ToString: unit -> string + 2 overloads static member ConvertFromUtf32: utf32: int -> string static member ConvertToUtf32: highSurrogate: char * lowSurrogate: char -> int + 1 overload static member GetNumericValue: c: char -> float + 1 overload static member GetUnicodeCategory: c: char -> UnicodeCategory + 1 overload static member IsAscii: c: char -> bool ...
<summary>Represents a character as a UTF-16 code unit.</summary>
Char.GetNumericValue(c: char) : float
Char.GetNumericValue(s: string, index: int) : float
val rx: x: int -> string
val kl: Kleisli<float,int list>
Multiple items
union case Kleisli.Kleisli: ('t -> 'monad<'u>) -> Kleisli<'t,'monad<'u>>

--------------------
module Kleisli from FSharpPlus.Data
<summary> Basic operations on Kleisli </summary>

--------------------
[<Struct>] type Kleisli<'t,'monad<'u>> = | Kleisli of ('t -> 'monad<'u>) static member (+++) : Kleisli<'T,'u> * Kleisli<'v,'w> -> Kleisli<Choice<'v,'T>,'z> (requires member (>>=) and member Return and member (>>=)) static member (<<<) : Kleisli<'a2,'a3> * Kleisli<'a5,'a4> -> Kleisli<'a5,'a3> (requires member (>>=)) static member ``<|>`` : Kleisli<'a2,'a3> * Kleisli<'a2,'a3> * _mthd: Append -> Kleisli<'a2,'a3> (requires member ``<|>``) static member Arr: f: ('a2 -> 'a3) -> Kleisli<'a2,'a4> (requires member Return) static member Contramap: Kleisli<'B,'Monad<'C>> * k: ('A -> 'B) -> Kleisli<'A,'Monad<'C>> static member Dimap: Kleisli<'B,'Monad<'C>> * ab: ('A -> 'B) * cd: ('C -> 'D) -> Kleisli<'A,'Monad<'D>> (requires member Map) static member Empty: _output: Kleisli<'T,'Monad<'U>> * _mthd: Empty -> Kleisli<'a4,'a5> (requires member Empty) static member First: Kleisli<'a2,'a3> -> Kleisli<('a2 * 'a6),'a4> (requires member (>>=) and member Return) static member Left: Kleisli<'a2,'a3> -> 'a4 (requires member ``+++`` and member Arr) static member Map: Kleisli<'B,'Monad<'C>> * cd: ('C -> 'D) -> Kleisli<'B,'Monad<'D>> (requires member Map) ...
<summary> Kleisli arrows of a monad. Represents a function 'T -&gt; 'Monad&lt;'U&gt; </summary>
val y: float
Multiple items
val float: value: 'T -> float (requires member op_Explicit)

--------------------
type float = Double

--------------------
type float<'Measure> = float
val resl: Kleisli<char,int list>
val lmap: f: ('A -> 'B) -> source: 'Profunctor<'B,'C> -> 'Profunctor<'A,'C> (requires member Contramap)
<summary> Maps over the left part of a Profunctor. </summary>
<category index="6">Contravariant/Bifunctor/Profunctor/Invariant</category>
val r105n210n315: int list
val run: Kleisli<'a,'b> -> ('a -> 'b)
val resr: Kleisli<float,string list>
val rmap: f: ('C -> 'D) -> source: 'Profunctor<'B,'C> -> 'Profunctor<'B,'D> (requires member Map)
<summary> Maps over the right part of a Profunctor. </summary>
<category index="6">Contravariant/Bifunctor/Profunctor/Invariant</category>
val r105n110n115: string list
val resd: Kleisli<char,string list>
val r205n310n415: string list