Skip to content

Instantly share code, notes, and snippets.

@YusukeKokubo
Last active December 11, 2015 17:38
Show Gist options
  • Save YusukeKokubo/4635710 to your computer and use it in GitHub Desktop.
Save YusukeKokubo/4635710 to your computer and use it in GitHub Desktop.
hello lemon (todo)
module Server
open Lemon
open System.Collections.Generic
let todolist = ResizeArray<string>()
let (|Int|_|) (str: string) =
match System.Int32.TryParse(str) with
| true, x -> Some x
| _ -> None
let (server:Server) = function
| GET(Url []) ->
let res = Seq.mapi (fun i todo -> i.ToString() + ":" + todo) todolist
ok >> response (String.concat "\n" res)
| GET(Url ["add"; todo]) ->
todolist.Add(todo)
ok >> response ("added " + todo)
| GET(Url [Int id; "edit"; todo]) ->
let before = todolist.[id]
todolist.[id] <- todo
ok >> response ("updated " + id.ToString() + ":" + before + " -> " + todo)
| GET(Url [Int id; "delete"]) ->
todolist.RemoveAt(id)
ok >> response ("deleted " + id.ToString())
| _ -> notFound
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment