List comprehensions are good, let's use them

This commit is contained in:
Christine Dodrill 2015-08-14 14:20:54 -07:00
parent 813e1164c1
commit d80166a420
1 changed files with 3 additions and 4 deletions

View File

@ -126,14 +126,13 @@ routes:
get "/search": get "/search":
var var
query = @"q".toLower query = @"q".toLower
eps: seq[Episode]
if query == "": if query == "":
halt Http406, myHeaders, $ %* { "error": "Need to specify query" } halt Http406, myHeaders, $ %* { "error": "Need to specify query" }
for episode in episodes: var
if episode.name.toLower.contains query: eps: seq[Episode] =
eps = eps & episode lc[x | (x <- episodes, x.name.toLower.contains query), Episode]
if eps.len == 0: if eps.len == 0:
resp Http404, myHeaders, $ %* { "error": "No episodes found" } resp Http404, myHeaders, $ %* { "error": "No episodes found" }