Skip to content

Instantly share code, notes, and snippets.

@olpeh
Created November 3, 2017 17:19
Show Gist options
  • Save olpeh/cc1dd89561e4cdbb06bf588386e98b52 to your computer and use it in GitHub Desktop.
Save olpeh/cc1dd89561e4cdbb06bf588386e98b52 to your computer and use it in GitHub Desktop.
names -> emails (Elm)
module Main exposing (..)
import Regex
import String.Extra exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
main =
Html.beginnerProgram
{ model = model
, view = view
, update = update
}
model =
"Olavi Haapala"
update textThatTheUserHasWritten model =
textThatTheUserHasWritten
view model =
div []
[ textarea
[ value model
, onInput (\text -> text)
, rows 5
, cols 30
]
[]
, br [] []
, pre []
[ Html.text (toEmails model)
]
]
toEmails : String -> String
toEmails input =
let
fullNameList =
String.split "\n" input
namesWithSomething =
List.filter filterNonEmpty fullNameList
names =
List.map addDots namesWithSomething
in
names
|> String.join ",\n"
filterNonEmpty str =
not (isBlank str)
addDots : String -> String
addDots fullName =
fullName
|> String.trim
|> String.toLower
|> removeAccents
|> removeScandics
|> String.split " "
|> String.join "."
|> (\dottedName -> dottedName ++ "@futurice.com")
removeScandics : String -> String
removeScandics input =
input
|> Regex.replace Regex.All (Regex.regex "[ö]") (\_ -> "o")
|> Regex.replace Regex.All (Regex.regex "[åä]") (\_ -> "a")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment