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

core-common: AttributeKey add maybe method #780

Merged

Conversation

iRevive
Copy link
Contributor

@iRevive iRevive commented Sep 14, 2024

Resolves #2 (in some way).

Motivation

Adding optional attribute values is rather verbose. To make these operations more bearable, we can allow passing optional values.

@iRevive
Copy link
Contributor Author

iRevive commented Sep 14, 2024

@NthPortal what do you think?

@iRevive iRevive force-pushed the core-common/attributes-builder-option branch from 6ea416c to 3f74d63 Compare September 14, 2024 19:37
@NthPortal
Copy link
Contributor

NthPortal commented Sep 16, 2024

I was all set to dismiss this by saying "Option is IterableOnce, so you can just use concat/addAll", but that doesn't solve the case where you have Option[T] rather than Option[Attribute[T]].

on the other hand, should we actually be encouraging the key/value methods? at the very least, I don't think we should be adding additional methods with String key names, but I have a harder time arguing against (AttributeKey[T], Option[T]).

I will have to ponder this some more

@NthPortal
Copy link
Contributor

there's part of me that thinks it would be cleaner to add a single method to AttributeKey to complement apply, such as

trait AttributeKey[T] {
  // ...
  final def maybe(value: Option[T]): Option[Attribute[T]] =
    value.map(apply)
}

@iRevive
Copy link
Contributor Author

iRevive commented Sep 18, 2024

there's part of me that thinks it would be cleaner to add a single method to AttributeKey to complement apply, such as

trait AttributeKey[T] {
  // ...
  final def maybe(value: Option[T]): Option[Attribute[T]] =
    value.map(apply)
}

Brilliant idea. It's much better than the bunch of overloaded methods.

@iRevive iRevive force-pushed the core-common/attributes-builder-option branch from 3f74d63 to adf07bd Compare September 18, 2024 08:50
@iRevive iRevive changed the title core-common: Attributes provide overloaded addOne and added core-common: AttributeKey add maybe method Sep 18, 2024
@iRevive iRevive force-pushed the core-common/attributes-builder-option branch from adf07bd to 3afae11 Compare September 22, 2024 08:22
Copy link
Contributor

@NthPortal NthPortal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, thought I approved this last week

@iRevive iRevive merged commit 16fdfc5 into typelevel:main Sep 24, 2024
10 checks passed
@iRevive iRevive deleted the core-common/attributes-builder-option branch September 24, 2024 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional attributes
2 participants