Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposed mapExpect function. #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/Http.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ effect module Http where { command = MyCmd, subscription = MySub } exposing
, Header, header
, Body, emptyBody, stringBody, jsonBody, fileBody, bytesBody
, multipartBody, Part, stringPart, filePart, bytesPart
, Expect, expectString, expectJson, expectBytes, expectWhatever, Error(..)
, Expect, expectString, expectJson, expectBytes, expectWhatever, mapExpect, Error(..)
, track, Progress(..), fractionSent, fractionReceived
, cancel
, riskyRequest
Expand All @@ -26,7 +26,7 @@ effect module Http where { command = MyCmd, subscription = MySub } exposing
@docs multipartBody, Part, stringPart, filePart, bytesPart

# Expect
@docs Expect, expectString, expectJson, expectBytes, expectWhatever, Error
@docs Expect, expectString, expectJson, expectBytes, expectWhatever, mapExpect, Error

# Progress
@docs track, Progress, fractionSent, fractionReceived
Expand Down Expand Up @@ -541,6 +541,19 @@ resolve toResult response =
GoodStatus_ _ body -> Result.mapError BadBody (toResult body)


{-| Transform the messages produced by an expect.
Very similar to [`Html.map`](/packages/elm/html/latest/Html#map).

This is very rarely useful in well-structured Elm code, so definitely read the
section on [structure] in the guide before reaching for this!

[structure]: https://guide.elm-lang.org/webapps/structure.html
-}
mapExpect : (a -> msg) -> Expect a -> Expect msg
mapExpect =
Elm.Kernel.Http.mapExpect


{-| A `Request` can fail in a couple ways:

- `BadUrl` means you did not provide a valid URL.
Expand Down Expand Up @@ -950,7 +963,7 @@ cmdMap func cmd =
, headers = r.headers
, url = r.url
, body = r.body
, expect = Elm.Kernel.Http.mapExpect func r.expect
, expect = mapExpect func r.expect
, timeout = r.timeout
, tracker = r.tracker
, allowCookiesFromOtherDomains = r.allowCookiesFromOtherDomains
Expand Down