Update withMetadata to accept a combine function.

This commit is contained in:
Dillon Kearns 2023-01-07 09:56:51 -08:00
parent f3170ecb81
commit 55e94c3970
3 changed files with 9 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

@ -96,7 +96,7 @@ all =
, retries = 0
, timeoutInMs = Nothing
}
(BackendTask.Http.withMetadata
(BackendTask.Http.withMetadata Tuple.pair
(BackendTask.Http.expectJson
(Decode.field "stargazers_count" Decode.int)
)

View File

@ -208,27 +208,27 @@ expectJson =
{-| -}
withMetadata : Expect value -> Expect ( Metadata, value )
withMetadata originalExpect =
withMetadata : (Metadata -> value -> combined) -> Expect value -> Expect combined
withMetadata combineFn originalExpect =
-- known-unoptimized-recursion
case originalExpect of
ExpectJson jsonDecoder ->
ExpectMetadata (\metadata -> ExpectJson (jsonDecoder |> Json.Decode.map (Tuple.pair metadata)))
ExpectMetadata (\metadata -> ExpectJson (jsonDecoder |> Json.Decode.map (combineFn metadata)))
ExpectString stringToValue ->
ExpectMetadata
(\metadata ->
ExpectString (\string -> string |> stringToValue |> Tuple.pair metadata)
ExpectString (\string -> string |> stringToValue |> combineFn metadata)
)
ExpectBytes bytesDecoder ->
ExpectMetadata (\metadata -> ExpectBytes (bytesDecoder |> Bytes.Decode.map (Tuple.pair metadata)))
ExpectMetadata (\metadata -> ExpectBytes (bytesDecoder |> Bytes.Decode.map (combineFn metadata)))
ExpectWhatever value ->
ExpectMetadata (\metadata -> ExpectWhatever ( metadata, value ))
ExpectMetadata (\metadata -> ExpectWhatever (combineFn metadata value))
ExpectMetadata metadataToExpect ->
ExpectMetadata (\metadata -> withMetadata (metadataToExpect metadata))
ExpectMetadata (\metadata -> withMetadata combineFn (metadataToExpect metadata))
{-| -}