Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add a closure taking Register.write API #66

Closed
rauhul opened this issue Jan 12, 2024 · 0 comments · Fixed by #75
Closed

Add a closure taking Register.write API #66

rauhul opened this issue Jan 12, 2024 · 0 comments · Fixed by #75
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@rauhul
Copy link
Collaborator

rauhul commented Jan 12, 2024

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

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

Provide an api which takes a closure with an inout w and performs the write after the closure completes. This makes write as ergonomic as modify. It can also be extended with a parameter on how to form the initial value to be written.

foo.write { w in
  w.x = 1
  w.y = true
}
@rauhul rauhul added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Jan 12, 2024
@rauhul rauhul added this to the 0.0.2 milestone Jan 12, 2024
rauhul added a commit that referenced this issue 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:
``` 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 added a commit that referenced this issue 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:
``` 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant