Adding code examples in comments (#27)

This commit is contained in:
Cristhian Motoche 2016-06-23 03:27:05 -05:00 committed by Mark Karpov
parent f505bafb70
commit 456fd6c1f0
7 changed files with 48 additions and 0 deletions

View File

@ -134,6 +134,9 @@ import Data.Char ( toLower )
-- | Transforms CamelCasedString to
-- snake_cased_string_with_underscores. Throws exception if parsing failed
--
-- >>> toUnderscore "FooBarBazz"
-- "foo_bar_bazz"
toUnderscore :: String -> String
toUnderscore =
underscore
@ -142,6 +145,9 @@ toUnderscore =
-- | Transforms CamelCasedString to snake-cased-string-with-dashes. Throws
-- exception if parsing failed.
--
-- >>> toDashed "FooBarBazz"
-- "foo-bar-bazz"
toDashed :: String -> String
toDashed =
dasherize
@ -153,6 +159,11 @@ toDashed =
-- 'True' then FirstCharacter in result string will be in upper case. If
-- 'False' then firstCharacter will be in lower case. Throws exception if
-- parsing failed
--
-- >>> toCamelCased True "foo_bar_bazz"
-- "FooBarBazz"
-- >>> toCamelCased False "foo_bar_bazz"
-- "fooBarBazz"
toCamelCased :: Bool -> String -> String
toCamelCased t =
camelizeCustom t

View File

@ -7,12 +7,20 @@ import Data.Char (toUpper, toLower)
import Prelude (String, Bool(..), concatMap, (.), zip, ($), repeat)
-- |Turns a an input Word List in into CamelCase. Returns the CamelCase String.
--
-- >>> camelize [ Word "foo", Acronym "bar", Word "bazz" ]
-- "FoobarBazz"
camelize
:: [Word] -- ^ Input Words to separate with underscores
-> String -- ^ The camelized String
camelize = camelizeCustom True
-- |Turns an input Word List into a CamelCase String.
--
-- >>> camelizeCustom False [ Word "foo", Acronym "bar", Word "bazz" ]
-- "foobarBazz"
camelizeCustom
:: Bool -- ^ Whether to capitalize the first character in the output String
-> [Word] -- ^ The input Words

View File

@ -7,6 +7,11 @@ import Data.List (intercalate)
import Prelude (String, (.), map)
-- | Replaces underscores in a snake_cased string with dashes (hyphens).
-- |
-- >>> dasherize [ Word "foo", Acronym "bar", Word "bazz" ]
-- "foo-bar-bazz"
dasherize
:: [Word] -- ^ Input Words to separate with dashes
-> String -- ^ The dasherized String

View File

@ -8,6 +8,9 @@ import Prelude (String, Bool(..), (.), map, zip, ($), unwords, repeat)
-- |Capitalizes the first word and turns underscores into spaces. Like titleize,
-- this is meant for creating pretty output.
--
-- >>> humanize [ Word "foo", Acronym "bar", Word "bazz" ]
-- "Foo bar bazz"
humanize
:: [Word] -- ^ List of Words, first of which will be capitalized
-> String -- ^ The humanized output

View File

@ -3,6 +3,13 @@ where
-- |Returns the suffix that should be added to a number to denote the position
-- in an ordered sequence such as 1st, 2nd, 3rd, 4th.
--
-- >>> ordinal 1
-- "st"
-- >>> ordinal 2
-- "nd"
-- >>> ordinal 10
-- "th"
ordinal :: Integer -> String
ordinal number
| remainder100 `elem` [11..13] = "th"
@ -16,6 +23,13 @@ ordinal number
-- |Turns a number into an ordinal string used to denote the position in an
-- ordered sequence such as 1st, 2nd, 3rd, 4th.
--
-- >>> ordinalize 1
-- "1st"
-- >>> ordinalize 2
-- "2nd"
-- >>> ordinalize 10
-- "10th"
ordinalize :: Integer -> String
ordinalize n = show n ++ ordinal n

View File

@ -7,6 +7,9 @@ import Data.Char (toUpper)
import Prelude (String, unwords, map, ($))
-- | Capitalizes all the Words in the input 'Data.List'.
--
-- >>> titleize [ Word "foo", Acronym "bar", Word "bazz" ]
-- "Foo bar Bazz"
titleize
:: [Word] -- ^ List of Words, first of which will be capitalized
-> String -- ^ The titleized String

View File

@ -8,6 +8,10 @@ import Data.List (intercalate)
import Prelude (String, (.), map)
-- |Turns a CamelCase string into an underscore_separated String.
--
-- >>> underscore [ Word "foo", Acronym "bar", Word "bazz" ]
-- "foo_bar_bazz"
underscore
:: [Word] -- ^ Input Words to separate with underscores
-> String -- ^ The underscored String