Skip to content

Commit 7e71844

Browse files
committed
Add comments/type annotations
1 parent f0cd254 commit 7e71844

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

src/FSharpPlus/Data/Seq.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ module SeqT_V2 =
167167
[<Literal>]
168168
let private enumNotStarted = "Enumeration has not started. Call MoveNext."
169169

170+
/// Creates a SeqT sequence from an IEnumerableM.
170171
let ofIEnumerableM x : SeqT<'``Monad<bool>``, 'T> = SeqT x
171172

172173
[<RequireQualifiedAccess; EditorBrowsable(EditorBrowsableState.Never)>]
@@ -209,6 +210,8 @@ module SeqT_V2 =
209210
dispose e1
210211
| _ -> () } }
211212

213+
214+
/// Transforms a regular sequence into a SeqT, driven by the return type.
212215
let inline ofSeq (source: seq<'T>) : SeqT<'``Monad<bool>``, 'T> =
213216
SeqT
214217
{ new IEnumerableM<'``Monad<bool>``, 'T> with
@@ -242,6 +245,7 @@ module SeqT_V2 =
242245
dispose e
243246
| _ -> () } }
244247

248+
/// Transforms a regular sequence into a SeqT, driven by the return type.
245249
let inline hoist (source: seq<'T>) : SeqT<'``Monad<bool>``, 'T> = wrap (result source: '``Monad<seq<'T>>``)
246250

247251
[<EditorBrowsable(EditorBrowsableState.Never)>]
@@ -342,9 +346,11 @@ module SeqT_V2 =
342346
{ new IEnumerableM<'``Monad<bool>``, 'T> with
343347
member _.GetEnumerator () = (f () :> IEnumerableM<'``Monad<bool>``, 'T>).GetEnumerator () }
344348

349+
/// A combination of bind and lift operations.
345350
let inline bindLift<'T, 'U, .. > (f: 'T -> SeqT<'``Monad<bool>``, 'U>) (source: '``Monad<'T>``) : SeqT<'``Monad<bool>``, 'U> =
346351
make (fun () -> innerMonad<'``Monad<SeqT<'Monad<bool>, 'U>>``> { let! v = source in return f v })
347352

353+
/// Lifts the source into the SeqT.
348354
let inline lift (source: '``Monad<'T>``) : SeqT<'``Monad<bool>``, 'T> =
349355
SeqT
350356
{ new IEnumerableM<'``Monad<bool>``, 'T> with
@@ -941,7 +947,7 @@ module SeqT_V2 =
941947
/// <returns>The result sequence.</returns>
942948
///
943949
/// <exception cref="T:System.ArgumentNullException">Thrown when count is negative.</exception>
944-
/// <exception cref="T:System.InvalidOperationException">Thrown when count exceeds the number of elements
950+
/// <exception cref="T:System.InvalidOperationException">Thrown when count exceeds the number of elements.
945951
/// in the sequence.</exception>
946952
let inline take count (source: SeqT<'``Monad<bool>``, 'T>) : SeqT<'``Monad<bool>``, 'T> =
947953
if (count < 0) then invalidArg "count" "must be non-negative"

src/FSharpPlus/Data/Validation.fs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,15 @@ module Validation =
101101

102102
#endif
103103

104-
let bimap (f: 'T1->'U1) (g: 'T2->'U2) = function
105-
| Failure e -> Failure (f e)
106-
| Success a -> Success (g a)
104+
/// <summary>Maps both success and failure of a Validation.</summary>
105+
/// <param name="failureMapper">Function to be applied to source, if it contains a Failure value.</param>
106+
/// <param name="successMapper">Function to be applied to source, if it contains a Success value.</param>
107+
/// <param name="source">The source value, containing a Success or a Failure.</param>
108+
/// <returns>The result of applying the corresponding mapping function.</returns>
109+
let bimap (failureMapper: 'TError -> 'UError) (successMapper: 'T -> 'U) source =
110+
match source with
111+
| Failure e -> Failure (failureMapper e)
112+
| Success a -> Success (successMapper a)
107113

108114
let bifoldBack f g (source: Validation<'Error,'T>) (state: 'State) : 'State =
109115
match source with
@@ -117,7 +123,7 @@ module Validation =
117123
| Failure e -> f e x
118124

119125
/// Like traverse but taking an additional function to traverse the Failure part as well.
120-
let inline bitraverse (f: 'Error1->'``Functor<'Error2>``) (g: 'T1->'``Functor<'T2>``) (source: Validation<'Error1,'T1>) : '``Functor<Validation<'Error2,'T2>>`` =
126+
let inline bitraverse (f: 'TError -> '``Functor<'UError>``) (g: 'T -> '``Functor<'U>``) (source: Validation<'TError, 'T>) : '``Functor<Validation<'UError, 'U>>`` =
121127
match source with
122128
| Success a -> Validation<'Error2,'T2>.Success <!> g a
123129
| Failure e -> Validation<'Error2,'T2>.Failure <!> f e
@@ -180,11 +186,11 @@ module Validation =
180186
let ofChoice (x: Choice<'T,'Error>) = match x with Choice1Of2 a -> Success a | Choice2Of2 e -> Failure e
181187

182188
/// <summary> Extracts a value from either side of a Validation.</summary>
183-
/// <param name="fSuccess">Function to be applied to source, if it contains a Success value.</param>
184-
/// <param name="fFailure">Function to be applied to source, if it contains a Failure value.</param>
189+
/// <param name="successMapper">Function to be applied to source, if it contains a Success value.</param>
190+
/// <param name="failureMapper">Function to be applied to source, if it contains a Failure value.</param>
185191
/// <param name="source">The source value, containing a Success or a Failure.</param>
186192
/// <returns>The result of applying either functions.</returns>
187-
let either (fSuccess: 'T->'U) (fFailure: 'Error->'U) source = match source with Success v -> fSuccess v | Failure e -> fFailure e
193+
let either (failureMapper: 'TError -> 'U) (successMapper: 'T -> 'U) source = match source with Success v -> successMapper v | Failure e -> failureMapper e
188194

189195
[<System.Obsolete("This function will not be supported in future versions.")>]
190196
let validate (e: 'e) (p: 'a -> bool) (a: 'a) : Validation<'e,'a> = if p a then Success a else Failure e
@@ -193,18 +199,18 @@ module Validation =
193199
/// validationNel : Result<'a,'e> -> Validation (NonEmptyList<'e>) a
194200
/// This is 'liftError' specialized to 'NonEmptyList', since
195201
/// they are a common semigroup to use.
196-
let validationNel (x: Result<_,_>) : (Validation<NonEmptyList<'e>,'a>) = (liftResult result) x
202+
let validationNel (x: Result<'T, 'TError>) : (Validation<NonEmptyList<'TError>, 'T>) = (liftResult result) x
197203
#endif
198204

199205
[<System.Obsolete("This function will not be supported in future versions.")>]
200206
let ensure (e: 'e) (p: 'a-> bool) = function
201207
| Failure x -> Failure x
202208
| Success a -> validate e p a
203209

204-
/// Creates a safe version of the supplied function, which returns a Validation<exn,'U> instead of throwing exceptions.
205-
let protect (f: 'T->'U) x =
210+
/// Creates a safe version of the supplied function, which returns a Validation<exn, 'U> instead of throwing exceptions.
211+
let protect (unsafeFunction: 'T -> 'U) x =
206212
try
207-
Success (f x)
213+
Success (unsafeFunction x)
208214
with e -> Failure e
209215

210216
#if !FABLE_COMPILER
@@ -221,7 +227,7 @@ module Validation =
221227
/// <returns>
222228
/// A tuple with both resulting lists, Success are in the first list.
223229
/// </returns>
224-
let partition (source: list<Validation<'Error,'T>>) =
230+
let partition (source: list<Validation<'TErrors, 'T>>) =
225231
let rec loop ((acc1, acc2) as acc) = function
226232
| [] -> acc
227233
| x::xs ->

src/FSharpPlus/Memoization.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ module Memoization =
2020
static member getOrAdd (cd: ConcurrentDictionary<MemoizationKeyWrapper<'a>,'b>) (f: 'a -> 'b) k =
2121
cd.GetOrAdd (MemoizationKeyWrapper k, (fun (MemoizationKeyWrapper x) -> x) >> f)
2222

23-
let inline memoizeN (f:'``(T1 -> T2 -> ... -> Tn)``): '``(T1 -> T2 -> ... -> Tn)`` =
23+
/// Memoizes a function taking an arbitrary number of parameters.
24+
let inline memoizeN (f: '``(T1 -> T2 -> ... -> Tn)``) : '``(T1 -> T2 -> ... -> Tn)`` =
2425
let inline call_2 (a: ^MemoizeN, b: ^b) = ((^MemoizeN or ^b) : (static member MemoizeN : ^MemoizeN * 'b -> _ ) (a, b))
2526
call_2 (Unchecked.defaultof<MemoizeN>, Unchecked.defaultof<'``(T1 -> T2 -> ... -> Tn)``>) f
2627

src/FSharpPlus/Operators.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -984,13 +984,13 @@ module Operators =
984984
/// Converts to a Collection from a list.
985985
/// </summary>
986986
/// <category index="19">Collection</category>
987-
let inline ofList (source: list<'T>) = OfList.Invoke source : 'Collection
987+
let inline ofList (source: list<'T>) = OfList.Invoke source : '``Collection<'T>``
988988

989989
/// <summary>
990990
/// Converts to a Collection from a seq.
991991
/// </summary>
992992
/// <category index="19">Collection</category>
993-
let inline ofSeq (source: seq<'T> ) = OfSeq.Invoke source : 'Collection
993+
let inline ofSeq (source: seq<'T> ) = OfSeq.Invoke source : '``Collection<'T>``
994994

995995
/// <summary>Returns a new collection containing only the elements of the collection
996996
/// for which the given predicate returns "true"</summary>
@@ -999,7 +999,7 @@ module Operators =
999999
/// <param name="predicate">The function to test the input elements.</param>
10001000
/// <param name="source">The input collection.</param>
10011001
/// <returns>A collection containing only the elements that satisfy the predicate.</returns>
1002-
let inline filter (predicate: _->bool) (source: 'Collection) : 'Collection = Filter.Invoke predicate source
1002+
let inline filter (predicate: 'T -> bool) (source: '``Collection<'T>``) : '``Collection<'T>`` = Filter.Invoke predicate source
10031003

10041004
/// <summary>Returns a collection that skips N elements of the original collection and then yields the
10051005
/// remaining elements of the collection.</summary>

0 commit comments

Comments
 (0)