Last active
September 13, 2015 07:01
-
-
Save sifue/8a73b7f093b3171bf125 to your computer and use it in GitHub Desktop.
DDDに役立つScalaの関数型プログラミング的機能 ref: http://qiita.com/sifue/items/8618eba5e48bd8063813
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
| public interface User { | |
| public LotResult lot(); | |
| public class Present {} | |
| public interface LotResult { | |
| public Present present(); | |
| } | |
| public class Hit implements LotResult { | |
| public Present present() { return new Present();} | |
| } | |
| public class Blank implements LotResult { | |
| public Present present() { return null;} | |
| } | |
| } |
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
| trait User { | |
| def lot:Option[Present] | |
| } | |
| class Present |
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
| trait Student { | |
| def tryTest:Either[FailReason, Department] | |
| } |
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
| trait BanExecutor { | |
| def ban(user:User, administrator:Administrator): (BanedUser, BanMail) | |
| } |
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
| interface Administrator { | |
| public BanResult ban(user:User); | |
| } | |
| interface BanResult |
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
| val invitations:Seq[Invitaion] = visitors | |
| .filter(_.signUped) | |
| .filter(_.prefecture == "東京都") | |
| .map(createInvitaion) |
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
| trait User { | |
| def present(item:Item, targetUser:User): Unit = { | |
| moveOwnership(buy(item), targetUser) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment