summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core/Util/Arrow.hs
blob: 96a5e09b565b4f6929d298f37b76de45ed317a8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
--------------------------------------------------------------------------------
-- | Various arrow utility functions
module Hakyll.Core.Util.Arrow
    ( ArrowMap (..)
    , constA
    , sequenceA
    , unitA
    ) where


--------------------------------------------------------------------------------
import           Control.Arrow (Arrow, ArrowChoice, arr, (&&&), (>>^))


--------------------------------------------------------------------------------
-- | Additional arrow typeclass for performance reasons.
class ArrowChoice a => ArrowMap a where
    mapA :: a b c -> a [b] [c]


--------------------------------------------------------------------------------
instance ArrowMap (->) where
    mapA = map


--------------------------------------------------------------------------------
constA :: Arrow a => c -> a b c
constA = arr . const


--------------------------------------------------------------------------------
sequenceA :: Arrow a => [a b c] -> a b [c]
sequenceA = foldr reduce $ constA []
  where
    reduce xa la = xa &&& la >>^ arr (uncurry (:))


--------------------------------------------------------------------------------
unitA :: Arrow a => a b ()
unitA = constA ()