{-# LANGUAGE ViewPatterns #-}
module Text.Pandoc.Readers.Odt.Generic.Utils
( uncurry3
, uncurry4
, uncurry5
, uncurry6
, swap
, reverseComposition
, tryToRead
, Lookupable(..)
, readLookupable
, readPercent
, findBy
, swing
, composition
) where
import Control.Category (Category, (<<<), (>>>))
import qualified Control.Category as Cat (id)
import Data.Char (isSpace)
import qualified Data.Foldable as F (Foldable, foldr)
import Data.Maybe
import Data.Text (Text)
import qualified Data.Text as T
composition :: (Category cat, F.Foldable f) => f (cat a a) -> cat a a
composition :: f (cat a a) -> cat a a
composition = (cat a a -> cat a a -> cat a a)
-> cat a a -> f (cat a a) -> cat a a
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr cat a a -> cat a a -> cat a a
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
(<<<) cat a a
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
Cat.id
reverseComposition :: (Category cat, F.Foldable f) => f (cat a a) -> cat a a
reverseComposition :: f (cat a a) -> cat a a
reverseComposition = (cat a a -> cat a a -> cat a a)
-> cat a a -> f (cat a a) -> cat a a
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr cat a a -> cat a a -> cat a a
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
(>>>) cat a a
forall k (cat :: k -> k -> *) (a :: k). Category cat => cat a a
Cat.id
swing :: (((a -> b) -> b) -> c -> d) -> c -> a -> d
swing :: (((a -> b) -> b) -> c -> d) -> c -> a -> d
swing = (a -> c -> d) -> c -> a -> d
forall a b c. (a -> b -> c) -> b -> a -> c
flip((a -> c -> d) -> c -> a -> d)
-> ((((a -> b) -> b) -> c -> d) -> a -> c -> d)
-> (((a -> b) -> b) -> c -> d)
-> c
-> a
-> d
forall b c a. (b -> c) -> (a -> b) -> a -> c
.((((a -> b) -> b) -> c -> d) -> (a -> (a -> b) -> b) -> a -> c -> d
forall b c a. (b -> c) -> (a -> b) -> a -> c
.((a -> b) -> a -> b) -> a -> (a -> b) -> b
forall a b c. (a -> b -> c) -> b -> a -> c
flip (a -> b) -> a -> b
forall a. a -> a
id)
tryToRead :: (Read r) => Text -> Maybe r
tryToRead :: Text -> Maybe r
tryToRead = (ReadS r
forall a. Read a => ReadS a
reads ReadS r -> (Text -> String) -> Text -> [(r, String)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack) (Text -> [(r, String)])
-> ([(r, String)] -> Maybe r) -> Text -> Maybe r
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> [(r, String)] -> Maybe (r, String)
forall a. [a] -> Maybe a
listToMaybe ([(r, String)] -> Maybe (r, String))
-> (Maybe (r, String) -> Maybe r) -> [(r, String)] -> Maybe r
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ((r, String) -> r) -> Maybe (r, String) -> Maybe r
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (r, String) -> r
forall a b. (a, b) -> a
fst
readPercent :: ReadS Int
readPercent :: ReadS Int
readPercent String
s = [ (Int
i,String
s') | (Int
i , String
r ) <- ReadS Int
forall a. Read a => ReadS a
reads String
s
, (String
"%" , String
s') <- ReadS String
lex String
r
]
class Lookupable a where
lookupTable :: [(Text, a)]
readLookupable :: (Lookupable a) => Text -> Maybe a
readLookupable :: Text -> Maybe a
readLookupable Text
s =
Text -> [(Text, a)] -> Maybe a
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ((Char -> Bool) -> Text -> Text
T.takeWhile (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isSpace) (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Text
T.dropWhile Char -> Bool
isSpace Text
s) [(Text, a)]
forall a. Lookupable a => [(Text, a)]
lookupTable
uncurry3 :: (a->b->c -> z) -> (a,b,c ) -> z
uncurry4 :: (a->b->c->d -> z) -> (a,b,c,d ) -> z
uncurry5 :: (a->b->c->d->e -> z) -> (a,b,c,d,e ) -> z
uncurry6 :: (a->b->c->d->e->f -> z) -> (a,b,c,d,e,f ) -> z
uncurry3 :: (a -> b -> c -> z) -> (a, b, c) -> z
uncurry3 a -> b -> c -> z
fun (a
a,b
b,c
c ) = a -> b -> c -> z
fun a
a b
b c
c
uncurry4 :: (a -> b -> c -> d -> z) -> (a, b, c, d) -> z
uncurry4 a -> b -> c -> d -> z
fun (a
a,b
b,c
c,d
d ) = a -> b -> c -> d -> z
fun a
a b
b c
c d
d
uncurry5 :: (a -> b -> c -> d -> e -> z) -> (a, b, c, d, e) -> z
uncurry5 a -> b -> c -> d -> e -> z
fun (a
a,b
b,c
c,d
d,e
e ) = a -> b -> c -> d -> e -> z
fun a
a b
b c
c d
d e
e
uncurry6 :: (a -> b -> c -> d -> e -> f -> z) -> (a, b, c, d, e, f) -> z
uncurry6 a -> b -> c -> d -> e -> f -> z
fun (a
a,b
b,c
c,d
d,e
e,f
f ) = a -> b -> c -> d -> e -> f -> z
fun a
a b
b c
c d
d e
e f
f
swap :: (a,b) -> (b,a)
swap :: (a, b) -> (b, a)
swap (a
a,b
b) = (b
b,a
a)
findBy :: (a -> Maybe b) -> [a] -> Maybe b
findBy :: (a -> Maybe b) -> [a] -> Maybe b
findBy a -> Maybe b
_ [] = Maybe b
forall a. Maybe a
Nothing
findBy a -> Maybe b
f ((a -> Maybe b
f -> Just b
x):[a]
_ ) = b -> Maybe b
forall a. a -> Maybe a
Just b
x
findBy a -> Maybe b
f ( a
_:[a]
xs) = (a -> Maybe b) -> [a] -> Maybe b
forall a b. (a -> Maybe b) -> [a] -> Maybe b
findBy a -> Maybe b
f [a]
xs