Skip to content

Commit 09cf4be

Browse files
committed
Merge branch 'master' into v1.3
2 parents a78cfa3 + 70350cf commit 09cf4be

File tree

6 files changed

+50
-30
lines changed

6 files changed

+50
-30
lines changed

src/FSharpPlus/Builders.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ module GenericBuilders =
341341
#endif
342342
member inline _.MergeSources (t1: '``Applicative<'T>``, t2: '``Applicative<'U>``) : '``Applicative<'T * 'U>`` = Lift2.Invoke tuple2 t1 t2
343343
member inline _.MergeSources3 (t1: '``Applicative<'T>``, t2: '``Applicative<'U>``, t3: '``Applicative<'V>``) : '``Applicative<'T * 'U * 'V>`` = Lift3.Invoke tuple3 t1 t2 t3
344-
member _.Run f = f : '``applicative<'t>``
344+
member _.Run f = f : '``Applicative<'T>``
345345

346346
/// Generic 2 layers Applicative CE builder.
347347
type ApplicativeBuilder2<'``applicative1<applicative2<'t>>``> () =
@@ -355,7 +355,7 @@ module GenericBuilders =
355355
#endif
356356
member inline _.MergeSources (t1, t2) : '``Applicative1<Applicative2<'T>>`` = (lift2 >> lift2) tuple2 t1 t2
357357
member inline _.MergeSources3 (t1, t2, t3) : '``Applicative1<Applicative2<'T>>`` = (lift3 >> lift3) tuple3 t1 t2 t3
358-
member _.Run x : '``applicative1<applicative2<'t>>`` = x
358+
member _.Run x : '``Applicative1<Applicative2<'T>>`` = x
359359

360360
/// Generic 3 layers Applicative CE builder.
361361
type ApplicativeBuilder3<'``applicative1<applicative2<applicative3<'t>>>``> () =
@@ -369,7 +369,7 @@ module GenericBuilders =
369369
#endif
370370
member inline _.MergeSources (t1, t2) : '``Applicative1<Applicative2<Applicative3<'T>>>`` = (lift2 >> lift2 >> lift2) tuple2 t1 t2
371371
member inline _.MergeSources3 (t1, t2, t3) : '``Applicative1<Applicative2<Applicative3<'T>>>`` = (lift3 >> lift3 >> lift3) tuple3 t1 t2 t3
372-
member _.Run x : '``applicative1<applicative2<applicative3<'t>>>`` = x
372+
member _.Run x : '``Applicative1<Applicative2<Applicative3<'T>>>`` = x
373373

374374

375375

src/FSharpPlus/Data/Validation.fs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,21 @@ module Validation =
8484
-> Failure (e1 + e2)
8585
#endif
8686

87-
let inline foldBack (folder: 'T->'State->'State) (source: Validation<'Error,'T>) (state: 'State) =
87+
let inline foldBack (folder: 'T -> 'State -> 'State) (source: Validation<'Error, 'T>) (state: 'State) =
8888
match source with
8989
| Success a -> folder a state
9090
| Failure _ -> state
9191

9292
#if !FABLE_COMPILER || FABLE_COMPILER_3
9393

9494
/// Traverse the Success case with the supplied function.
95-
let inline traverse (f: 'T->'``Functor<'U>``) (source: Validation<'Error,'T>) : '``Functor<Validation<'Error,'U>>`` =
95+
let inline traverse (f: 'T -> '``Functor<'U>``) (source: Validation<'Error, 'T>) : '``Functor<Validation<'Error, 'U>>`` =
9696
match source with
9797
| Success a -> Validation<'Error,'U>.Success <!> f a
9898
| Failure e -> result (Validation<'Error,'U>.Failure e)
9999

100100
/// Traverse the Success case.
101-
let inline sequence (source: Validation<'Error,'``Functor<'T>``>) : '``Functor<Validation<'Error,'T>>`` = traverse id source
101+
let inline sequence (source: Validation<'Error, '``Functor<'T>``>) : '``Functor<Validation<'Error, 'T>>`` = traverse id source
102102

103103
#endif
104104

@@ -245,11 +245,11 @@ module Validation =
245245
#endif
246246

247247

248-
type Validation<'err,'a> with
248+
type Validation<'error, 't> with
249249

250250
// as Applicative
251251
static member Return x = Success x
252-
static member inline (<*>) (f: Validation<_,'T->'U>, x: Validation<_,'T>) : Validation<_,_> = Validation.apply f x
252+
static member inline (<*>) (f: Validation<'Error, 'T -> 'U>, x: Validation<_, 'T>) : Validation<_, _> = Validation.apply f x
253253

254254
/// <summary>
255255
/// Sequences two Validations left-to-right, discarding the value of the first argument.
@@ -264,39 +264,39 @@ type Validation<'err,'a> with
264264
static member inline (<* ) (x: Validation<'Error, 'U>, y: Validation<'Error, 'T>): Validation<'Error, 'U> = ((fun (k: 'U) (_: 'T) -> k ) </Validation.map/> x : Validation<'Error, 'T->'U>) </Validation.apply/> y
265265

266266
[<EditorBrowsable(EditorBrowsableState.Never)>]
267-
static member inline Lift2 (f, x: Validation<_,'T>, y: Validation<_,'U>) : Validation<_,'V> = Validation.map2 f x y
267+
static member inline Lift2 (f, x: Validation<'Error, 'T>, y: Validation<'Error, 'U>) : Validation<'Error, 'V> = Validation.map2 f x y
268268

269269
[<EditorBrowsable(EditorBrowsableState.Never)>]
270-
static member inline Lift3 (f, x: Validation<_,'T>, y: Validation<_,'U>, z: Validation<_,'V>) : Validation<_,'W> = Validation.map3 f x y z
270+
static member inline Lift3 (f, x: Validation<'Error, 'T>, y: Validation<_, 'U>, z: Validation<_, 'V>) : Validation<_, 'W> = Validation.map3 f x y z
271271

272-
#if !FABLE_COMPILER || FABLE_COMPILER_3
273272
// as Alternative (inherits from Applicative)
273+
#if !FABLE_COMPILER || FABLE_COMPILER_3
274274
static member inline get_Empty () = Failure (getEmpty ())
275-
static member inline (<|>) (x: Validation<_,_>, y: Validation<_,_>) = Validation.appValidation Control.Append.Invoke x y
275+
static member inline (<|>) (x: Validation<'Error, 'T>, y: Validation<_,_>) = Validation.appValidation Control.Append.Invoke x y
276276
#endif
277277

278278
// as Functor
279279
[<EditorBrowsable(EditorBrowsableState.Never)>]
280-
static member Map (x: Validation<_,_>, f) = Validation.map f x
280+
static member Map (x: Validation<'Error, _>, f: 'T -> 'U) = Validation.map f x
281281

282282
/// <summary>Lifts a function into a Validator. Same as map.
283283
/// To be used in Applicative Style expressions, combined with &lt;*&gt;
284284
/// </summary>
285285
/// <category index="1">Functor</category>
286-
static member (<!>) (f, x: Validation<_,_>) = Validation.map f x
286+
static member (<!>) (f: 'T -> 'U, x: Validation<'Error, _>) = Validation.map f x
287287

288288
// as Bifunctor
289289
[<EditorBrowsable(EditorBrowsableState.Never)>]
290-
static member Bimap (x: Validation<'T,'V>, f: 'T->'U, g: 'V->'W) : Validation<'U,'W> = Validation.bimap f g x
290+
static member Bimap (x: Validation<'T, 'V>, f: 'T -> 'U, g: 'V -> 'W) : Validation<'U, 'W> = Validation.bimap f g x
291291

292292
#if !FABLE_COMPILER || FABLE_COMPILER_3
293293

294294
// as Traversable
295295
[<EditorBrowsable(EditorBrowsableState.Never)>]
296-
static member inline Traverse (t: Validation<'err,'a>, f: 'a->'b) : 'c = Validation.traverse f t
296+
static member inline Traverse (t: Validation<'Error, 'T>, f: 'T -> '``Functor<'U>``) : '``Functor<Validation<'Error, 'U>>`` = Validation.traverse f t
297297

298298
[<EditorBrowsable(EditorBrowsableState.Never)>]
299-
static member inline Sequence (t: Validation<'err,'a>) : 'c = Validation.sequence t
299+
static member inline Sequence (t: Validation<'Error, '``Functor<'T>``>) : '``Functor<Validation<'Error, 'T>>`` = Validation.sequence t
300300

301301
#endif
302302

src/FSharpPlus/Extensions/List.fs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -357,19 +357,14 @@ module List =
357357
/// <param name="i">The index of the item to remove </param>
358358
/// <param name="lst">The input list</param>
359359
///
360-
/// <returns>For invalid indexes, the input list. Otherwise, a new list with the item removed.</returns>
360+
/// <returns>For invalid indexes, the input list. Otherwise, a new list with the item removed.</returns>
361+
/// <remarks>Use List.removeAt from FSharp.Core if you want to throw exceptions when using invalid indexes.</remarks>
361362
let deleteAt i lst =
362363
if List.length lst > i then
363364
lst.[0..i-1] @ lst.[i+1..]
364365
else lst
365366

366-
/// <summary>Attempts to remove an item from a list.</summary>
367-
/// <param name="i">The index of the item to remove </param>
368-
/// <param name="lst">The input list</param>
369-
///
370-
/// <returns>For invalid indexes, the input list. Otherwise, a new list with the item removed.</returns>
371-
/// <remarks>Use deletaAt instead or if you want to throw exceptions use the full path to removeAt in FSharp.Core until this function is removed from this library.</remarks>
372-
[<Obsolete("This function was included in FSharp.Core but throwing")>]
367+
[<Obsolete("This function was included in FSharp.Core but throwing. Use deletaAt instead or if you want to throw exceptions use the full path to removeAt in FSharp.Core until this function is removed from this library")>]
373368
let removeAt i lst = deleteAt i lst
374369

375370
/// <summary>Updates the value of an item in a list</summary>
@@ -378,9 +373,8 @@ module List =
378373
/// <param name="lst">The input list</param>
379374
///
380375
/// <returns>A new list with the updated element</returns>
381-
/// <remarks>Use List.updateAt if you want to throw exceptions when using invalid indexes.</remarks>
376+
/// <remarks>Use List.updateAt from FSharp.Core if you want to throw exceptions when using invalid indexes.</remarks>
382377
let setAt i x lst =
383378
if List.length lst > i && i >= 0 then
384379
lst.[0..i-1] @ x::lst.[i+1..]
385380
else lst
386-

src/FSharpPlus/Extensions/Result.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ module Result =
6161
| Error e, _, _
6262
| _, Error e, _
6363
| _, _, Error e -> Error e
64+
65+
/// <summary>Maps both Ok and Error of a Result.</summary>
66+
/// <param name="errorMapper">Function to be applied to source, if it contains an Error value.</param>
67+
/// <param name="okMapper">Function to be applied to source, if it contains an Ok value.</param>
68+
/// <param name="source">The source value, containing an Ok or an Error.</param>
69+
/// <returns>The result of applying the corresponding mapping function.</returns>
70+
let bimap (errorMapper: 'TError -> 'UError) (okMapper: 'T -> 'U) source =
71+
match source with
72+
| Error e -> Error (errorMapper e)
73+
| Ok a -> Ok (okMapper a)
6474

6575
/// <summary>Flattens two nested Results.</summary>
6676
/// <param name="source">The nested Results.</param>

src/FSharpPlus/Lens.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ module Lens =
126126
module List =
127127
/// Given a specific key, produces a Lens from a List<value> to an Option<value>. When setting,
128128
/// a Some(value) will insert or replace the value into the list at the given index. Setting a value of
129-
/// None will delete the value at the specified index. Works well together with non.
130-
let inline _item i f t =
129+
/// None will delete the value at the specified index. Works well together with non.
130+
let inline _item i f t =
131131
Map.InvokeOnInstance
132-
(function | None -> List.removeAt i t | Some x -> List.setAt i x t)
132+
(function None -> List.deleteAt i t | Some x -> List.setAt i x t)
133133
(f (List.tryItem i t))
134134

135135
[<RequireQualifiedAccess>]

tests/FSharpPlus.Tests/ComputationExpressions.fs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ module ComputationExpressions =
7676
testTryFinallyCaught ()
7777
()
7878

79+
// specialized to Validation
80+
81+
let mk1 (s: string) = if true then Success '1' else Failure [s]
82+
let mk2 (s: string) = if false then Success 1 else Failure [s]
83+
let mk3 (s: string) = if false then Success true else Failure [s]
84+
85+
let f x = applicative<Validation<_,_>> {
86+
let! x = mk1 x
87+
and! y = mk2 "2"
88+
and! z = mk3 "3"
89+
return (x, y, z) }
90+
let _ = f "1"
91+
92+
()
93+
94+
7995
[<Test>]
8096
let monadFx () =
8197
SideEffects.reset ()

0 commit comments

Comments
 (0)