Last active
December 18, 2015 04:58
-
-
Save ToJans/5728757 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Posts do | |
defrecord BlogPost, id: nil, title: nil, publishedOn: nil | |
defmodule FakeData do | |
def allPosts do | |
[ | |
BlogPost.new(id: 1,title: "Blog post one" ,publishedOn: "20130201"), | |
BlogPost.new(id: 2,title: "Blog post two" ,publishedOn: "20130202"), | |
BlogPost.new(id: 3,title: "Blog post three",publishedOn: "20130312"), | |
BlogPost.new(id: 4,title: "Blog post four" ,publishedOn: "20130404"), | |
BlogPost.new(id: 5,title: "Blog post five" ,publishedOn: "20130510"), | |
BlogPost.new(id: 6,title: "Blog post six" ,publishedOn: "20130520"), | |
BlogPost.new(id: 7,title: "Blog post seven",publishedOn: "20130521"), | |
BlogPost.new(id: 8,title: "Blog post eight",publishedOn: "20130522") | |
] | |
end | |
end | |
defmodule Queries do | |
def recentPosts() do | |
recentPosts 5 | |
end | |
def recentPosts(n) do | |
FakeData.allPosts | |
|> Enum.sort(fn x,y -> x.publishedOn < y.publishedOn end) | |
|> Enum.take(n) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment