@@ -10,18 +10,18 @@ The Functor abstraction is used for types that can be mapped over.
10
10
___
11
11
Minimal complete definition
12
12
---------------------------
13
- * ``map f x``/ ``(|>>) x f``/ ``(<<|) f x``/ ``(<!>) f x``
13
+ * ``map f x`` / ``(|>>) x f`` / ``(<<|) f x`` / ``(<!>) f x``
14
14
*)
15
15
(**
16
- static member Map (x:'Functor<'T>, f:'T-> 'U) :'Functor<'U>
16
+ static member Map (x: 'Functor<'T>, f: 'T -> 'U) : 'Functor<'U>
17
17
*)
18
18
(**
19
19
Other operations
20
20
----------------
21
21
* ``unzip x``
22
22
*)
23
23
(**
24
- static member Unzip (x:Functor<'T * 'U>) :'Functor<'T> * 'Functor<'U>
24
+ static member Unzip (x: ' Functor<'T * 'U>) : 'Functor<'T> * 'Functor<'U>
25
25
*)
26
26
(**
27
27
Rules
@@ -54,49 +54,49 @@ From F#
54
54
- ``Async<'T>``
55
55
- ``Result<'T,'U>``
56
56
- ``Choice<'T,'U>``
57
- - ``KeyValuePair<'Key,'T>``
57
+ - ``KeyValuePair<'Key, 'T>``
58
58
- ``Map<'Key,'T>``
59
59
- ``'Monoid * 'T``
60
60
- ``'struct ('Monoid * 'T)``
61
61
- ``Task<'T>``
62
62
- ``ValueTask<'T>``
63
63
- ``'R->'T``
64
64
- ``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>``
68
68
- ``ResizeArray<'T>``
69
69
70
70
From F#+
71
71
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)
77
77
- [``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)
80
80
- [``OptionT<'Monad<option<'T>>``](type-optiont.html)
81
81
- [``ValueOptionT<'Monad<voption<'T>>``](type-valueoptiont.html)
82
82
- [``SeqT<'Monad<seq<'T>>``](type-seqt.html)
83
83
- [``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)
87
87
- [``NonEmptyList<'T>``](type-nonempty.html)
88
88
- [``NonEmptySet<'T>``](type-nonempty-set.html)
89
89
- [``NonEmptyMap<'Key, 'T>``](type-nonempty-map.html)
90
- - [``Validation<'Error,'T>``](type-validation.html)
90
+ - [``Validation<'Error, 'T>``](type-validation.html)
91
91
- [``ZipList<'T>``](type-ziplist.html)
92
92
- [``ParallelArray<'T>``](type-parallelarray.html)
93
- - [``Const<'C,'T>``](type-const.html)
93
+ - [``Const<'C, 'T>``](type-const.html)
94
94
- [``Compose<'AlternativeF<'AlternativeG<'T>>>``](type-compose.html)
95
95
- [``DList<'T>``](type-dlist.html)
96
96
- [``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)
100
100
101
101
Restricted:
102
102
- ``string``
@@ -118,7 +118,7 @@ Examples
118
118
open FSharpPlus
119
119
open FSharpPlus.Math .Generic
120
120
121
- let getLine = async { return System.Console.ReadLine() }
121
+ let getLine = async { return System.Console.ReadLine () }
122
122
let putStrLn x = async { printfn " %s " x}
123
123
let print x = async { printfn " %A " x}
124
124
@@ -141,8 +141,8 @@ let noValue = map minus3 None
141
141
let lstTimes2 = map times2 [ 1 ; 2 ; 3 ; 4 ]
142
142
let fTimes2minus3 = map minus3 times2
143
143
let 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 @>
146
146
147
147
148
148
// try -> runIO getChars ;;
@@ -153,11 +153,11 @@ type Tree<'a> =
153
153
| Leaf of 'a
154
154
static member map f ( t : Tree < 'a > ) =
155
155
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)
158
158
159
159
// 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
161
161
162
162
let myTree = Tree( 6 , Tree( 2 , Leaf 1 , Leaf 3 ), Leaf 9 )
163
163
let mappedTree = map fTimes2minus3 myTree
@@ -167,10 +167,10 @@ let mappedTree = map fTimes2minus3 myTree
167
167
// An Applicative is automatically a Functor
168
168
169
169
type 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>
172
172
173
- let mappedZipList = map string ( ZipList [ 1 ; 2 ; 3 ])
173
+ let mappedZipList = map string ( ZipList [ 1 ; 2 ; 3 ])
174
174
175
175
176
176
// A Monad is automatically a Functor
@@ -179,4 +179,13 @@ type MyList<'s> = MyList of 's seq with
179
179
static member Return ( x : 'a ) = MyList x
180
180
static member (>>= ) ( MyList x: MyList< 'T>, f) = MyList ( Seq.collect ( f >> ( fun ( MyList x ) -> x)) x)
181
181
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