summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOShev <>2018-04-16 08:54:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2018-04-16 08:54:00 (GMT)
commit7d31f912f093614f3714a879a8761b50eb6a04a2 (patch)
tree8d4b4075ee0bda5416fb8eb825c6535ecbd05a68
parentbff6e028ac6ad45af6a5c47f441db15885e27858 (diff)
version 0.1.10.1.1
-rw-r--r--library/Timestamp/Foldls.hs30
-rw-r--r--library/Timestamp/Prelude.hs4
-rw-r--r--timestamp.cabal4
3 files changed, 37 insertions, 1 deletions
diff --git a/library/Timestamp/Foldls.hs b/library/Timestamp/Foldls.hs
new file mode 100644
index 0000000..f842eb0
--- /dev/null
+++ b/library/Timestamp/Foldls.hs
@@ -0,0 +1,30 @@
+{-|
+Folds on timestamped values
+-}
+module Timestamp.Foldl
+where
+
+import Timestamp.Prelude hiding (maximum)
+import Timestamp
+import Control.Foldl
+
+
+untimestamped :: Fold input output -> Fold (Timestamped input) output
+untimestamped =
+ premap (\ (Timestamped _ x) -> x)
+
+filteringByUtcTime :: (UTCTime -> Bool) -> Fold (Timestamped input) output -> Fold (Timestamped input) output
+filteringByUtcTime filter =
+ filteringByTimestamp (filter . timestampUtcTime)
+
+filteringByTimestamp :: (Timestamp -> Bool) -> Fold (Timestamped input) output -> Fold (Timestamped input) output
+filteringByTimestamp filter =
+ prefilter (\ (Timestamped ts _) -> filter ts)
+
+inUtcTimeRange :: UTCTime -> UTCTime -> Fold (Timestamped input) output -> Fold (Timestamped input) output
+inUtcTimeRange start end =
+ inTimestampRange (utcTimeTimestamp start) (utcTimeTimestamp end)
+
+inTimestampRange :: Timestamp -> Timestamp -> Fold (Timestamped input) output -> Fold (Timestamped input) output
+inTimestampRange start end =
+ filteringByTimestamp (\ ts -> ts >= start && ts < end)
diff --git a/library/Timestamp/Prelude.hs b/library/Timestamp/Prelude.hs
index f6d867c..bfcdc9e 100644
--- a/library/Timestamp/Prelude.hs
+++ b/library/Timestamp/Prelude.hs
@@ -69,6 +69,10 @@ import Text.Printf as Exports (printf, hPrintf)
import Text.Read as Exports (Read(..), readMaybe, readEither)
import Unsafe.Coerce as Exports
+-- foldl
+-------------------------
+import Control.Foldl as Exports (Fold(..), FoldM(..))
+
-- cereal
-------------------------
import Data.Serialize as Exports (Serialize)
diff --git a/timestamp.cabal b/timestamp.cabal
index f19609f..3a95882 100644
--- a/timestamp.cabal
+++ b/timestamp.cabal
@@ -1,7 +1,7 @@
name:
timestamp
version:
- 0.1.0.1
+ 0.1.1
synopsis:
Space-efficient Unix timestamp and utilities
category:
@@ -40,12 +40,14 @@ library
Haskell2010
exposed-modules:
Timestamp
+ Timestamp.Foldls
other-modules:
Timestamp.Data.Conversion
Timestamp.Data.TypesAndInstances
Timestamp.Prelude
build-depends:
cereal >=0.5.4 && <0.6,
+ foldl >=1.3.5 && <2,
hashable >=1.2 && <2,
QuickCheck >=2.8.1 && <3,
time >=1.8 && <2,