Last active
December 18, 2015 09:09
-
-
Save ToJans/5758964 to your computer and use it in GitHub Desktop.
My take on immutable models and builders
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 EasyPeasy | |
defrecord Post, | |
id: nil, | |
title: nil, | |
body: nil, | |
publishedOn: nil, | |
formatter: nil | |
def formatter(post) do | |
"#{post.id} - #{post.title}\n published on #{post.publishedOn}\n\n#{post.body}" | |
end | |
end | |
aPost = EasyPeasy.Post.new id: 1, title: "Muahaha", publishedOn: :calendar.local_time, formatter: EasyPeasy.formatter | |
aPost = aPost.body("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc eget sagittis eros.") | |
aPost |> aPost.formatter | |
aPost = aPost.formatter (fn post -> title) | |
aPost |> aPost.formatter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment