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