Skip to content

Commit

Permalink
Remove Obsoletes for v2
Browse files Browse the repository at this point in the history
  • Loading branch information
gusty committed Jun 23, 2024
1 parent 3b0dc3d commit a948ef0
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 142 deletions.
9 changes: 0 additions & 9 deletions src/FSharpPlus/Data/NonEmptyList.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ type NonEmptyList<'t> = {Head: 't; Tail: 't list} with
interface IReadOnlyList<'t> with member s.Item with get index = s.Item index
interface NonEmptySeq<'t> with member s.First = s.Head

[<System.Obsolete("Use Head instead.")>]
member this.head = let {Head = a; Tail = _} = this in a

[<System.Obsolete("Use Tail instead.")>]
member this.tail = let {Tail = a} = this in a

member this.Item = function 0 -> this.Head | n -> this.Tail.[n-1]
member this.GetSlice = function
| None , None
Expand Down Expand Up @@ -334,9 +328,6 @@ module NonEmptyListBuilder =
member _.Yield x = x
member _.Delay expr = expr ()
member _.Run (x: NonEmptyList<_>) = x

[<System.Obsolete("Use nelist instead.")>]
let nel = NelBuilder ()

let nelist = NelBuilder ()

Expand Down
20 changes: 0 additions & 20 deletions src/FSharpPlus/Data/Validation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@ module Validation =
| Success a -> g a state
| Failure e -> f e state

[<System.Obsolete("Use Validation.bifoldBack instead.")>]
let biFoldBack f g state x =
match state with
| Success a -> g a x
| Failure e -> f e x

/// Like traverse but taking an additional function to traverse the Failure part as well.
let inline bitraverse (f: 'TError -> '``Functor<'UError>``) (g: 'T -> '``Functor<'U>``) (source: Validation<'TError, 'T>) : '``Functor<Validation<'UError, 'U>>`` =
match source with
Expand All @@ -156,18 +150,12 @@ module Validation =
| Failure e -> Failure e
| Success a -> f a

[<System.Obsolete("Use Validation.defaultValue instead.")>]
let orElse v (a: 'a) = match v with | Failure _ -> a | Success x -> x

/// Extracts the Success value or use the supplied default value when it's a Failure.
let defaultValue (value: 'T) (source: Validation<'Error,'T>) : 'T = match source with Success v -> v | _ -> value

/// Extracts the Success value or applies the compensation function over the Failure.
let defaultWith (compensation: 'Error->'T) (source: Validation<'Error,'T>) : 'T = match source with | Success x -> x | Failure e -> compensation e

[<System.Obsolete("Use Validation.defaultWith instead.")>]
let valueOr ea (v: Validation<'e,'a>) = match v with | Failure e -> ea e | Success a -> a

/// Converts a 'Result' to a 'Validation'
/// when the 'Error' of the 'Result' needs to be lifted into a 'Semigroup'.
let liftResult f : (Result<'T,'Error> -> Validation<'Semigroup,'T>) = function Error e -> Failure (f e) | Ok a -> Success a
Expand Down Expand Up @@ -216,21 +204,13 @@ module Validation =
/// <returns>The result of applying either functions.</returns>
let either (failureMapper: 'TError -> 'U) (successMapper: 'T -> 'U) source = match source with Success v -> successMapper v | Failure e -> failureMapper e

[<System.Obsolete("This function will not be supported in future versions.")>]
let validate (e: 'e) (p: 'a -> bool) (a: 'a) : Validation<'e,'a> = if p a then Success a else Failure e

#if (!FABLE_COMPILER || FABLE_COMPILER_3) && !FABLE_COMPILER_4
/// validationNel : Result<'a,'e> -> Validation (NonEmptyList<'e>) a
/// This is 'liftError' specialized to 'NonEmptyList', since
/// they are a common semigroup to use.
let validationNel (x: Result<'T, 'TError>) : (Validation<NonEmptyList<'TError>, 'T>) = (liftResult result) x
#endif

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

/// Creates a safe version of the supplied function, which returns a Validation<exn, 'U> instead of throwing exceptions.
let protect (unsafeFunction: 'T -> 'U) x =
try
Expand Down
4 changes: 2 additions & 2 deletions src/FSharpPlus/Extensions/Choice.fs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ module Choice =
/// <returns>A result of the output type of the binder.</returns>
let bind (binder: 'T->Choice<'U,'T2>) (source: Choice<'T,'T2>) = match source with Choice1Of2 v -> binder v | Choice2Of2 e -> Choice2Of2 e

[<System.Obsolete("Use Choice.bindChoice2Of2")>]
let inline catch (f: 't -> _) = function Choice1Of2 v -> Choice1Of2 v | Choice2Of2 e -> f e : Choice<'v,'e>
/// Like Choice.bindChoice2Of2 but with flipped arguments.
let inline catch x f = x |> function Choice1Of2 v -> Choice1Of2 v | Choice2Of2 e -> f e : Choice<'v,'e>

/// <summary>If the input value is a Choice1Of2 leaves it unchanged, otherwise maps the value on the Choice2Of2 and flattens the resulting nested Choice.</summary>
/// <param name="binder">A function that takes the value of type T and transforms it into a Choice containing (potentially) a value of type U.</param>
Expand Down
17 changes: 1 addition & 16 deletions src/FSharpPlus/Extensions/Extensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ module Extensions =
static member SequentialLazy (t: seq<Async<'T>>) : Async<seq<_>> = async {
let! ct = Async.CancellationToken
return Seq.map (fun t -> Async.AsTask(t, ct).Result) t }
[<Obsolete("Renamed to Async.Sequential or Async.SequentialLazy")>]static member Sequence (t: seq<Async<_>>) = Async.SequentialLazy t

#endif

/// Combine all asyncs in one, chaining them in sequence order.
Expand All @@ -216,8 +216,6 @@ module Extensions =
coll.Add v
return coll.Close () }
#endif
[<Obsolete("Renamed to Async.Sequential")>]static member Sequence (t: list<Async<'T>>) = Async<_>.Sequential t


/// Combine all asyncs in one, chaining them in sequence order.
static member Sequential (t: array<Async<_>>) : Async<array<_>> = async {
Expand All @@ -227,39 +225,30 @@ module Extensions =
let! v = t.[i]
arr.[i] <- v
return arr }
[<Obsolete("Renamed to Async.Sequential")>]static member Sequence (t: array<Async<_>>) = Async<_>.Sequential t


/// Creates an async Result from a Result where the Ok case is async.
static member Sequential (t: Result<Async<'T>, 'Error>) : Async<Result<'T,'Error>> =
match t with
| Ok a -> Async.Map Ok a
| Error e -> async.Return (Error e)
[<Obsolete("Renamed to Async.Sequential")>]static member Sequence (t: Result<Async<'T>, 'Error>) = Async<_>.Sequential t


/// Creates an async Choice from a Choice where the Choice1Of2 case is async.
static member Sequential (t: Choice<Async<'T>, 'Choice2Of2>) : Async<Choice<'T,'Choice2Of2>> =
match t with
| Choice1Of2 a -> Async.Map Choice1Of2 a
| Choice2Of2 e -> async.Return (Choice2Of2 e)
[<Obsolete("Renamed to Async.Sequential")>]static member Sequence (t: Choice<Async<'T>, 'Choice2Of2>) = Async<_>.Sequential t


/// Creates an async Result from a Result where both cases are async.
static member Bisequential (t: Result<Async<'T>, Async<'Error>>) : Async<Result<'T,'Error>> =
match t with
| Ok a -> Async.Map Ok a
| Error e -> Async.Map Error e
[<Obsolete("Renamed to Async.Bisequential")>]static member Bisequence (t: Result<Async<'T>, Async<'Error>>) = Async.Bisequential t


/// Creates an async Choice from a Choice where both cases are async.
static member Bisequential (t: Choice<Async<'T>, Async<'Choice2Of2>>) : Async<Choice<'T,'Choice2Of2>> =
match t with
| Choice1Of2 a -> Async.Map Choice1Of2 a
| Choice2Of2 e -> Async.Map Choice2Of2 e
[<Obsolete("Renamed to Async.Bisequential")>]static member Bisequence (t: Choice<Async<'T>, Async<'Choice2Of2>>) = Async.Bisequential t


type Option<'t> with
Expand Down Expand Up @@ -288,7 +277,6 @@ module Extensions =
then None
else accumulator.Close () |> Array.toSeq |> Some
#endif
[<Obsolete("Renamed to Option.Sequential")>]static member Sequence (t: seq<option<'t>>) = Option.Sequential t


type ValueOption<'t> with
Expand Down Expand Up @@ -317,7 +305,6 @@ module Extensions =
then ValueNone
else accumulator.Close () |> Array.toSeq |> ValueSome
#endif
[<Obsolete("Renamed to ValueOption.Sequential")>]static member Sequence (t: seq<voption<'t>>) = ValueOption.Sequential t


type Choice<'T1, 'T2> with
Expand Down Expand Up @@ -348,7 +335,6 @@ module Extensions =
| ValueNone -> Choice1Of2 (accumulator.Close () |> Array.toSeq)
| ValueSome x -> Choice2Of2 x
#endif
[<Obsolete("Renamed to Choice.Sequential")>]static member Sequence (t: seq<Choice<_, _>>) = Choice<_, _>.Sequential t


/// Returns all Choice2Of2's combined, otherwise a sequence of all Choice1Of2 elements.
Expand Down Expand Up @@ -396,7 +382,6 @@ module Extensions =
| ValueNone -> Ok (accumulator.Close () |> Array.toSeq)
| ValueSome x -> Error x
#endif
[<Obsolete("Renamed to Result.Sequential")>]static member Sequence (t: seq<Result<_, _>>) = Result.Sequential t

/// Returns all Errors combined, otherwise a sequence of all elements.
static member Parallel (errorCombiner, t: seq<Result<'T, 'Error>>) =
Expand Down
3 changes: 0 additions & 3 deletions src/FSharpPlus/Extensions/IReadOnlyDictionary.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ module IReadOnlyDictionary =
dct.Add (k, mapper v)
dct :> IReadOnlyDictionary<'Key, 'U>

[<System.Obsolete("Name is a bit ambiguous, use mapValues if the intention is to map only over the values or mapi to map over both keys and values.")>]
let map f (x: IReadOnlyDictionary<'Key, 'T>) = mapValues f x // F#+ 2: if following F# core naming, it should point to mapi instead.

/// <summary>Creates a read-only dictionary value from a pair of read-only dictionaries,
/// using a function to combine them.</summary>
/// <remarks>Keys that are not present on both read-only dictionaries are dropped.</remarks>
Expand Down
3 changes: 0 additions & 3 deletions src/FSharpPlus/Extensions/List.fs
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,6 @@ module List =
lst.[0..i-1] @ lst.[i+1..]
else lst

[<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")>]
let removeAt i lst = deleteAt i lst

/// <summary>Updates the value of an item in a list</summary>
/// <param name="i">The index of the item to update</param>
/// <param name="x">The new value of the item</param>
Expand Down
13 changes: 2 additions & 11 deletions src/FSharpPlus/Extensions/Result.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ module Result =
open FSharp.Core.CompilerServices
open System

/// Creates an Ok with the supplied value.
[<Obsolete("Prefer Result.Ok")>]
let result value : Result<'T,'Error> = Ok value

/// Creates an Error With the supplied value.
[<Obsolete("Prefer Result.Error")>]
let throw value : Result<'T,'Error> = Error value

/// Applies the wrapped value to the wrapped function when both are Ok and returns a wrapped result or the first Error.
/// <param name="f">The function wrapped in an Ok or an Error.</param>
/// <param name="x">The value wrapped in an Ok or an Error.</param>
Expand Down Expand Up @@ -78,9 +70,8 @@ module Result =
/// <remarks><c>flatten</c> is equivalent to <c>bind id</c>.</remarks>
let flatten source : Result<'T,'Error> = match source with Ok (Ok v) -> Ok v | Ok (Error e) | Error e -> Error e

// Note: To be fixed in F#+ 2. Arguments should be flipped in order to match the generic catch.
[<System.Obsolete("Use Result.bindError instead.")>]
let inline catch f = function Ok v -> Ok v | Error e -> (f: 't->_) e : Result<'v,'e>
/// Like Result.bindError but with flipped arguments.
let inline catch x f = x |> function Ok v -> Ok v | Error e -> (f: 't->_) e : Result<'v,'e>

/// <summary>If the input value is an Ok leaves it unchanged, otherwise maps the Error value and flattens the resulting nested Result.</summary>
/// <param name="binder">A function that takes the error and transforms it into a result.</param>
Expand Down
13 changes: 0 additions & 13 deletions src/FSharpPlus/Operators.fs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ module Operators =
/// <category index="2">Applicative</category>
let inline lift2 (f: 'T->'U->'V) (x: '``Applicative<'T>``) (y: '``Applicative<'U>``) : '``Applicative<'V>`` = Lift2.Invoke f x y

[<System.Obsolete("Use lift2 instead.")>]
let inline liftA2 (f: 'T->'U->'V) (x: '``Applicative<'T>``) (y: '``Applicative<'U>``) : '``Applicative<'V>`` = lift2 f x y

/// <summary>
/// Applies 3 lifted arguments to a non-lifted function. Equivalent to map3 in non list-like types.
/// </summary>
Expand All @@ -224,12 +221,6 @@ module Operators =
/// <category index="2">Applicative</category>
let inline (<* ) (x: '``Applicative<'U>``) (y: '``Applicative<'T>``) : '``Applicative<'U>`` = ((fun (k: 'U) (_: 'T) -> k ) <!> x : '``Applicative<'T->'U>``) <*> y

[<System.Obsolete("Use flip (<*>) instead.")>]
let inline (<**>) (x: '``Applicative<'T>``) : '``Applicative<'T -> 'U>``->'``Applicative<'U>`` = flip (<*>) x

[<System.Obsolete("Use opt instead.")>]
let inline optional v = Some <!> v </Append.Invoke/> result None

/// <summary>
/// Transforms an alternative value (which has the notion of success/failure) to an alternative
/// that always succeed, wrapping the original value into an option to signify success/failure of the original alternative.
Expand Down Expand Up @@ -1623,10 +1614,6 @@ module Operators =
let inline implicit (x: ^T) = ((^R or ^T) : (static member op_Implicit : ^T -> ^R) x) : ^R


[<System.Obsolete("Use Parsed instead.")>]
/// <category index="23">Additional Functions</category>
let inline (|Parse|_|) str : 'T option = tryParse str

/// <summary>
/// An active recognizer for a generic value parser.
/// </summary>
Expand Down
67 changes: 2 additions & 65 deletions tests/FSharpPlus.Tests/Validations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,6 @@ module Validation =
Assert.AreEqual(1, subject)
*)

[<Test>]
let testEnsureLeftFalse () =
let subject = ensure three (konst false) (Failure seven)
areStEqual (Failure seven) subject

[<Test>]
let testEnsureLeftTrue () =
let subject = ensure three (konst true) (Failure seven)
areStEqual (Failure seven) subject

[<Test>]
let testEnsureRightFalse () =
let subject = ensure three (konst false) (Success seven)
areStEqual (Failure three) subject

[<Test>]
let testEnsureRightTrue () =
let subject = ensure three (konst true ) (Success seven)
areStEqual (Success seven) subject

[<Test>]
let testDefaultValueSuccess () =
let v = Success seven
Expand All @@ -218,18 +198,6 @@ module Validation =
// :: forall v. (Validate v, Eq (v Int Int), Show (v Int Int)) => Proxy v -> Test


[<Test>]
let testValidateTrue () =
let subject = validate three (konst true) seven
let expected = Success seven
areStEqual expected subject

[<Test>]
let testValidateFalse () =
let subject = validate three (konst false) seven
let expected = Failure three
areStEqual expected subject

module Tests=
//( # ) :: AReview t b -> b -> t
let seven = 7
Expand Down Expand Up @@ -262,55 +230,24 @@ module Validation =
let subject = validation length (const' 0) $ validationNel (Error ())
Assert.AreEqual(1, subject)
*)
[<Test>]
let testEnsureLeftFalse () =
let subject = ensure three (konst false) (Failure seven)
areStEqual (Failure seven) subject

[<Test>]
let testEnsureLeftTrue () =
let subject = ensure three (konst true) (Failure seven)
areStEqual (Failure seven) subject

[<Test>]
let testEnsureRightFalse () =
let subject = ensure three (konst false) (Success seven)
areStEqual (Failure three) subject

[<Test>]
let testEnsureRightTrue () =
let subject = ensure three (konst true ) (Success seven)
areStEqual (Success seven) subject

[<Test>]
let testOrElseRight () =
let v = Success seven
let subject = Validation.orElse v three
let subject = Validation.defaultValue v three
areStEqual seven subject

[<Test>]
let testOrElseLeft () =
let v = Failure seven
let subject = Validation.orElse v three
let subject = Validation.defaultValue v three
areStEqual three subject

//testEnsureLeftFalse, testEnsureLeftTrue, testEnsureRightFalse, testEnsureRightTrue,
// testOrElseRight, testOrElseLeft
// :: forall v. (Validate v, Eq (v Int Int), Show (v Int Int)) => Proxy v -> Test


[<Test>]
let testValidateTrue () =
let subject = validate three (konst true) seven
let expected = Success seven
areStEqual expected subject

[<Test>]
let testValidateFalse () =
let subject = validate three (konst false) seven
let expected = Failure three
areStEqual expected subject

[<Test>]
let testValidateWithExceptions () =
let subject =
Expand Down

0 comments on commit a948ef0

Please sign in to comment.