module Language.Drasil.People (
HasName
, Person, People, Conv(..)
, person, person', personWM, personWM', mononym
, name, nameStr
, lstName
, rendPersLFM, rendPersLFM', rendPersLFM''
, comparePeople
) where
data Person = Person { Person -> String
_given :: String
, Person -> String
_surname :: String
, Person -> [String]
_middle :: [String]
, Person -> Conv
_convention :: Conv
} deriving (Person -> Person -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Person -> Person -> Bool
$c/= :: Person -> Person -> Bool
== :: Person -> Person -> Bool
$c== :: Person -> Person -> Bool
Eq)
type People = [Person]
data Conv = Western
| Eastern
| Mono
deriving (Conv -> Conv -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Conv -> Conv -> Bool
$c/= :: Conv -> Conv -> Bool
== :: Conv -> Conv -> Bool
$c== :: Conv -> Conv -> Bool
Eq)
comparePeople :: [Person] -> [Person] -> Ordering
comparePeople :: [Person] -> [Person] -> Ordering
comparePeople [] [] = Ordering
EQ
comparePeople [Person]
_ [] = Ordering
GT
comparePeople [] [Person]
_ = Ordering
LT
comparePeople (Person String
f1 String
l1 [String]
_ Conv
_:[Person]
xs) (Person String
f2 String
l2 [String]
_ Conv
_:[Person]
ys)
| String
l1 forall a. Eq a => a -> a -> Bool
/= String
l2 = String
l1 forall a. Ord a => a -> a -> Ordering
`compare` String
l2
| String
f1 forall a. Eq a => a -> a -> Bool
/= String
f2 = String
f1 forall a. Ord a => a -> a -> Ordering
`compare` String
f2
| Bool
otherwise = [Person] -> [Person] -> Ordering
comparePeople [Person]
xs [Person]
ys
person :: String -> String -> Person
person :: String -> String -> Person
person String
f String
l = String -> String -> [String] -> Conv -> Person
Person String
f String
l [] Conv
Western
person' :: String -> String -> Person
person' :: String -> String -> Person
person' String
s String
g = String -> String -> [String] -> Conv -> Person
Person String
g String
s [] Conv
Eastern
personWM :: String -> [String] -> String -> Person
personWM :: String -> [String] -> String -> Person
personWM String
f [String]
ms String
l = String -> String -> [String] -> Conv -> Person
Person String
f String
l [String]
ms Conv
Western
personWM' :: String -> [String] -> String -> Person
personWM' :: String -> [String] -> String -> Person
personWM' String
g [String]
ms String
s = String -> String -> [String] -> Conv -> Person
Person String
g String
s [String]
ms Conv
Eastern
mononym :: String -> Person
mononym :: String -> Person
mononym String
n = String -> String -> [String] -> Conv -> Person
Person String
"NFN" String
n [] Conv
Mono
class HasName p where
nameStr :: p -> String
instance HasName Person where
nameStr :: Person -> String
nameStr (Person String
_ String
n [String]
_ Conv
Mono) = String -> String
dotInitial String
n
nameStr (Person String
f String
l [String]
ms Conv
Western) = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr String -> String -> String
nameSep String
"" (
[String -> String
dotInitial String
f] forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map String -> String
dotInitial [String]
ms forall a. [a] -> [a] -> [a]
++ [String -> String
dotInitial String
l])
nameStr (Person String
g String
s [String]
ms Conv
Eastern) = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr String -> String -> String
nameSep String
"" (
[String -> String
dotInitial String
s] forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map String -> String
dotInitial [String]
ms forall a. [a] -> [a] -> [a]
++ [String -> String
dotInitial String
g])
name :: (HasName n) => n -> String
name :: forall n. HasName n => n -> String
name = forall n. HasName n => n -> String
nameStr
lstName :: Person -> String
lstName :: Person -> String
lstName Person {_surname :: Person -> String
_surname = String
l} = String
l
rendPersLFM :: Person -> String
rendPersLFM :: Person -> String
rendPersLFM Person {_surname :: Person -> String
_surname = String
n, _convention :: Person -> Conv
_convention = Conv
Mono} = String
n
rendPersLFM Person {_given :: Person -> String
_given = String
f, _surname :: Person -> String
_surname = String
l, _middle :: Person -> [String]
_middle = [String]
ms} =
String -> String
dotInitial String
l String -> String -> String
`orderSep` String -> String
dotInitial String
f String -> String -> String
`nameSep`
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (String -> String -> String
nameSep forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
dotInitial) String
"" [String]
ms
rendPersLFM' :: Person -> String
rendPersLFM' :: Person -> String
rendPersLFM' Person {_surname :: Person -> String
_surname = String
n, _convention :: Person -> Conv
_convention = Conv
Mono} = String
n
rendPersLFM' Person {_given :: Person -> String
_given = String
f, _surname :: Person -> String
_surname = String
l, _middle :: Person -> [String]
_middle = [String]
ms} =
String -> String
dotInitial String
l String -> String -> String
`orderSep` forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (String -> String -> String
nameSep forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
initial) String
"" (String
fforall a. a -> [a] -> [a]
:[String]
ms)
rendPersLFM'' :: Person -> String
rendPersLFM'' :: Person -> String
rendPersLFM'' Person {_surname :: Person -> String
_surname = String
n, _convention :: Person -> Conv
_convention = Conv
Mono} = String
n
rendPersLFM'' Person {_given :: Person -> String
_given = String
f, _surname :: Person -> String
_surname = String
l, _middle :: Person -> [String]
_middle = [String]
ms} =
String -> String
dotInitial String
l String -> String -> String
`orderSep` forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 String -> String -> String
nameSep (String -> String
dotInitial String
f forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map String -> String
initial [String]
ms)
initial :: String -> String
initial :: String -> String
initial [] = []
initial (Char
x:String
_) = [Char
x , Char
'.']
dotInitial :: String -> String
dotInitial :: String -> String
dotInitial [Char
x] = [Char
x,Char
'.']
dotInitial String
nm = String
nm
joiner :: String -> String -> String -> String
joiner :: String -> String -> String -> String
joiner String
_ String
a String
"" = String
a
joiner String
_ String
"" String
b = String
b
joiner String
j String
a String
b = String
a forall a. [a] -> [a] -> [a]
++ String
j forall a. [a] -> [a] -> [a]
++ String
b
orderSep :: String -> String -> String
orderSep :: String -> String -> String
orderSep = String -> String -> String -> String
joiner String
", "
nameSep :: String -> String -> String
nameSep :: String -> String -> String
nameSep = String -> String -> String -> String
joiner String
" "