From 05f1716c4347623afddf25edc5c327514608e6ea Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 1 Apr 2016 10:39:55 -0700 Subject: [PATCH] Use performAction instead of Task.map and Task.onError directly --- stages/5/Main.elm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/stages/5/Main.elm b/stages/5/Main.elm index ffd1fde..596540f 100644 --- a/stages/5/Main.elm +++ b/stages/5/Main.elm @@ -40,12 +40,8 @@ searchFeed query = "https://api.github.com/search/repositories?q=" ++ query ++ "+language:elm&sort=stars&order=desc" - - task = - Http.get responseDecoder url - |> Task.map SetResults in - Task.onError task (\_ -> Task.succeed (SetResults [])) + performAction SetResults (\_ -> SetResults []) (Http.get responseDecoder url) responseDecoder : Decoder (List SearchResult) @@ -63,6 +59,15 @@ searchResultDecoder = ("TODO what field goes here?" := Json.Decode.int) +performAction : (a -> b) -> (y -> b) -> Task y a -> Task x b +performAction successToAction errorToAction task = + let + successTask = + Task.map successToAction task + in + Task.onError successTask (\err -> Task.succeed (errorToAction err)) + + type alias Model = { query : String , results : List SearchResult