Created
April 13, 2020 10:47
-
-
Save kutyel/aa6b6461070da433085cd085d56e5d48 to your computer and use it in GitHub Desktop.
Translator to mi mi mi in Elm! ~20 mins.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main exposing (..) | |
import Browser | |
import Html exposing (Html, div, h1, input, p, text) | |
import Html.Attributes exposing (placeholder) | |
import Html.Events exposing (onInput) | |
import Regex as R | |
---- MODEL ---- | |
type Model | |
= Message String | |
init : ( Model, Cmd Msg ) | |
init = | |
( Message "", Cmd.none ) | |
---- UPDATE ---- | |
type Msg | |
= UpdateMsg String | |
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg _ = | |
case msg of | |
UpdateMsg str -> | |
let | |
opts = | |
{ caseInsensitive = True, multiline = True } | |
regex = | |
Maybe.withDefault R.never <| R.fromStringWith opts "a|e|o|u" | |
in | |
( Message (R.replace regex (always "i") str), Cmd.none ) | |
---- VIEW ---- | |
view : Model -> Html Msg | |
view (Message str) = | |
div [] | |
[ h1 [] [ text "Translator to Mimimi!" ] | |
, input [ placeholder "text to translate", onInput UpdateMsg ] [] | |
, p [] [ text str ] | |
] | |
---- PROGRAM ---- | |
main : Program () Model Msg | |
main = | |
Browser.element | |
{ view = view | |
, init = always init | |
, update = update | |
, subscriptions = always Sub.none | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment