Skip to content

Commit

Permalink
Removed Async.retn since it duplicates Async.singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
1eyewonder committed Dec 17, 2024
1 parent edc9ae0 commit e0cfdd1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
9 changes: 0 additions & 9 deletions src/FsToolkit.ErrorHandling/Async.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ module Async =
value
|> async.Return

/// <summary>
/// Converts a value to an <c>Async</c> value
/// </summary>
/// <param name="value">The value to convert to an <c>Async</c> value.</param>
/// <returns>The <c>Async</c> value.</returns>
let inline retn (value: 'value) : Async<'value> =
value
|> async.Return

/// <summary>
/// Takes a transformation function and applies it to the value of an <c>Async</c> value.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/FsToolkit.ErrorHandling/AsyncValidationCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ module AsyncValidationCE =
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(s: Validation<'ok, 'error>) : AsyncValidation<'ok, 'error> =
Async.retn s
Async.singleton s

#if !FABLE_COMPILER

Expand Down
2 changes: 1 addition & 1 deletion tests/FsToolkit.ErrorHandling.Tests/AsyncOptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ let ``AsyncOptionCE using Tests`` =
<| async {
let mutable disposed = false
let mutable finished = false
let f1 _ = Async.retn (Some 42)
let f1 _ = Async.singleton (Some 42)

let! actual =
asyncOption {
Expand Down
46 changes: 23 additions & 23 deletions tests/FsToolkit.ErrorHandling.Tests/AsyncValidation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ let applyTests =
|> lift
|> AsyncValidation.apply (
Ok remainingCharacters
|> Async.retn
|> Async.singleton
)

return
Expand All @@ -162,7 +162,7 @@ let applyTests =
let! result =
AsyncValidation.apply
(Ok remainingCharacters
|> Async.retn)
|> Async.singleton)
(lift emptyInvalidTweetR)

return
Expand All @@ -184,7 +184,7 @@ let operatorsTests =
<*> (lift validTweetR)
>>= (fun tweet ->
Ok tweet
|> Async.retn
|> Async.singleton
)

return
Expand Down Expand Up @@ -212,9 +212,9 @@ let zipTests =
let! actual =
AsyncValidation.zip
(Ok 1
|> Async.retn)
|> Async.singleton)
(Ok 2
|> Async.retn)
|> Async.singleton)

Expect.equal actual (Ok(1, 2)) "Should be ok"
}
Expand All @@ -223,7 +223,7 @@ let zipTests =
let! actual =
AsyncValidation.zip
(Ok 1
|> Async.retn)
|> Async.singleton)
(AsyncValidation.error "Bad")

Expect.equal actual (Error [ "Bad" ]) "Should be Error"
Expand All @@ -234,7 +234,7 @@ let zipTests =
AsyncValidation.zip
(AsyncValidation.error "Bad")
(Ok 1
|> Async.retn)
|> Async.singleton)

Expect.equal actual (Error [ "Bad" ]) "Should be Error"
}
Expand All @@ -260,10 +260,10 @@ let orElseTests =
<| async {
let! result =
(Ok "First"
|> Async.retn)
|> Async.singleton)
|> AsyncValidation.orElse (
Ok "Second"
|> Async.retn
|> Async.singleton
)

return
Expand All @@ -274,10 +274,10 @@ let orElseTests =
<| async {
let! result =
(Ok "First"
|> Async.retn)
|> Async.singleton)
|> AsyncValidation.orElse (
Error [ "Second" ]
|> Async.retn
|> Async.singleton
)

return
Expand All @@ -288,10 +288,10 @@ let orElseTests =
<| async {
let! result =
(Error [ "First" ]
|> Async.retn)
|> Async.singleton)
|> AsyncValidation.orElse (
Ok "Second"
|> Async.retn
|> Async.singleton
)

return
Expand All @@ -302,10 +302,10 @@ let orElseTests =
<| async {
let! result =
(Error [ "First" ]
|> Async.retn)
|> Async.singleton)
|> AsyncValidation.orElse (
Error [ "Second" ]
|> Async.retn
|> Async.singleton
)

return
Expand All @@ -320,10 +320,10 @@ let orElseWithTests =
<| async {
let! result =
(Ok "First"
|> Async.retn)
|> Async.singleton)
|> AsyncValidation.orElseWith (fun _ ->
Ok "Second"
|> Async.retn
|> Async.singleton
)

return
Expand All @@ -334,10 +334,10 @@ let orElseWithTests =
<| async {
let! result =
(Ok "First"
|> Async.retn)
|> Async.singleton)
|> AsyncValidation.orElseWith (fun _ ->
Error [ "Second" ]
|> Async.retn
|> Async.singleton
)

return
Expand All @@ -348,10 +348,10 @@ let orElseWithTests =
<| async {
let! result =
(Error [ "First" ]
|> Async.retn)
|> Async.singleton)
|> AsyncValidation.orElseWith (fun _ ->
Ok "Second"
|> Async.retn
|> Async.singleton
)

return
Expand All @@ -362,10 +362,10 @@ let orElseWithTests =
<| async {
let! result =
(Error [ "First" ]
|> Async.retn)
|> Async.singleton)
|> AsyncValidation.orElseWith (fun _ ->
Error [ "Second" ]
|> Async.retn
|> Async.singleton
)

return
Expand Down

0 comments on commit e0cfdd1

Please sign in to comment.