Skip to content

Commit

Permalink
Added documentation for the else part of unwrap. (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
InukVT authored Apr 29, 2020
1 parent 7c8e954 commit 841fc5c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ let html = HTML(.body(
))
```

Just like `.if()`, the `.unwrap()` command can also be passed an `else` clause that will be used if the optional being unwrapped turned out to be `nil`:

```swift
let user: User? = loadUser()

let html = HTML(.body(
.unwrap(user, {
.p("Hello, \($0.name)")
},
else: .text("Please log in")
)
))
```

Finally, the `.forEach()` command can be used to transform any Swift `Sequence` into a group of nodes, which is incredibly useful when constructing lists:

```swift
Expand Down

0 comments on commit 841fc5c

Please sign in to comment.