fix: tuplecontaining instance (i think)

This commit is contained in:
orion 2023-11-18 17:35:12 -06:00
parent 8c40a57d99
commit 0445113850
Signed by: orion
GPG Key ID: 6D4165AE4C928719
2 changed files with 25 additions and 19 deletions

View File

@ -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

View File

@ -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