-
Notifications
You must be signed in to change notification settings - Fork 5
/
Util.hs
28 lines (21 loc) · 664 Bytes
/
Util.hs
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
module Util
( unionN
, intersectionN
, encodeText
, decodeText
) where
import Prelude
import Data.Aeson (encode, decode, FromJSON, ToJSON)
import qualified Data.ByteString.Lazy as LBS
import qualified Data.Set as S
import Data.Text (Text)
import Data.Text.Encoding (encodeUtf8, decodeUtf8)
intersectionN :: Ord a => [S.Set a] -> S.Set a
intersectionN [] = S.empty
intersectionN ls = foldl1 S.intersection ls
unionN :: Ord a => [S.Set a] -> S.Set a
unionN = foldl S.union S.empty
decodeText :: FromJSON a => Text -> Maybe a
decodeText = decode . LBS.fromStrict . encodeUtf8
encodeText :: ToJSON a => a -> Text
encodeText = decodeUtf8 . LBS.toStrict . encode