{-# 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 :: forall (cat :: * -> * -> *) (f :: * -> *) a.
(Category cat, Foldable f) =>
f (cat a a) -> cat a a
composition = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
(<<<) 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 :: forall (cat :: * -> * -> *) (f :: * -> *) a.
(Category cat, Foldable f) =>
f (cat a a) -> cat a a
reverseComposition = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
F.foldr forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
(>>>) forall {k} (cat :: k -> k -> *) (a :: k). Category cat => cat a a
Cat.id
swing :: (((a -> b) -> b) -> c -> d) -> c -> a -> d
swing :: forall a b c d. (((a -> b) -> b) -> c -> d) -> c -> a -> d
swing = forall a b c. (a -> b -> c) -> b -> a -> c
flipforall b c a. (b -> c) -> (a -> b) -> a -> c
.(forall b c a. (b -> c) -> (a -> b) -> a -> c
.forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. a -> a
id)
tryToRead :: (Read r) => Text -> Maybe r
tryToRead :: forall r. Read r => Text -> Maybe r
tryToRead = (forall a. Read a => ReadS a
reads forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack) forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall a. [a] -> Maybe a
listToMaybe forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> a
fst
readPercent :: ReadS Int
readPercent :: ReadS Int
readPercent String
s = [ (Int
i,String
s') | (Int
i , String
r ) <- 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 :: forall a. Lookupable a => Text -> Maybe a
readLookupable Text
s =
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup ((Char -> Bool) -> Text -> Text
T.takeWhile (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isSpace) forall a b. (a -> b) -> a -> b
$ (Char -> Bool) -> Text -> Text
T.dropWhile Char -> Bool
isSpace Text
s) 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 :: forall a b c z. (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 :: forall a b c d z. (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 :: forall a b c d e z.
(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 :: forall a b c d e f z.
(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 :: forall a b. (a, b) -> (b, a)
swap (a
a,b
b) = (b
b,a
a)
findBy :: (a -> Maybe b) -> [a] -> Maybe b
findBy :: forall a b. (a -> Maybe b) -> [a] -> Maybe b
findBy a -> Maybe b
_ [] = forall a. Maybe a
Nothing
findBy a -> Maybe b
f ((a -> Maybe b
f -> Just b
x):[a]
_ ) = forall a. a -> Maybe a
Just b
x
findBy a -> Maybe b
f ( a
_:[a]
xs) = forall a b. (a -> Maybe b) -> [a] -> Maybe b
findBy a -> Maybe b
f [a]
xs