Skip to content

Instantly share code, notes, and snippets.

@kutyel
Created Apr 13, 2020
Embed
What would you like to do?
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