Skip to content

Commit cff0a20

Browse files
committed
Added extract helper for responses with only one status
1 parent ea60b62 commit cff0a20

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

generated-docs/md/Apiary.Client.Response.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## Module Apiary.Client.Response
22

3+
#### `extract`
4+
5+
``` purescript
6+
extract :: forall status r a. IsSymbol status => ResponseStatus status => Cons status a () r => Variant r -> a
7+
```
8+
39
#### `DecodeResponse`
410

511
``` purescript

src/Apiary/Client/Response.purs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ import Control.Monad.Error.Class (throwError)
1010
import Control.Monad.Except (Except, withExcept)
1111
import Data.Maybe (isJust)
1212
import Data.Symbol (class IsSymbol)
13-
import Data.Variant (SProxy(..), Variant, expand, inj, prj)
13+
import Data.Variant (SProxy(..), Variant, case_, expand, inj, on, prj)
1414
import Partial.Unsafe (unsafeCrashWith)
1515
import Prim.Row (class Cons, class Union)
1616
import Prim.RowList (class RowToList, kind RowList, Cons, Nil)
1717
import Type.Data.RowList (RLProxy(..))
1818
import Type.Proxy (Proxy(..))
1919

20+
extract :: forall status r a. IsSymbol status => ResponseStatus status => Cons status a () r => Variant r -> a
21+
extract = case_ # on (SProxy :: _ status) identity
22+
2023
class DecodeResponse rep response | rep -> response where
2124
decodeResponse :: forall proxy. proxy rep -> Response -> Except (Request -> Error) response
2225

0 commit comments

Comments
 (0)