From 044511385000b980ca2bd710ffd38be007d46abc Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Sat, 18 Nov 2023 17:35:12 -0600 Subject: [PATCH] fix: tuplecontaining instance (i think) --- src/Data.Tuple.Containing.purs | 24 ++++++++++++++++++++++++ src/HTTP/Request.purs | 20 +------------------- 2 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 src/Data.Tuple.Containing.purs diff --git a/src/Data.Tuple.Containing.purs b/src/Data.Tuple.Containing.purs new file mode 100644 index 0000000..6e9d632 --- /dev/null +++ b/src/Data.Tuple.Containing.purs @@ -0,0 +1,24 @@ +module Data.Tuple.Containing where + +import Prelude + +import Data.Tuple (Tuple, fst, snd) +import Data.Tuple.Nested (type (/\), (/\)) + +-- | given a tuple of any size with at least 1 value +-- | of type `a`, `extract` the first occurence of `a` +-- | from the tuple +class TupleContaining a tup where + extract :: tup -> a + +instance TupleContaining a a where + extract = identity +else instance TupleContaining a (a /\ b) where + extract = fst +else instance TupleContaining b (a /\ b) where + extract = snd +else instance TupleContaining b (a /\ b /\ Unit) where + extract (_ /\ b /\ _) = b +else instance TupleContaining a tail => TupleContaining a (Tuple head tail) where + extract (_ /\ tail) = extract tail + diff --git a/src/HTTP/Request.purs b/src/HTTP/Request.purs index 3c97bc8..d618d9c 100644 --- a/src/HTTP/Request.purs +++ b/src/HTTP/Request.purs @@ -24,8 +24,7 @@ import Data.Map (Map) import Data.Map as Map import Data.Maybe (Maybe(..)) import Data.Newtype (unwrap) -import Data.Tuple (Tuple, fst, snd) -import Data.Tuple.Nested (type (/\), (/\)) +import Data.Tuple.Containing (class TupleContaining, extract) import Effect (Effect) import Effect.Aff.Class (class MonadAff, liftAff) import Effect.Class (class MonadEffect, liftEffect) @@ -102,23 +101,6 @@ data Method | DELETE | PATCH --- | given a tuple of any size with at least 1 value --- | of type `a`, `extract` the first occurence of `a` --- | from the tuple -class TupleContaining a tup where - extract :: tup -> a - -instance TupleContaining a a where - extract = identity -else instance TupleContaining a (a /\ b) where - extract = fst -else instance TupleContaining b (a /\ b) where - extract = snd -else instance TupleContaining b (a /\ b /\ Unit) where - extract (_ /\ b /\ _) = b -else instance TupleContaining a tail => TupleContaining a (Tuple head tail) where - extract (_ /\ tail) = extract tail - class Request :: Type -> Constraint class Request a where requestUrl :: forall m. MonadAff m => a -> m URL