-
Notifications
You must be signed in to change notification settings - Fork 95
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
added method Flat
#187
added method Flat
#187
Conversation
Flat
& FlatMap
Flat
& FlatMap
v2/of.go
Outdated
@@ -57,6 +57,10 @@ func (o OfSlice[T]) FirstOr(defaultValue T) T { | |||
return FirstOr(o.Result, defaultValue) | |||
} | |||
|
|||
func (o OfSlice[T]) FlatMap(fn func(T) []T) OfSlice[T] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing Flat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flat
works with a 2-dimensional array, I'm not sure it should be part of the OfSlice
type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it should be part of OfSlice
since it deals with slices.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's impossible to add Flat
to the OfSlice
type because Result
is a one-dimensional slice ([]T
) but Flat
works with a two-dimensional slice ([][]T
) so this does not work:
func (o OfSlice[T]) Flat() []T {
return OfSlice[T]{Flat(o.Result)}
}
if you mean another way to add it to the OfSlice
type I'll be thankful for your help
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see what you mean. That's fair - you can leave it out.
v2/of.go
Outdated
@@ -57,6 +57,10 @@ func (o OfSlice[T]) FirstOr(defaultValue T) T { | |||
return FirstOr(o.Result, defaultValue) | |||
} | |||
|
|||
func (o OfSlice[T]) FlatMap(fn func(T) []T) OfSlice[T] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it should be part of OfSlice
since it deals with slices.
No description provided.