Skip to content

Commit cbcc8c2

Browse files
committed
+ ZipApplicative docs
1 parent b6168c7 commit cbcc8c2

File tree

6 files changed

+67
-36
lines changed

6 files changed

+67
-36
lines changed

docsrc/content/abstraction-applicative.fsx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ Other operations
2626
2727
* ``lift2``
2828
*)
29+
2930
(**
30-
static member Lift2 (f: 'T1 -> 'T2 -> 'T, x1: 'Applicative<'T1>, x2: 'Applicative<'T2>) : 'Applicative<'T>
31+
static member Lift2 (f: 'T1 -> 'T2 -> 'T, x1: 'Applicative<'T1>, x2: 'Applicative<'T2>) : 'Applicative<'T>
3132
*)
33+
3234
(**
3335
3436
@@ -62,44 +64,44 @@ From F#
6264
- ``IObservable<'T>``
6365
- ``Lazy<'T>``
6466
- ``Async<'T>``
65-
- ``Result<'T,'U>``
66-
- ``Choice<'T,'U>``
67-
- ``KeyValuePair<'Key,'T>``
67+
- ``Result<'T, 'U>``
68+
- ``Choice<'T, 'U>``
69+
- ``KeyValuePair<'Key, 'T>``
6870
- ``'Monoid * 'T``
6971
- ``ValueTuple<'Monoid, 'T>``
7072
- ``Task<'T>``
7173
- ``ValueTask<'T>``
72-
- ``'R->'T``
74+
- ``'R -> 'T``
7375
- ``Expr<'T>``
7476
- ``ResizeArray<'T>``
7577
7678
From F#+
7779
7880
- [``Identity<'T>``](type-identity.html)
79-
- [``Cont<'R,'T>``](type-cont.html)
80-
- [``ContT<'R,'T>``](type-contt.html)
81-
- [``Reader<'R,'T>``](type-reader.html)
82-
- [``ReaderT<'R,'Monad<'T>>``](type-readert.html)
83-
- [``Writer<'Monoid,'T>``](type-writer.html)
81+
- [``Cont<'R, 'T>``](type-cont.html)
82+
- [``ContT<'R, 'T>``](type-contt.html)
83+
- [``Reader<'R, 'T>``](type-reader.html)
84+
- [``ReaderT<'R, 'Monad<'T>>``](type-readert.html)
85+
- [``Writer<'Monoid, 'T>``](type-writer.html)
8486
- [``WriterT<'Monad<'T * 'Monoid>>``](type-writert.html)
85-
- [``State<'S,'T * 'S>``](type-state.html)
86-
- [``StateT<'S,'Monad<'T * 'S>>``](type-statet.html)
87+
- [``State<'S, 'T * 'S>``](type-state.html)
88+
- [``StateT<'S, 'Monad<'T * 'S>>``](type-statet.html)
8789
- [``OptionT<'Monad<option<'T>>``](type-optiont.html)
8890
- [``ValueOptionT<'Monad<voption<'T>>``](type-valueoptiont.html)
8991
- [``SeqT<'Monad<seq<'T>>``](type-seqt.html)
9092
- [``ListT<'Monad<list<'T>>``](type-listt.html)
91-
- [``ResultT<'Monad<Result<'T,'TError>>``](type-resultt.html)
92-
- [``ChoiceT<'Monad<Choice<'T,'TError>>``](type-choicet.html)
93-
- [``Free<'Functor<'T>,'T>``](type-free.html)
93+
- [``ResultT<'Monad<Result<'T, 'TError>>``](type-resultt.html)
94+
- [``ChoiceT<'Monad<Choice<'T, 'TError>>``](type-choicet.html)
95+
- [``Free<'Functor<'T>, 'T>``](type-free.html)
9496
- [``NonEmptyList<'T>``](type-nonempty.html)
95-
- [``Validation<'Error,'T>``](type-validation.html)
97+
- [``Validation<'Error, 'T>``](type-validation.html)
9698
- [``ZipList<'T>``](type-ziplist.html)
9799
- [``ParallelArray<'T>``](type-parallelarray.html)
98-
- [``Const<'C,'T>``](type-const.html)
100+
- [``Const<'C, 'T>``](type-const.html)
99101
- [``Compose<'Applicative1<'Applicative2<'T>>>``](type-compose.html)
100102
- [``DList<'T>``](type-dlist.html)
101-
- [``Vector<'T,'Dimension>``](type-vector.html)
102-
- [``Matrix<'T,'Rows,'Columns>``](type-matrix.html)
103+
- [``Vector<'T, 'Dimension>``](type-vector.html)
104+
- [``Matrix<'T, 'Rows, 'Columns>``](type-matrix.html)
103105
104106
Restricted:
105107
- ``string``

docsrc/content/abstraction-misc.fsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ let res113 = foldi (fun s i t -> t * s - i) 2 [|3;4;5|]
3232
let resSomeId20 = traversei (fun k t -> Some (10 + t)) (Tuple 10)
3333

3434

35-
// ZipFunctor
36-
37-
let (x, y) = zip (async { return 1 }) (async { return '2' }) |> Async.RunSynchronously
38-
39-
4035
// Collection
4136

4237
let a = skip 3 [1..10]

docsrc/content/abstraction-traversable.fsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Minimal complete definition
3030
Other operations
3131
----------------
3232
33-
* ``gather f x`` | ``transpose x`` (same as traverse and sequence but operating on ZipApplicatives)
33+
* ``gather f x`` | ``transpose x`` (same as ``traverse`` and ``sequence`` but operating on [ZipApplicatives](abstraction-zipapplicative.html) )
3434
*)
3535
(**
3636
static member Gather (t: 'Traversable<'T>, f: 'T -> 'ZipApplicative<'U>) : 'ZipApplicative<'Traversable<'U>>
@@ -55,7 +55,7 @@ Related Abstractions
5555
--------------------
5656
5757
- [Functor](abstraction-functor.html): A traversable is generic on the Traversable type parameter and the (Applicative) Functor inner type parameter.
58-
- [Applicative](abstraction-applicative.html): An applicative is a functor whose ``map`` operation can be splitted in ``return`` and ``(<*>)`` operations.
58+
- [Applicative](abstraction-applicative.html): An applicative is a functor whose ``map`` operation can be splitted in ``return`` and ``(<*>)`` operations.
5959
- [Foldable](abstraction-foldable.html) : All traversables are foldables.
6060
6161

docsrc/content/abstraction-zipapplicative.fsx

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#r @"../../src/FSharpPlus/bin/Release/netstandard2.0/FSharpPlus.dll"
55

66
(**
7-
ZipApplicative
8-
==============
7+
Zip Applicative (aka Non-sequential Applicative)
8+
================================================
99
A functor with application, providing operations to embed pure expressions (``pur``), run computations pointwise and/or paralell and combine their results (``<.>``).
1010
___
1111
Minimal complete definition
@@ -29,6 +29,12 @@ Other operations
2929
static member Zip (x1: 'ZipApplicative<'T1>, x2: 'ZipApplicative<'T2>) : 'ZipApplicative<'T1 * 'T2>
3030
*)
3131
(**
32+
* ``unzip``
33+
*)
34+
(**
35+
static member Unzip (x: 'ZipApplicative<'T1 * 'T2>) : 'ZipApplicative<'T1> * 'ZipApplicative<'T2>
36+
*)
37+
(**
3238
* ``map2``
3339
*)
3440
(**
@@ -47,19 +53,32 @@ Other operations
4753
4854
Rules
4955
-----
56+
5057
*)
5158
(**
59+
60+
Since ZipApplicatives are Applicatives they obey the same applicative rules:
61+
5262
pur id <.> v = v
5363
pur (<<) <.> u <.> v <.> w = u <.> (v <.> w)
5464
pur f <*> pur x = pur (f x)
5565
u <*> pur y = pur ((|>) y) <.> u
5666
*)
67+
(**
68+
69+
But they have some additional rules:
70+
71+
zip x y = tuple2 <!> x <.> y
72+
unzip = map fst &&& map snd
73+
id = unzip >> (<||) zip = (<||) zip >> unzip
74+
*)
75+
5776
(**
5877
Related Abstractions
5978
--------------------
6079
- [Functor](abstraction-functor.html): A zipApplicative is a functor whose ``map`` operation can be splitted in ``pur`` and ``(<.>)`` operations,
6180
62-
- [ZipApplicative](abstraction-applicative.html) : ZipApplicatives are applicatives which usually don't form a [Monad](abstraction-monad.html).
81+
- [Applicative](abstraction-applicative.html) : ZipApplicatives are applicatives which usually don't form a [Monad](abstraction-monad.html), therefore the Applicative instance normally is not the same.
6382
6483
Concrete implementations
6584
------------------------
@@ -88,7 +107,7 @@ From F#+
88107
- [``NonEmptyList<'T>``](type-nonempty.html)
89108
- [``Compose<'ZipApplicative1<'ZipApplicative2<'T>>>``](type-compose.html)
90109
91-
(*) The operation is the same as that for the normal applicative
110+
(*) The operations are the same as those for the normal applicative
92111
93112
94113
Only for <*> operation:
@@ -115,8 +134,11 @@ Examples
115134

116135
open FSharpPlus
117136

137+
let (x, y) = zip (async { return 1 }) (async { return '2' }) |> Async.RunSynchronously
138+
// val y: char = '2'
139+
118140

119-
// pointwise operations
141+
// crossproduct vs pointwise operations
120142

121143
let arr1 = (+) <!> [|1;2;3|] <*> [|10;20;30|]
122144
let arr2 = (+) <!> [|1;2;3|] <.> [|10;20;30|]
@@ -129,10 +151,10 @@ let arr2 = (+) <!> [|1;2;3|] <.> [|10;20;30|]
129151

130152
let validated = applicative2' {
131153
let! x = async { return Ok 1 }
132-
and! y = async { return Ok 2 }
133-
and! z = async { return Error ["Error"] }
154+
and! y = async { return Error ["Error1"] }
155+
and! z = async { return Error ["Error2"] }
134156
return x + y + z
135157
}
136158

137159
validated |> Async.RunSynchronously
138-
// val it: Result<int,string list> = Error ["Error"]
160+
// val it: Result<int,string list> = Error ["Error1"; "Error2"]

docsrc/content/computation-expressions.fsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ Computations Expressions
1212
1313
This library allows to use some common computation expressions without writing any boiler plate code.
1414
15-
For applicatives there is single computation expression: ``applicative { .. }``. Additionally ``applicative2 { .. }`` and ``applicative3 { .. }`` exists for composed (aka layered) applicatives.
15+
For [Applicatives](abstraction-applicative.html) there is single computation expression: ``applicative { .. }``. Additionally ``applicative2 { .. }`` and ``applicative3 { .. }`` exists for composed (aka layered) applicatives.
1616
17-
For monadic code there is a single computation expression: ``monad { .. }`` but it comes in 4 flavours:
17+
For [ZipApplicatives](abstraction-zipapplicative.html) there is a counterpart set of computation expressions: ``applicative' { .. }``, ``applicative2' { .. }`` and ``applicative3' { .. }``.
18+
19+
For [monadic](abstraction-monad.html) code there is a single computation expression: ``monad { .. }`` but it comes in 4 flavours:
1820
1921
- Delayed or strict
2022

docsrc/tools/templates/abstractions.plantuml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ abstract class Alternative [[http://fsprojects.github.io/FSharpPlus/abstraction-
4848
+ mfilter p x
4949
}
5050

51+
abstract class ZipApplicative [[http://fsprojects.github.io/FSharpPlus/abstraction-zipapplicative.html]] {
52+
+ pur x
53+
+ (<.>) f x
54+
==
55+
+ map f x
56+
+ map2 f x y
57+
}
58+
5159
abstract class Monad [[http://fsprojects.github.io/FSharpPlus/abstraction-monad.html]] {
5260
+ return x
5361
+ (>>=) x f
@@ -117,13 +125,15 @@ Functor --|> Bifunctor
117125
Functor --|> Applicative
118126
Applicative --|> Monad
119127
Applicative --|> Alternative
128+
ZipApplicative --|> Alternative
120129
Monoid ..|> Monad
121130
Monoid ..|> Foldable
122131
Monoid ..|> Bifoldable
123132
Functor --|> Comonad
124133
Functor --|> Traversable
125134
Foldable --|> Traversable
126135
Bifoldable --|> Bitraversable
136+
Applicative ..|> ZipApplicative
127137
Applicative ..|> Bitraversable
128138
Applicative ..|> Traversable
129139
Monoid ..|> Alternative

0 commit comments

Comments
 (0)