Skip to content

Instantly share code, notes, and snippets.

@kutyel
Created April 13, 2020 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kutyel/aa6b6461070da433085cd085d56e5d48 to your computer and use it in GitHub Desktop.
Save kutyel/aa6b6461070da433085cd085d56e5d48 to your computer and use it in GitHub Desktop.
Translator to mi mi mi in Elm! ~20 mins.
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