Skip to content

Instantly share code, notes, and snippets.

@cakesmith
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save cakesmith/30026d3b482cc6bc0265 to your computer and use it in GitHub Desktop.

Select an option

Save cakesmith/30026d3b482cc6bc0265 to your computer and use it in GitHub Desktop.
import Graphics.Element (..)
import Graphics.Input.Field as Field
import Signal
import List (head)
import Char (..)
import String (length, slice, toList, indexes, cons, map)
import Text (plainText)
content : Signal.Channel Field.Content
content =
Signal.channel Field.noContent
main : Signal Element
main =
Signal.map scene (Signal.subscribe content)
scene : Field.Content -> Element
scene fieldContent =
flow down
[ Field.field Field.defaultStyle (Signal.send content) "Type here!" fieldContent
, plainText (rot13 fieldContent.string)
]
rot13 : String -> String
rot13 message =
message
|> map (\ch ->
if
| isLower ch -> rotate 13 ch
| isUpper ch -> toUpper (rotate 13 (toLower ch))
)
rotate : Int -> Char -> Char
rotate i ch =
charAt <| (charValue ch + i) % (length alphabet)
alphabet = "abcdefghijklmnopqrstuvwxyz"
charAt : Int -> Char
charAt i =
slice i (i+1) alphabet
|> toList
|> head
charValue : Char -> Int
charValue ch =
head <| indexes (cons ch "") alphabet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment