on 5dba607 help sign in
hakyll/src/Hakyll/Core/Writable/WritableTuple.hs
37 lines 1.2 kB history raw
1-- | This module exposes a writable type 'WritableTuple' which is a simple
2-- newtype wrapper around a tuple.
3--
4-- The idea is that, given a tuple @(a, b)@, @a@ is the value you actually want
5-- to save to the disk, and @b@ is some additional info that you /don't/ want to
6-- save, but that you need later, for example in a 'require' clause.
7--
8{-# LANGUAGE GeneralizedNewtypeDeriving, DeriveDataTypeable #-}
9module Hakyll.Core.Writable.WritableTuple
10 ( WritableTuple (..)
11 , writableTupleFst
12 , writableTupleSnd
13 , writableTupleCompiler
14 ) where
16import Control.Arrow (arr)
18import Data.Typeable (Typeable)
19import Data.Binary (Binary)
21import Hakyll.Core.Writable
22import Hakyll.Core.Compiler
24newtype WritableTuple a b = WritableTuple {unWritableTuple :: (a, b)}
25 deriving (Show, Eq, Ord, Binary, Typeable)
27instance Writable a => Writable (WritableTuple a b) where
28 write dst (WritableTuple (x, _)) = write dst x
30writableTupleFst :: WritableTuple a b -> a
31writableTupleFst = fst . unWritableTuple
33writableTupleSnd :: WritableTuple a b -> b
34writableTupleSnd = snd . unWritableTuple
36writableTupleCompiler :: Compiler (a, b) (WritableTuple a b)
37writableTupleCompiler = arr WritableTuple