Skip to content

Commit c006ee6

Browse files
committed
209 remove MergeSources (and!) from some implementations (#261)
* Remove MergeSources from resultCE * Remove MergeSources from AsyncResult * Remove MergeSources from ResultOption * Fixup resultOption docs * Remove MergeSources from OptionCE * Remove MergeSources from ValueOptionCE * remove MergeSources Option/ValueOption
1 parent 724b51b commit c006ee6

File tree

12 files changed

+2
-925
lines changed

12 files changed

+2
-925
lines changed

benchmarks/ApplicativeTests.fs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,6 @@ type Result_BindvsAndCEBenchmarks() =
4141
}
4242
|> ignore
4343

44-
[<Benchmark>]
45-
member this.All_Success_And() =
46-
result {
47-
let! r1 = successSlowSync this.delay
48-
and! r2 = successSlowSync this.delay
49-
and! r3 = successSlowSync this.delay
50-
51-
return
52-
r1
53-
+ r2
54-
+ r3
55-
}
56-
|> ignore
5744

5845
[<Benchmark>]
5946
member this.Fail_First_Bind() =
@@ -69,20 +56,6 @@ type Result_BindvsAndCEBenchmarks() =
6956
}
7057
|> ignore
7158

72-
[<Benchmark>]
73-
member this.Fail_First_And() =
74-
result {
75-
let! r1 = errorSlowSync this.delay
76-
and! r2 = successSlowSync this.delay
77-
and! r3 = successSlowSync this.delay
78-
79-
return
80-
r1
81-
+ r2
82-
+ r3
83-
}
84-
|> ignore
85-
8659
[<Benchmark>]
8760
member this.Fail_Mid_Bind() =
8861
result {
@@ -97,20 +70,6 @@ type Result_BindvsAndCEBenchmarks() =
9770
}
9871
|> ignore
9972

100-
[<Benchmark>]
101-
member this.Fail_Mid_And() =
102-
result {
103-
let! r1 = successSlowSync this.delay
104-
and! r2 = errorSlowSync this.delay
105-
and! r3 = successSlowSync this.delay
106-
107-
return
108-
r1
109-
+ r2
110-
+ r3
111-
}
112-
|> ignore
113-
11473
[<Benchmark>]
11574
member this.Fail_Last_Bind() =
11675
result {
@@ -124,17 +83,3 @@ type Result_BindvsAndCEBenchmarks() =
12483
+ r3
12584
}
12685
|> ignore
127-
128-
[<Benchmark>]
129-
member this.Fail_Last_And() =
130-
result {
131-
let! r1 = successSlowSync this.delay
132-
and! r2 = successSlowSync this.delay
133-
and! r3 = errorSlowSync this.delay
134-
135-
return
136-
r1
137-
+ r2
138-
+ r3
139-
}
140-
|> ignore

gitbook/resultOption/ce.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ let add x y z = x + y + z
2525
2626
let addResult : Result<int option, string> = resultOption {
2727
let! x = Ok (Some 30)
28-
and! y = Error "Oops 1"
29-
and! z = Error "Oops 2"
28+
let! y = Error "Oops 1"
29+
let! z = Error "Oops 2"
3030
return add x y z
3131
}
3232
// Error "Oops 1"

src/FsToolkit.ErrorHandling/AsyncResultCE.fs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,6 @@ module AsyncResultCE =
112112
) : Async<Result<'okOutput, 'error>> =
113113
AsyncResult.map f x
114114

115-
member inline _.MergeSources
116-
(
117-
t1: Async<Result<'leftOk, 'error>>,
118-
t2: Async<Result<'rightOk, 'error>>
119-
) : Async<Result<'leftOk * 'rightOk, 'error>> =
120-
AsyncResult.zip t1 t2
121-
122-
123115
/// <summary>
124116
/// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type.
125117
///

src/FsToolkit.ErrorHandling/OptionCE.fs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,6 @@ module OptionCE =
111111
) : 'output option =
112112
Option.map f (Option.ofObj x)
113113

114-
member inline _.MergeSources
115-
(
116-
option1: 'left option,
117-
option2: 'right option
118-
) : ('left * 'right) option =
119-
Option.zip option1 option2
120-
121114
/// <summary>
122115
/// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type.
123116
///
@@ -145,29 +138,6 @@ module OptionExtensionsLower =
145138

146139
member inline _.Source(m: string) : string option = Option.ofObj m
147140

148-
member inline _.MergeSources
149-
(
150-
nullableObj1: 'left,
151-
option2: 'right option
152-
) : ('left * 'right) option =
153-
Option.zip (Option.ofObj nullableObj1) option2
154-
155-
156-
member inline _.MergeSources
157-
(
158-
option1: 'left option,
159-
nullableObj2: 'right
160-
) : ('left * 'right) option =
161-
Option.zip (option1) (Option.ofObj nullableObj2)
162-
163-
164-
member inline _.MergeSources
165-
(
166-
nullableObj1: 'left,
167-
nullableObj2: 'right
168-
) : ('left * 'right) option =
169-
Option.zip (Option.ofObj nullableObj1) (Option.ofObj nullableObj2)
170-
171141
[<AutoOpen>]
172142
module OptionExtensions =
173143
open System

src/FsToolkit.ErrorHandling/ResultCE.fs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,6 @@ module ResultCE =
109109
) : Result<'okOutput, 'error> =
110110
Result.map f x
111111

112-
member inline _.MergeSources
113-
(
114-
left: Result<'left, 'error>,
115-
right: Result<'right, 'error>
116-
) : Result<'left * 'right, 'error> =
117-
Result.zip left right
118-
119112
/// <summary>
120113
/// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type.
121114
///

src/FsToolkit.ErrorHandling/ResultOptionCE.fs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,6 @@ module ResultOptionCE =
114114
) : Result<'U option, 'TError> =
115115
ResultOption.map binder resultOpt
116116

117-
member inline _.MergeSources
118-
(
119-
left: Result<'left option, 'error>,
120-
right: Result<'right option, 'error>
121-
) : Result<('left * 'right) option, 'error> =
122-
ResultOption.zip left right
123-
124117
member inline _.Source(result: Result<'ok option, 'error>) : Result<'ok option, 'error> =
125118
result
126119

src/FsToolkit.ErrorHandling/ValueOptionCE.fs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ module ValueOptionCE =
103103
|> ValueOption.ofObj
104104
|> ValueOption.map f
105105

106-
member inline _.MergeSources(option1, option2) = ValueOption.zip option1 option2
107-
108106
/// <summary>
109107
/// Method lets us transform data types into our internal representation. This is the identity method to recognize the self type.
110108
///
@@ -127,17 +125,6 @@ module ValueOptionExtensionsLower =
127125
m
128126
|> ValueOption.ofObj
129127

130-
member inline _.MergeSources(nullableObj1, option2) =
131-
ValueOption.zip (ValueOption.ofObj nullableObj1) option2
132-
133-
134-
member inline _.MergeSources(option1, nullableObj2) =
135-
ValueOption.zip (option1) (ValueOption.ofObj nullableObj2)
136-
137-
138-
member inline _.MergeSources(nullableObj1, nullableObj2) =
139-
ValueOption.zip (ValueOption.ofObj nullableObj1) (ValueOption.ofObj nullableObj2)
140-
141128
[<AutoOpen>]
142129
module ValueOptionExtensions =
143130
open System

tests/FsToolkit.ErrorHandling.Tests/AsyncResultCE.fs

Lines changed: 0 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -526,173 +526,6 @@ let toTaskResult v =
526526
|> Task.FromResult
527527
#endif
528528

529-
let ``AsyncResultCE applicative tests`` =
530-
testList "AsyncResultCE applicative tests" [
531-
testCaseAsync "Happy Path AsyncResult"
532-
<| async {
533-
let! actual =
534-
asyncResult {
535-
let! a = AsyncResult.retn 3
536-
and! b = AsyncResult.retn 2
537-
and! c = AsyncResult.retn 1
538-
return a + b - c
539-
}
540-
541-
Expect.equal actual (Ok 4) "Should be ok"
542-
}
543-
544-
#if !FABLE_COMPILER
545-
546-
testCaseAsync "Happy Path TaskResult"
547-
<| async {
548-
let! actual =
549-
asyncResult {
550-
let! a = toTaskResult 3
551-
and! b = toTaskResult 2
552-
and! c = toTaskResult 1
553-
return a + b - c
554-
}
555-
556-
Expect.equal actual (Ok 4) "Should be ok"
557-
}
558-
559-
#endif
560-
561-
testCaseAsync "Happy Path Result"
562-
<| async {
563-
let! actual =
564-
asyncResult {
565-
let! a = Result.Ok 3
566-
and! b = Result.Ok 2
567-
and! c = Result.Ok 1
568-
return a + b - c
569-
}
570-
571-
Expect.equal actual (Ok 4) "Should be ok"
572-
}
573-
574-
testCaseAsync "Happy Path Choice"
575-
<| async {
576-
let! actual =
577-
asyncResult {
578-
let! a = Choice1Of2 3
579-
and! b = Choice1Of2 2
580-
and! c = Choice1Of2 1
581-
return a + b - c
582-
}
583-
584-
Expect.equal actual (Ok 4) "Should be ok"
585-
}
586-
587-
// Cannot get this to compile properly
588-
testCaseAsync "Happy Path Async"
589-
<| async {
590-
let! actual =
591-
asyncResult {
592-
let! a = Async.singleton 3 //: Async<int>
593-
and! b = Async.singleton 2 //: Async<int>
594-
and! c = Async.singleton 1 //: Async<int>
595-
return a + b - c
596-
}
597-
598-
Expect.equal actual (Ok 4) "Should be ok"
599-
}
600-
601-
testCaseAsync "Happy Path 2 Async"
602-
<| async {
603-
let! actual =
604-
asyncResult {
605-
let! a = Async.singleton 3 //: Async<int>
606-
and! b = Async.singleton 2 //: Async<int>
607-
return a + b
608-
}
609-
610-
Expect.equal actual (Ok 5) "Should be ok"
611-
}
612-
613-
#if !FABLE_COMPILER
614-
615-
testCaseAsync "Happy Path 2 Task"
616-
<| async {
617-
let! actual =
618-
asyncResult {
619-
let! a = Task.FromResult 3
620-
and! b = Task.FromResult 2
621-
return a + b
622-
}
623-
624-
Expect.equal actual (Ok 5) "Should be ok"
625-
}
626-
627-
#endif
628-
629-
testCaseAsync "Happy Path Result/Choice/AsyncResult"
630-
<| async {
631-
let! actual =
632-
asyncResult {
633-
let! a = Ok 3
634-
and! b = Choice1Of2 2
635-
636-
and! c =
637-
Ok 1
638-
|> Async.singleton
639-
640-
return a + b - c
641-
}
642-
643-
Expect.equal actual (Ok 4) "Should be ok"
644-
}
645-
646-
testCaseAsync "Fail Path Result"
647-
<| async {
648-
let expected = Error "TryParse failure"
649-
650-
let! actual =
651-
asyncResult {
652-
let! a = Ok 3
653-
and! b = Ok 2
654-
and! c = expected
655-
return a + b - c
656-
}
657-
658-
Expect.equal actual expected "Should be Error"
659-
}
660-
661-
testCaseAsync "Fail Path Choice"
662-
<| async {
663-
let errorMsg = "TryParse failure"
664-
665-
let! actual =
666-
asyncResult {
667-
let! a = Choice1Of2 3
668-
and! b = Choice1Of2 2
669-
and! c = Choice2Of2 errorMsg
670-
return a + b - c
671-
}
672-
673-
Expect.equal actual (Error errorMsg) "Should be Error"
674-
}
675-
676-
testCaseAsync "Fail Path Result/Choice/AsyncResult"
677-
<| async {
678-
let errorMsg = "TryParse failure"
679-
680-
let! actual =
681-
asyncResult {
682-
let! a = Choice1Of2 3
683-
684-
and! b =
685-
Ok 2
686-
|> Async.singleton
687-
688-
and! c = Error errorMsg
689-
return a + b - c
690-
}
691-
692-
Expect.equal actual (Error errorMsg) "Should be Error"
693-
}
694-
]
695-
696529

697530
let ``AsyncResultCE Stack Trace Tests`` =
698531

@@ -769,7 +602,6 @@ let allTests =
769602
``AsyncResultCE try Tests``
770603
``AsyncResultCE using Tests``
771604
``AsyncResultCE loop Tests``
772-
``AsyncResultCE applicative tests``
773605
``AsyncResultCE Stack Trace Tests``
774606
``AsyncResultCE inference checks``
775607
]

0 commit comments

Comments
 (0)