Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added missing instances to Snaplet #35

Closed
wants to merge 1 commit into from

2 participants

Edward Kmett Doug Beardsley
Edward Kmett

There are a number of instances that can be made for Snaplet that are currently missing.

They expose no new functionality, as everything that you can do with them you could do before using the exposed lenses, this just provides a few new ways to do things using standard classes, so no safety is lost, and there isn't any canonical place these instances could live outside of the snap package since they would otherwise be orphans.

Doug Beardsley
Owner

Merged into the 0.10 branch.

Doug Beardsley mightybyte closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 24, 2012
  1. Edward Kmett
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 1 deletion.
  1. +1 −0  snap.cabal
  2. +20 −1 src/Snap/Snaplet/Internal/Types.hs
1  snap.cabal
View
@@ -126,6 +126,7 @@ Library
cereal >= 0.3 && < 0.4,
clientsession >= 0.7.3.6 && < 0.8,
configurator >= 0.1 && < 0.3,
+ comonad >= 1.1 && < 3.1,
containers >= 0.3 && < 0.6,
directory >= 1.0 && < 1.2,
directory-tree >= 0.10 && < 0.11,
21 src/Snap/Snaplet/Internal/Types.hs
View
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
@@ -10,6 +11,7 @@ module Snap.Snaplet.Internal.Types where
import Prelude hiding ((.), id)
import Control.Applicative
import Control.Category ((.), id)
+import Control.Comonad
import Control.Monad.CatchIO hiding (Handler)
import Control.Monad.Reader
import Control.Monad.State.Class
@@ -22,6 +24,8 @@ import Data.Monoid
import Data.Lens.Lazy
import Data.Lens.Template
import Data.Text (Text)
+import Data.Foldable (Foldable(..))
+import Data.Traversable
import Snap.Core
import qualified Snap.Snaplet.Internal.LensT as LT
@@ -72,9 +76,24 @@ data Snaplet s = Snaplet
, _snapletValue :: s
}
-
makeLenses [''SnapletConfig, ''Snaplet]
+instance Functor Snaplet where
+ fmap f (Snaplet c a) = Snaplet c (f a)
+
+instance Foldable Snaplet where
+ foldMap f (Snaplet _ a) = f a
+
+instance Traversable Snaplet where
+ traverse f (Snaplet c a) = Snaplet c <$> f a
+
+instance Comonad Snaplet where
+ extract (Snaplet _ a) = a
+
+#if !(MIN_VERSION_comonad(3,0,0))
+instance Extend Snaplet where
+#endif
+ extend f w@(Snaplet c _) = Snaplet c (f w)
------------------------------------------------------------------------------
-- | A lens referencing the opaque SnapletConfig data type held inside
Something went wrong with that request. Please try again.