Last active
April 1, 2018 14:43
-
-
Save napicella/5082912ca89847629bf33f8199a1dfc9 to your computer and use it in GitHub Desktop.
Golang-patterns maybe
This file contains 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
Context("User present", func() { | |
var greeting string | |
MaybeUser(getUser(1)).IfPresent(func(u *User) { | |
greeting = "Hello " + u.name | |
}) | |
It("greets the user", func() { | |
Expect(greeting).To(Equal("Hello Mickey")) | |
}) | |
}) | |
Context("User absent", func() { | |
var greeting string | |
MaybeUser(getUser(-1)).WhenAbsent(func() { | |
greeting = "Hello stranger" | |
}) | |
It("greets the user", func() { | |
Expect(greeting).To(Equal("Hello stranger")) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment