Skip to content

Commit

Permalink
Added documentation for conditional operators (#29)
Browse files Browse the repository at this point in the history
* Added documentation for conditional operators

* fixed table of contents links
* fixed a couple of other small errors.

* Changes based on PR feedback.
  • Loading branch information
mluisbrown authored May 21, 2018
1 parent a230d0f commit 77fa8a2
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ In our experience it makes UI-related code easier to build and maintain. Our aim

## Content 📋

- [What's it like?](#whats-it-like)
- [How does it work?](#how-does-it-work)
- [How do components look?](#how-do-components-look)
- [Samples](#samples)
- [Installation](#installation)
- [State of the project](#state-of-the-project)
- [Contribute](#contribute)
- [What's it like?](#whats-it-like-)
- [How does it work?](#how-does-it-work-)
- [Examples](#examples-)
- [Installation](#installation-)
- [Development installation](#development-installation-)
- [State of the project](#state-of-the-project-%EF%B8%8F)
- [Contributing](#contributing-%EF%B8%8F)

### What's it like? 🧐

Expand Down Expand Up @@ -124,7 +124,9 @@ precedencegroup SectionConcatenationPrecedence {

infix operator <>: ComposingPrecedence
infix operator |-+: SectionConcatenationPrecedence
infix operator |--+: NodeConcatenationPrecedence
infix operator |-?: SectionConcatenationPrecedence
infix operator |---+: NodeConcatenationPrecedence
infix operator |---?: NodeConcatenationPrecedence

let bento = Box.empty // 3
|-+ Section() // 2
Expand All @@ -143,6 +145,30 @@ The order of the expression above is:
2. `Section() |---+ Node()` => `Section`
3. `Box() |-+ Section()` => `Box`

#### Conditional operators ❓

In addition to the `|-+` and `|---+` concatenation operators, Bento has conditional concatenation operators:
* `|-?` for `Section`
* `|---?` for `Node`

They are used to provide a `Section` or `Node` in a closure for the `Bool` and `Optional` happy path, via the `.iff` and `.some` functions.

Here are some examples:
```swift
let box = Box.empty
|-? .iff(aBoolCondition) {
       Section() // <-- Section only added if `boolCondition` is `true`
   }
```
```swift
let box = Box.empty
   |-? .some(anOptional) { theOptional in // <-- the value of anOptional unwrapped
       Section() // <-- Section only added if `anOptional` is not `nil`
   }
```

`|---?` works in exactly the same way for `Node`s

### Examples 😎

Sections | Appointment | Movies
Expand Down Expand Up @@ -193,4 +219,4 @@ Contributions are very welcome and highly appreciated! ❤️ Here's how to do i

- If you have any questions feel free to create an issue with a `question` label;
- If you have a feature request you can create an issue with a `Feature request` label;
- If you found a bug feel free to create an issue with a `bug` label or open a PR with a fix.
- If you found a bug feel free to create an issue with a `bug` label or open a PR with a fix.

0 comments on commit 77fa8a2

Please sign in to comment.