@@ -10,18 +10,18 @@ The Functor abstraction is used for types that can be mapped over.
1010___
1111Minimal complete definition
1212---------------------------
13- * ``map f x``/ ``(|>>) x f``/ ``(<<|) f x``/ ``(<!>) f x``
13+ * ``map f x`` / ``(|>>) x f`` / ``(<<|) f x`` / ``(<!>) f x``
1414*)
1515(**
16- static member Map (x:'Functor<'T>, f:'T-> 'U) :'Functor<'U>
16+ static member Map (x: 'Functor<'T>, f: 'T -> 'U) : 'Functor<'U>
1717*)
1818(**
1919Other operations
2020----------------
2121 * ``unzip x``
2222*)
2323(**
24- static member Unzip (x:Functor<'T * 'U>) :'Functor<'T> * 'Functor<'U>
24+ static member Unzip (x: ' Functor<'T * 'U>) : 'Functor<'T> * 'Functor<'U>
2525*)
2626(**
2727Rules
@@ -54,49 +54,49 @@ From F#
5454 - ``Async<'T>``
5555 - ``Result<'T,'U>``
5656 - ``Choice<'T,'U>``
57- - ``KeyValuePair<'Key,'T>``
57+ - ``KeyValuePair<'Key, 'T>``
5858 - ``Map<'Key,'T>``
5959 - ``'Monoid * 'T``
6060 - ``'struct ('Monoid * 'T)``
6161 - ``Task<'T>``
6262 - ``ValueTask<'T>``
6363 - ``'R->'T``
6464 - ``Expr<'T>``
65- - ``Dictionary<'Key,'T>``
66- - ``IDictionary<'Key,'T>``
67- - ``IReadOnlyDictionary<'Key,'T>``
65+ - ``Dictionary<'Key, 'T>``
66+ - ``IDictionary<'Key,' T>``
67+ - ``IReadOnlyDictionary<'Key, 'T>``
6868 - ``ResizeArray<'T>``
6969
7070From F#+
7171
72- - [``Cont<'R,'T>``](type-cont.html)
73- - [``ContT<'R,'T>``](type-contt.html)
74- - [``Reader<'R,'T>``](type-reader.html)
75- - [``ReaderT<'R,'Monad<'T>>``](type-readert.html)
76- - [``Writer<'Monoid,'T>``](type-writer.html)
72+ - [``Cont<'R, 'T>``](type-cont.html)
73+ - [``ContT<'R, 'T>``](type-contt.html)
74+ - [``Reader<'R, 'T>``](type-reader.html)
75+ - [``ReaderT<'R, 'Monad<'T>>``](type-readert.html)
76+ - [``Writer<'Monoid, 'T>``](type-writer.html)
7777 - [``WriterT<'Monad<'T * 'Monoid>>``](type-writert.html)
78- - [``State<'S,'T * 'S>``](type-state.html)
79- - [``StateT<'S,'Monad<'T * 'S>>``](type-statet.html)
78+ - [``State<'S, 'T * 'S>``](type-state.html)
79+ - [``StateT<'S, 'Monad<'T * 'S>>``](type-statet.html)
8080 - [``OptionT<'Monad<option<'T>>``](type-optiont.html)
8181 - [``ValueOptionT<'Monad<voption<'T>>``](type-valueoptiont.html)
8282 - [``SeqT<'Monad<seq<'T>>``](type-seqt.html)
8383 - [``ListT<'Monad<list<'T>>``](type-listt.html)
84- - [``ResultT<'Monad<Result<'T,'TError>>``](type-resultt.html)
85- - [``ChoiceT<'Monad<Choice<'T,'TError>>``](type-choicet.html)
86- - [``Free<'Functor<'T>,'T>``](type-free.html)
84+ - [``ResultT<'Monad<Result<'T, 'TError>>``](type-resultt.html)
85+ - [``ChoiceT<'Monad<Choice<'T, 'TError>>``](type-choicet.html)
86+ - [``Free<'Functor<'T>, 'T>``](type-free.html)
8787 - [``NonEmptyList<'T>``](type-nonempty.html)
8888 - [``NonEmptySet<'T>``](type-nonempty-set.html)
8989 - [``NonEmptyMap<'Key, 'T>``](type-nonempty-map.html)
90- - [``Validation<'Error,'T>``](type-validation.html)
90+ - [``Validation<'Error, 'T>``](type-validation.html)
9191 - [``ZipList<'T>``](type-ziplist.html)
9292 - [``ParallelArray<'T>``](type-parallelarray.html)
93- - [``Const<'C,'T>``](type-const.html)
93+ - [``Const<'C, 'T>``](type-const.html)
9494 - [``Compose<'AlternativeF<'AlternativeG<'T>>>``](type-compose.html)
9595 - [``DList<'T>``](type-dlist.html)
9696 - [``Kleisli<'T, 'Monad<'U>>``](type-kleisli.html)
97- - [``Coproduct<'FunctorL<'T>,'FunctorR<'T>>``](type-coproduct.html)
98- - [``Vector<'T,'Dimension>``](type-vector.html)
99- - [``Matrix<'T,'Rows,'Columns>``](type-matrix.html)
97+ - [``Coproduct<'FunctorL<'T>, 'FunctorR<'T>>``](type-coproduct.html)
98+ - [``Vector<'T, 'Dimension>``](type-vector.html)
99+ - [``Matrix<'T, 'Rows, 'Columns>``](type-matrix.html)
100100
101101Restricted:
102102 - ``string``
@@ -118,7 +118,7 @@ Examples
118118open FSharpPlus
119119open FSharpPlus.Math .Generic
120120
121- let getLine = async { return System.Console.ReadLine() }
121+ let getLine = async { return System.Console.ReadLine () }
122122let putStrLn x = async { printfn " %s " x}
123123let print x = async { printfn " %A " x}
124124
@@ -141,8 +141,8 @@ let noValue = map minus3 None
141141let lstTimes2 = map times2 [ 1 ; 2 ; 3 ; 4 ]
142142let fTimes2minus3 = map minus3 times2
143143let res39 = fTimes2minus3 21 G
144- let getChars = map ( fun ( x : string ) -> x.ToCharArray() |> Seq.toList ) action
145- let quot7 = map ((+) 2 ) <@ 5 @>
144+ let getChars = map ( fun ( x : string) -> x.ToCharArray () |> Seq.toList) action
145+ let quot7 = map ((+) 2 ) <@ 5 @>
146146
147147
148148// try -> runIO getChars ;;
@@ -153,11 +153,11 @@ type Tree<'a> =
153153 | Leaf of 'a
154154 static member map f ( t : Tree < 'a > ) =
155155 match t with
156- | Leaf x -> Leaf ( f x)
157- | Tree( x, t1, t2) -> Tree( f x, Tree.map f t1, Tree.map f t2)
156+ | Leaf x -> Leaf ( f x)
157+ | Tree ( x, t1, t2) -> Tree ( f x, Tree.map f t1, Tree.map f t2)
158158
159159// add instance for Functor class
160- static member Map ( x : Tree < _ >, f ) = Tree.map f x
160+ static member Map ( x : Tree < _ >, f ) = Tree.map f x
161161
162162let myTree = Tree( 6 , Tree( 2 , Leaf 1 , Leaf 3 ), Leaf 9 )
163163let mappedTree = map fTimes2minus3 myTree
@@ -167,10 +167,10 @@ let mappedTree = map fTimes2minus3 myTree
167167// An Applicative is automatically a Functor
168168
169169type ZipList < 's > = ZipList of 's seq with
170- static member Return ( x : 'a ) = ZipList ( Seq.initInfinite ( konst x))
171- static member (<*>) ( ZipList ( f : seq < 'a -> 'b >), ZipList x ) = ZipList ( Seq.zip f x |> Seq.map ( fun ( f , x ) -> f x)) : ZipList< 'b>
170+ static member Return ( x : 'a ) = ZipList ( Seq.initInfinite ( konst x))
171+ static member (<*>) ( ZipList ( f : seq < 'a -> 'b >), ZipList x ) = ZipList ( Seq.zip f x |> Seq.map ( fun ( f , x ) -> f x)) : ZipList< 'b>
172172
173- let mappedZipList = map string ( ZipList [ 1 ; 2 ; 3 ])
173+ let mappedZipList = map string ( ZipList [ 1 ; 2 ; 3 ])
174174
175175
176176// A Monad is automatically a Functor
@@ -179,4 +179,13 @@ type MyList<'s> = MyList of 's seq with
179179 static member Return ( x : 'a ) = MyList x
180180 static member (>>= ) ( MyList x: MyList< 'T>, f) = MyList ( Seq.collect ( f >> ( fun ( MyList x ) -> x)) x)
181181
182- let mappedMyList = map string ( MyList [ 1 ; 2 ; 3 ])
182+ let mappedMyList = map string ( MyList [ 1 ; 2 ; 3 ])
183+
184+
185+ (**
186+ Recommended reading
187+ -------------------
188+
189+ - Highly recommended Matt Thornton's blog [Grokking Functors](https://dev.to/choc13/grokking-functors-bla).
190+ It contains examples using F#+ and an explanation from scratch.
191+ *)
0 commit comments