Generalize name generation

main
Bram van den Heuvel 2023-09-03 09:30:12 +02:00
parent 0dbc38aebc
commit 54bece3aea
3 changed files with 176 additions and 57 deletions

View File

@ -9,20 +9,17 @@ For more name generators, make sure to check out <https://www.fantasynamegenerat
-}
import Names.Tools as Tools
import Random exposing (Generator)
import String.Extra
female : Generator String
female =
Random.uniform
(Random.map3 (\a b c -> a ++ b ++ c) nm1 nm2 nm3
|> Random.map String.Extra.toTitleCase
)
[ Random.map5 (\a b c d e -> a ++ b ++ c ++ d ++ e) nm1 nm2 nm3 nm4 nm5
|> Random.map String.Extra.toTitleCase
]
|> Random.andThen identity
Tools.chooseFrom2
(Tools.map3 nm1 nm2 nm3)
(Tools.map5 nm1 nm2 nm3 nm4 nm5)
|> Random.map String.Extra.toTitleCase
male : Generator String

View File

@ -9,71 +9,30 @@ For more name generators, make sure to check out <https://www.fantasynamegenerat
-}
import Names.Tools as Tools
import Random exposing (Generator)
import String.Extra
female : Generator String
female =
Random.uniform
(Random.map5
(\a b c d e -> a ++ " " ++ b ++ " " ++ c ++ " " ++ d ++ " " ++ e)
nm7
nm8
nm9
nm10
nm13
)
[ Random.map5
(\( a, b ) ( c, d ) e f g ->
a ++ " " ++ b ++ " " ++ c ++ " " ++ d ++ " " ++ e ++ " " ++ f ++ " " ++ g
)
(Random.map2 Tuple.pair nm7 nm8)
(Random.map2 Tuple.pair nm9 nm10)
nm11
nm12
nm13
]
|> Random.andThen identity
Tools.chooseFrom2
(Tools.map5 nm7 nm8 nm9 nm10 nm13)
(Tools.map7 nm7 nm8 nm9 nm10 nm11 nm12 nm13)
|> Random.map String.Extra.toTitleCase
male : Generator String
male =
Random.uniform
(Random.map5
(\a b c d e -> a ++ " " ++ b ++ " " ++ c ++ " " ++ d ++ " " ++ e)
nm1
nm2
nm3
nm4
nm6
)
[ Random.map5
(\( a, b ) ( c, d ) e f g ->
a ++ " " ++ b ++ " " ++ c ++ " " ++ d ++ " " ++ e ++ " " ++ f ++ " " ++ g
)
(Random.map2 Tuple.pair nm1 nm2)
(Random.map2 Tuple.pair nm3 nm4)
nm5
nm4
nm6
]
|> Random.andThen identity
Tools.chooseFrom2
(Tools.map5 nm1 nm2 nm3 nm4 nm6)
(Tools.map7 nm1 nm2 nm3 nm4 nm5 nm4 nm6)
|> Random.map String.Extra.toTitleCase
lastName : Generator String
lastName =
Random.map5
(\( a, b ) ( c, d ) e f g ->
a ++ " " ++ b ++ " " ++ c ++ " " ++ d ++ " " ++ e ++ " " ++ f ++ " " ++ g
)
(Random.map2 Tuple.pair nm1 nm2)
(Random.map2 Tuple.pair nm3 nm4)
nm11
nm12
nm13
Tools.map7 nm1 nm2 nm3 nm4 nm11 nm12 nm13
|> Random.map String.Extra.toTitleCase

163
src/Names/Tools.elm Normal file
View File

@ -0,0 +1,163 @@
module Names.Tools exposing (..)
{-| The Tools module helps with the generation of names.
-}
import Random exposing (Generator)
chooseFrom2 : Generator a -> Generator a -> Generator a
chooseFrom2 a b =
Random.uniform a [ b ]
|> Random.andThen identity
chooseFrom3 : Generator a -> Generator a -> Generator a -> Generator a
chooseFrom3 a b c =
Random.uniform a [ b, c ]
|> Random.andThen identity
chooseFrom4 :
Generator a
-> Generator a
-> Generator a
-> Generator a
-> Generator a
chooseFrom4 a b c d =
Random.uniform a [ b, c, d ]
|> Random.andThen identity
chooseFrom5 :
Generator a
-> Generator a
-> Generator a
-> Generator a
-> Generator a
-> Generator a
chooseFrom5 a b c d e =
Random.uniform a [ b, c, d, e ]
|> Random.andThen identity
chooseFrom6 :
Generator a
-> Generator a
-> Generator a
-> Generator a
-> Generator a
-> Generator a
-> Generator a
chooseFrom6 a b c d e f =
Random.uniform a [ b, c, d, e, f ]
|> Random.andThen identity
chooseFrom7 :
Generator a
-> Generator a
-> Generator a
-> Generator a
-> Generator a
-> Generator a
-> Generator a
-> Generator a
chooseFrom7 a b c d e f g =
Random.uniform a [ b, c, d, e, f, g ]
|> Random.andThen identity
chooseFrom8 :
Generator a
-> Generator a
-> Generator a
-> Generator a
-> Generator a
-> Generator a
-> Generator a
-> Generator a
-> Generator a
chooseFrom8 a b c d e f g h =
Random.uniform a [ b, c, d, e, f, g, h ]
|> Random.andThen identity
map2 : Generator String -> Generator String -> Generator String
map2 =
Random.map2 (++)
map3 :
Generator String
-> Generator String
-> Generator String
-> Generator String
map3 =
Random.map3 (\a b c -> a ++ b ++ c)
map4 :
Generator String
-> Generator String
-> Generator String
-> Generator String
-> Generator String
map4 =
Random.map4 (\a b c d -> a ++ b ++ c ++ d)
map5 :
Generator String
-> Generator String
-> Generator String
-> Generator String
-> Generator String
-> Generator String
map5 =
Random.map5 (\a b c d e -> a ++ b ++ c ++ d ++ e)
map6 :
Generator String
-> Generator String
-> Generator String
-> Generator String
-> Generator String
-> Generator String
-> Generator String
map6 nm1 nm2 =
Random.map5 (\( a, b ) c d e f -> a ++ b ++ c ++ d ++ e ++ f)
(Random.map2 Tuple.pair nm1 nm2)
map7 :
Generator String
-> Generator String
-> Generator String
-> Generator String
-> Generator String
-> Generator String
-> Generator String
-> Generator String
map7 nm1 nm2 nm3 nm4 =
Random.map5 (\( a, b ) ( c, d ) e f g -> a ++ b ++ c ++ d ++ e ++ f ++ g)
(Random.map2 Tuple.pair nm1 nm2)
(Random.map2 Tuple.pair nm3 nm4)
map8 :
Generator String
-> Generator String
-> Generator String
-> Generator String
-> Generator String
-> Generator String
-> Generator String
-> Generator String
-> Generator String
map8 nm1 nm2 nm3 nm4 nm5 nm6 =
Random.map5 (\( a, b ) ( c, d ) ( e, f ) g h -> a ++ b ++ c ++ d ++ e ++ f ++ g ++ h)
(Random.map2 Tuple.pair nm1 nm2)
(Random.map2 Tuple.pair nm3 nm4)
(Random.map2 Tuple.pair nm5 nm6)