Skip to content

Commit a38507b

Browse files
authored
Made README clearer still (hopefully) by replacing lhsaVariable and rhsnewValue and a few other rewrites.
1 parent 1d05201 commit a38507b

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,47 @@ NilCoalescingAssignmentOperators is Swift micro-library that provides two nil-co
44

55
## `??=`
66

7-
**`lhs ??= rhs`** works like Ruby's `||=` operator:
7+
**`aVariable ??= newValue`** performs the value assignment if `aVariable` is nil _(like Ruby's `||=` operator)_:
88

9-
1. If `lhs` is non-nil, does nothing.
10-
2. If `lhs` is nil but `rhs` is non-nil, does the assignment: `lhs = rhs`
11-
3. If `lhs` & `rhs` are both nil, does nothing.
9+
1. If `aVariable` is non-nil, does nothing.
10+
2. If `aVariable` is nil but `newValue` is non-nil, does the assignment: `aVariable = newValue`
11+
3. If `aVariable` & `newValue` are both nil, does nothing.
1212

1313
```swift
14-
lhs ??= rhs
14+
aVariable ??= newValue
1515
```
1616
is equivalent to:
1717

1818
```swift
1919
// roughly:
20-
lhs = lhs ?? rhs
20+
aVariable = aVariable ?? newValue
2121

2222
// precisely:
23-
if lhs == nil { lhs = rhs }
23+
if aVariable == nil { aVariable = newValue }
2424
```
2525

2626
## `=??`
2727

28-
**`lhs =?? rhs`** works similarly, but prefers the `rhs` over the `lhs`:
28+
**`aVariable =?? newValue`** performs the value assignment if `newValue` is non-nil _(like `??=` but prefers the `newValue` over the `aVariable`)_:
2929

30-
1. If `rhs` is nil, does nothing.
31-
2. If `rhs` is non-nil, does the assignment: `lhs = rhs`
32-
* _If `lhs` & `rhs` are both non-nil, still does the assignment._
30+
1. If `newValue` is nil, does nothing.
31+
2. If `newValue` is non-nil, does the assignment: `aVariable = newValue`
32+
3. If `aVariable` & `newValue` are both non-nil, still does the assignment.
3333

3434

3535
```swift
36-
lhs =?? rhs
36+
aVariable =?? newValue
3737
```
3838
is equivalent to:
3939

4040
```swift
4141
// roughly:
42-
lhs = rhs ?? lhs
42+
aVariable = newValue ?? aVariable
4343

4444
// precisely:
45-
if rhs != nil { lhs = rhs }
45+
if newValue != nil { aVariable = newValue }
4646
// or
47-
if let rhs = rhs { lhs = rhs }
47+
if let newValue = newValue { aVariable = newValue }
4848
```
4949

5050

0 commit comments

Comments
 (0)