Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add closure taking write API #75

Merged
merged 2 commits into from
Jan 18, 2024
Merged

Add closure taking write API #75

merged 2 commits into from
Jan 18, 2024

Conversation

rauhul
Copy link
Collaborator

@rauhul rauhul commented Jan 18, 2024

Improves the ergonomics of writing to Registers with a new write method taking a builder closure.

Instead of requiring users to form a write value with following clunky dance:

var w = Foo.Write(Foo.Raw(0))
w.x = 1
w.y = true
foo.write(w)

The new write<T>(_: (inout Value.Write) -> (T)) -> T method allows them to use the following pattern:

foo.write { w in
  w.x = 1
  w.y = true
}

Fixes #66

Improves the ergonomics of writing to Registers with a new write method
taking a builder closure.

Instead of requiring users to form a write value with following clunky
dance:
``` swift
var w = Foo.Write(Foo.Raw(0))
w.x = 1
w.y = true
foo.write(w)
```

The new `write<T>(_: (inout Value.Write) -> (T)) -> T` method allows
them to use the following pattern:
```swift
foo.write { w in
  w.x = 1
  w.y = true
}
```

Fixes #66
@rauhul rauhul merged commit 1f5f129 into main Jan 18, 2024
@rauhul rauhul deleted the write-closure-api branch January 18, 2024 22:05
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a closure taking Register.write API
1 participant