-
Notifications
You must be signed in to change notification settings - Fork 19
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
MapFactory.iterate #126
Comments
These methods are more difficult to argue for their inclusion but they are still useful (names could be improved): extension [CC[_, _]](factory: MapFactory[CC])
def iterateKey[A, K](iterable: IterableOnce[A])(key: A => K): CC[K, A] =
iterate(iterable)(e => (key(e), e))
def iterateValue[A, V](iterable: IterableOnce[A])(value: A => V): CC[A, V] =
iterate(iterable)(e => (e, value(e))) |
You can use
Does this have some drawbacks for you? |
In terms of performance no, but in terms of readability and consistency with the IterableFactory yes. I find it easier to read:
Mainly because the intention of creating a map is in the beginning of the code, and the cognitive load of reading the code is smaller. |
Those are indeed very handy. I've added those to my small homegrown lib. https://github.com/jozic/scalax-collection#maptomap https://github.com/jozic/scalax-collection#tomapwithkey https://github.com/jozic/scalax-collection#tomapwithvalue But if they appear in this lib, i will happily switch. |
I'm constantly doing (or variations of):
Which is annoying since I'm allocating an intermediate list when I would prefer to build the map directly.
A method like this could be added to MapFactory:
(Feel free to bike shed the names/implementation)
Currently IterableFactory has some very good utility methods to construct iterables such as
fill
,iterate
,range
, andtabulate
. MapFactory on the other hand has nothing.The text was updated successfully, but these errors were encountered: