diff --git a/src/FSharpPlus/Data/NonEmptyList.fs b/src/FSharpPlus/Data/NonEmptyList.fs index 9c9e5bbfb..a73c71c60 100644 --- a/src/FSharpPlus/Data/NonEmptyList.fs +++ b/src/FSharpPlus/Data/NonEmptyList.fs @@ -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 - [] - member this.head = let {Head = a; Tail = _} = this in a - - [] - 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 @@ -334,9 +328,6 @@ module NonEmptyListBuilder = member _.Yield x = x member _.Delay expr = expr () member _.Run (x: NonEmptyList<_>) = x - - [] - let nel = NelBuilder () let nelist = NelBuilder () diff --git a/src/FSharpPlus/Data/Validation.fs b/src/FSharpPlus/Data/Validation.fs index 34e621fe8..b3afe3a17 100644 --- a/src/FSharpPlus/Data/Validation.fs +++ b/src/FSharpPlus/Data/Validation.fs @@ -128,12 +128,6 @@ module Validation = | Success a -> g a state | Failure e -> f e state - [] - 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>`` = match source with @@ -156,18 +150,12 @@ module Validation = | Failure e -> Failure e | Success a -> f a - [] - 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 - [] - 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 @@ -216,9 +204,6 @@ module Validation = /// The result of applying either functions. let either (failureMapper: 'TError -> 'U) (successMapper: 'T -> 'U) source = match source with Success v -> successMapper v | Failure e -> failureMapper e - [] - 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 @@ -226,11 +211,6 @@ module Validation = let validationNel (x: Result<'T, 'TError>) : (Validation, 'T>) = (liftResult result) x #endif - [] - 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 instead of throwing exceptions. let protect (unsafeFunction: 'T -> 'U) x = try diff --git a/src/FSharpPlus/Extensions/Choice.fs b/src/FSharpPlus/Extensions/Choice.fs index 1230ed116..fcc752ee9 100644 --- a/src/FSharpPlus/Extensions/Choice.fs +++ b/src/FSharpPlus/Extensions/Choice.fs @@ -61,8 +61,8 @@ module Choice = /// A result of the output type of the binder. let bind (binder: 'T->Choice<'U,'T2>) (source: Choice<'T,'T2>) = match source with Choice1Of2 v -> binder v | Choice2Of2 e -> Choice2Of2 e - [] - 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> /// If the input value is a Choice1Of2 leaves it unchanged, otherwise maps the value on the Choice2Of2 and flattens the resulting nested Choice. /// A function that takes the value of type T and transforms it into a Choice containing (potentially) a value of type U. diff --git a/src/FSharpPlus/Extensions/Extensions.fs b/src/FSharpPlus/Extensions/Extensions.fs index 8f5638317..f7432d285 100644 --- a/src/FSharpPlus/Extensions/Extensions.fs +++ b/src/FSharpPlus/Extensions/Extensions.fs @@ -198,7 +198,7 @@ module Extensions = static member SequentialLazy (t: seq>) : Async> = async { let! ct = Async.CancellationToken return Seq.map (fun t -> Async.AsTask(t, ct).Result) t } - []static member Sequence (t: seq>) = Async.SequentialLazy t + #endif /// Combine all asyncs in one, chaining them in sequence order. @@ -216,8 +216,6 @@ module Extensions = coll.Add v return coll.Close () } #endif - []static member Sequence (t: list>) = Async<_>.Sequential t - /// Combine all asyncs in one, chaining them in sequence order. static member Sequential (t: array>) : Async> = async { @@ -227,39 +225,30 @@ module Extensions = let! v = t.[i] arr.[i] <- v return arr } - []static member Sequence (t: array>) = Async<_>.Sequential t - /// Creates an async Result from a Result where the Ok case is async. static member Sequential (t: Result, 'Error>) : Async> = match t with | Ok a -> Async.Map Ok a | Error e -> async.Return (Error e) - []static member Sequence (t: Result, 'Error>) = Async<_>.Sequential t - /// Creates an async Choice from a Choice where the Choice1Of2 case is async. static member Sequential (t: Choice, 'Choice2Of2>) : Async> = match t with | Choice1Of2 a -> Async.Map Choice1Of2 a | Choice2Of2 e -> async.Return (Choice2Of2 e) - []static member Sequence (t: Choice, 'Choice2Of2>) = Async<_>.Sequential t - /// Creates an async Result from a Result where both cases are async. static member Bisequential (t: Result, Async<'Error>>) : Async> = match t with | Ok a -> Async.Map Ok a | Error e -> Async.Map Error e - []static member Bisequence (t: Result, Async<'Error>>) = Async.Bisequential t - /// Creates an async Choice from a Choice where both cases are async. static member Bisequential (t: Choice, Async<'Choice2Of2>>) : Async> = match t with | Choice1Of2 a -> Async.Map Choice1Of2 a | Choice2Of2 e -> Async.Map Choice2Of2 e - []static member Bisequence (t: Choice, Async<'Choice2Of2>>) = Async.Bisequential t type Option<'t> with @@ -288,7 +277,6 @@ module Extensions = then None else accumulator.Close () |> Array.toSeq |> Some #endif - []static member Sequence (t: seq>) = Option.Sequential t type ValueOption<'t> with @@ -317,7 +305,6 @@ module Extensions = then ValueNone else accumulator.Close () |> Array.toSeq |> ValueSome #endif - []static member Sequence (t: seq>) = ValueOption.Sequential t type Choice<'T1, 'T2> with @@ -348,7 +335,6 @@ module Extensions = | ValueNone -> Choice1Of2 (accumulator.Close () |> Array.toSeq) | ValueSome x -> Choice2Of2 x #endif - []static member Sequence (t: seq>) = Choice<_, _>.Sequential t /// Returns all Choice2Of2's combined, otherwise a sequence of all Choice1Of2 elements. @@ -396,7 +382,6 @@ module Extensions = | ValueNone -> Ok (accumulator.Close () |> Array.toSeq) | ValueSome x -> Error x #endif - []static member Sequence (t: seq>) = Result.Sequential t /// Returns all Errors combined, otherwise a sequence of all elements. static member Parallel (errorCombiner, t: seq>) = diff --git a/src/FSharpPlus/Extensions/IReadOnlyDictionary.fs b/src/FSharpPlus/Extensions/IReadOnlyDictionary.fs index e0baecd4c..9414c0c54 100644 --- a/src/FSharpPlus/Extensions/IReadOnlyDictionary.fs +++ b/src/FSharpPlus/Extensions/IReadOnlyDictionary.fs @@ -60,9 +60,6 @@ module IReadOnlyDictionary = dct.Add (k, mapper v) dct :> IReadOnlyDictionary<'Key, 'U> - [] - let map f (x: IReadOnlyDictionary<'Key, 'T>) = mapValues f x // F#+ 2: if following F# core naming, it should point to mapi instead. - /// Creates a read-only dictionary value from a pair of read-only dictionaries, /// using a function to combine them. /// Keys that are not present on both read-only dictionaries are dropped. diff --git a/src/FSharpPlus/Extensions/List.fs b/src/FSharpPlus/Extensions/List.fs index caef5e91e..756361714 100644 --- a/src/FSharpPlus/Extensions/List.fs +++ b/src/FSharpPlus/Extensions/List.fs @@ -449,9 +449,6 @@ module List = lst.[0..i-1] @ lst.[i+1..] else lst - [] - let removeAt i lst = deleteAt i lst - /// Updates the value of an item in a list /// The index of the item to update /// The new value of the item diff --git a/src/FSharpPlus/Extensions/Result.fs b/src/FSharpPlus/Extensions/Result.fs index ca3c15b5b..c30c618cf 100644 --- a/src/FSharpPlus/Extensions/Result.fs +++ b/src/FSharpPlus/Extensions/Result.fs @@ -6,14 +6,6 @@ module Result = open FSharp.Core.CompilerServices open System - /// Creates an Ok with the supplied value. - [] - let result value : Result<'T,'Error> = Ok value - - /// Creates an Error With the supplied value. - [] - 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. /// The function wrapped in an Ok or an Error. /// The value wrapped in an Ok or an Error. @@ -78,9 +70,8 @@ module Result = /// flatten is equivalent to bind id. 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. - [] - 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> /// If the input value is an Ok leaves it unchanged, otherwise maps the Error value and flattens the resulting nested Result. /// A function that takes the error and transforms it into a result. diff --git a/src/FSharpPlus/Operators.fs b/src/FSharpPlus/Operators.fs index ea2317048..7e3e131f3 100644 --- a/src/FSharpPlus/Operators.fs +++ b/src/FSharpPlus/Operators.fs @@ -203,9 +203,6 @@ module Operators = /// Applicative let inline lift2 (f: 'T->'U->'V) (x: '``Applicative<'T>``) (y: '``Applicative<'U>``) : '``Applicative<'V>`` = Lift2.Invoke f x y - [] - let inline liftA2 (f: 'T->'U->'V) (x: '``Applicative<'T>``) (y: '``Applicative<'U>``) : '``Applicative<'V>`` = lift2 f x y - /// /// Applies 3 lifted arguments to a non-lifted function. Equivalent to map3 in non list-like types. /// @@ -224,12 +221,6 @@ module Operators = /// Applicative let inline (<* ) (x: '``Applicative<'U>``) (y: '``Applicative<'T>``) : '``Applicative<'U>`` = ((fun (k: 'U) (_: 'T) -> k ) x : '``Applicative<'T->'U>``) <*> y - [) instead.")>] - let inline (<**>) (x: '``Applicative<'T>``) : '``Applicative<'T -> 'U>``->'``Applicative<'U>`` = flip (<*>) x - - [] - let inline optional v = Some v result None - /// /// 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. @@ -1623,10 +1614,6 @@ module Operators = let inline implicit (x: ^T) = ((^R or ^T) : (static member op_Implicit : ^T -> ^R) x) : ^R - [] - /// Additional Functions - let inline (|Parse|_|) str : 'T option = tryParse str - /// /// An active recognizer for a generic value parser. /// diff --git a/tests/FSharpPlus.Tests/Validations.fs b/tests/FSharpPlus.Tests/Validations.fs index 34515a3f8..ef89d29c1 100644 --- a/tests/FSharpPlus.Tests/Validations.fs +++ b/tests/FSharpPlus.Tests/Validations.fs @@ -16,22 +16,22 @@ module Validation = module FunctorP = [] let ``map id = id `` () = - fsCheck - "map id = id" - (fun (x :Validation) -> + fsCheck + "map id = id" + (fun (x :Validation) -> (Validation.map id) x = id x) [] let ``map (f << g) = map f << map g `` () = - fsCheck - "map (f << g) = map f << map g" + fsCheck + "map (f << g) = map f << map g" (fun (x :Validation) (f:string->int) (g:int->string) -> (Validation.map (f << g)) x = (Validation.map f << Validation.map g) x) module BifunctorP = [] let ``bimap f g = first f << second g`` () = - fsCheck + fsCheck "bimap f g = first f << second g" (fun (x :Validation) (f:string->int) (g:int->string) -> (bimap f g) x = (first f << second g) x) @@ -57,7 +57,7 @@ module Validation = ///Homomorphism: [] let ``result f <*> result x = result (f x)`` () = - fsCheck + fsCheck "result f <*> result x = result (f x)" (fun (x :Validation) (f:Validation -> int) -> let y:Validation = result (f x) @@ -65,9 +65,9 @@ module Validation = /// Interchange /// in haskell: u <*> pure y = pure ($ y) <*> u - [] + [] let ``u <*> result y = result ((|>) y) <*> u`` () = - fsCheck + fsCheck "u <*> result y = result ((|>) y) <*> u" (fun (u:Validationint>) (y:string) -> let right_side =result ((|>) y) <*> u @@ -77,26 +77,26 @@ module Validation = module AlternativeP = [] let ``empty <|> x = x`` () = - fsCheck "empty <|> x = x" + fsCheck "empty <|> x = x" (fun (x :Validation) -> getEmpty() <|> x = x) [] let ``x <|> empty = x`` () = - fsCheck "x <|> empty = x" + fsCheck "x <|> empty = x" (fun (x :Validation) -> x <|> getEmpty() = x) [] let ``(x <|> y) <|> z = x <|> (y <|> z)`` () = - fsCheck "(x <|> y) <|> z = x <|> (y <|> z)" + fsCheck "(x <|> y) <|> z = x <|> (y <|> z)" (fun (x :Validation) (y :Validation) (z :Validation) -> ((x <|> y) <|> z) = (x <|> (y <|> z))) [] let ``f (x <|> y) = (f x) <|> (f y)`` () = - fsCheck "f (x <|> y) = (f x) <|> (f y)" - (fun (x :Validation) (y :Validation) (f:int->string)-> + fsCheck "f (x <|> y) = (f x) <|> (f y)" + (fun (x :Validation) (y :Validation) (f:int->string) -> (f (x <|> y)) = ((f x) <|> (f y))) //Right Distribution: does not hold @@ -123,7 +123,7 @@ module Validation = (x :Result ) (t :int->string list) (f:string list->int) = let t_f = (t << f) let right_side = x |> (Result.traverse (t << f)) - let left_side = x |> (t << Result.traverse f ) + let left_side = x |> (t << Result.traverse f ) left_side = right_side *) (* @@ -165,13 +165,13 @@ module Validation = [] let testYN () = - let subject: Validation = Success plusOne <*> Failure ["f2"] + let subject: Validation = Success plusOne <*> Failure ["f2"] let expected = Failure ["f2"] areStEqual expected subject [] let testNN () = - let subject: Validation = Failure ["f1"] <*> Failure ["f2"] + let subject: Validation = Failure ["f1"] <*> Failure ["f2"] let expected = Failure ["f1";"f2"] areStEqual expected subject (* @@ -181,26 +181,6 @@ module Validation = Assert.AreEqual(1, subject) *) - [] - let testEnsureLeftFalse () = - let subject = ensure three (konst false) (Failure seven) - areStEqual (Failure seven) subject - - [] - let testEnsureLeftTrue () = - let subject = ensure three (konst true) (Failure seven) - areStEqual (Failure seven) subject - - [] - let testEnsureRightFalse () = - let subject = ensure three (konst false) (Success seven) - areStEqual (Failure three) subject - - [] - let testEnsureRightTrue () = - let subject = ensure three (konst true ) (Success seven) - areStEqual (Success seven) subject - [] let testDefaultValueSuccess () = let v = Success seven @@ -218,19 +198,7 @@ module Validation = // :: forall v. (Validate v, Eq (v Int Int), Show (v Int Int)) => Proxy v -> Test - [] - let testValidateTrue () = - let subject = validate three (konst true) seven - let expected = Success seven - areStEqual expected subject - - [] - let testValidateFalse () = - let subject = validate three (konst false) seven - let expected = Failure three - areStEqual expected subject - - module Tests= + module Tests = //( # ) :: AReview t b -> b -> t let seven = 7 let three = 3 @@ -241,19 +209,22 @@ module Validation = let subject:Validation = Success plusOne <*> Success seven let expected = Success 8 areStEqual expected subject + [] let testNY() = let subject:Validation = Failure ["f1"] <*> Success seven let expected = Failure ["f1"] areStEqual expected subject + [] let testYN() = - let subject:Validation = Success plusOne <*> Failure ["f2"] + let subject:Validation = Success plusOne <*> Failure ["f2"] let expected = Failure ["f2"] areStEqual expected subject + [] let testNN() = - let subject:Validation = Failure ["f1"] <*> Failure ["f2"] + let subject:Validation = Failure ["f1"] <*> Failure ["f2"] let expected = Failure ["f1";"f2"] areStEqual expected subject (* @@ -262,36 +233,17 @@ module Validation = let subject = validation length (const' 0) $ validationNel (Error ()) Assert.AreEqual(1, subject) *) - [] - let testEnsureLeftFalse () = - let subject = ensure three (konst false) (Failure seven) - areStEqual (Failure seven) subject - - [] - let testEnsureLeftTrue () = - let subject = ensure three (konst true) (Failure seven) - areStEqual (Failure seven) subject - - [] - let testEnsureRightFalse () = - let subject = ensure three (konst false) (Success seven) - areStEqual (Failure three) subject - - [] - let testEnsureRightTrue () = - let subject = ensure three (konst true ) (Success seven) - areStEqual (Success seven) subject [] let testOrElseRight () = let v = Success seven - let subject = Validation.orElse v three + let subject = Validation.defaultValue three v areStEqual seven subject [] let testOrElseLeft () = let v = Failure seven - let subject = Validation.orElse v three + let subject = Validation.defaultValue three v areStEqual three subject //testEnsureLeftFalse, testEnsureLeftTrue, testEnsureRightFalse, testEnsureRightTrue, @@ -300,24 +252,12 @@ module Validation = [] - let testValidateTrue () = - let subject = validate three (konst true) seven - let expected = Success seven - areStEqual expected subject - - [] - let testValidateFalse () = - let subject = validate three (konst false) seven - let expected = Failure three - areStEqual expected subject - - [] - let testValidateWithExceptions () = - let subject = + let testValidateWithExceptions () = + let subject = fun a b c d -> a + b + c + d - Failure (exn "Failure receiving first parameter") - <*> Success 4 - <*> Failure (exn "Failure receiving third parameter") + Failure (exn "Failure receiving first parameter") + <*> Success 4 + <*> Failure (exn "Failure receiving third parameter") <*> Failure (exn "Failure receiving last parameter") let expected : Validation = Failure ((new AggregateException ([exn "Failure receiving first parameter"; exn "Failure receiving third parameter"; exn "Failure receiving last parameter"])) :> exn) let f = function