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

Allow to list all enumeration indices and values #4

Closed
pedrorijo91 opened this Issue Nov 24, 2016 · 14 comments

Comments

Projects
None yet
3 participants
@pedrorijo91

pedrorijo91 commented Nov 24, 2016

Similar to scala.Enumeration#values it could be interesting to find a way to return all possible values from an ItemizedEnum


Still wip:

  • consider similar functionality for ItemizedCodec
  • write docs
@utaal

This comment has been minimized.

Show comment
Hide comment
@utaal

utaal Nov 25, 2016

Contributor

Hey, thank you for the PR! I've seen this done by other libraries, but I'm not yet sure what are the use cases, and I'm really committed to keeping this as small as possible. Can you share your use case for this?

Contributor

utaal commented Nov 25, 2016

Hey, thank you for the PR! I've seen this done by other libraries, but I'm not yet sure what are the use cases, and I'm really committed to keeping this as small as possible. Can you share your use case for this?

@esarbe

This comment has been minimized.

Show comment
Hide comment
@esarbe

esarbe Nov 25, 2016

Contributor

Hey @utaal, I've got a use case. I'm generating random instances of enumeration objects. To do that I need a set of all the possible values for a given enum type, so that I can select one of them.

Contributor

esarbe commented Nov 25, 2016

Hey @utaal, I've got a use case. I'm generating random instances of enumeration objects. To do that I need a set of all the possible values for a given enum type, so that I can select one of them.

@utaal

This comment has been minimized.

Show comment
Hide comment
@utaal

utaal Nov 25, 2016

Contributor

Makes sense. Are you using scalacheck?

Contributor

utaal commented Nov 25, 2016

Makes sense. Are you using scalacheck?

@esarbe

This comment has been minimized.

Show comment
Hide comment
@esarbe

esarbe Nov 25, 2016

Contributor

No, actually. I'm playing with generative algorithms and need a way to explore the state-space.

Contributor

esarbe commented Nov 25, 2016

No, actually. I'm playing with generative algorithms and need a way to explore the state-space.

@pedrorijo91

This comment has been minimized.

Show comment
Hide comment
@pedrorijo91

pedrorijo91 Nov 25, 2016

I personally don't have any use case (yet), but it was a disadvantage I noticed when comparing to using the scala.Enumeration. If you (and others) think it doesn't make sense to add it feel free to close the issue. But I think it may be useful for someone, specially to ease migrations between scala.Enumeration and Itemized in a first phase.

pedrorijo91 commented Nov 25, 2016

I personally don't have any use case (yet), but it was a disadvantage I noticed when comparing to using the scala.Enumeration. If you (and others) think it doesn't make sense to add it feel free to close the issue. But I think it may be useful for someone, specially to ease migrations between scala.Enumeration and Itemized in a first phase.

@utaal

This comment has been minimized.

Show comment
Hide comment
@utaal

utaal Nov 25, 2016

Contributor

Thank you both for taking the time to answer. I agree it's worthwhile, but I'd like to see whether it warrants a small refactor (so we can also support scalacheck and similar libraries): in particular, it probably does not belong in ItemizedCodec but should be in a separate typeclass. @esarbe if you don't mind, I'd like to try and work on top of your PR branch.

Contributor

utaal commented Nov 25, 2016

Thank you both for taking the time to answer. I agree it's worthwhile, but I'd like to see whether it warrants a small refactor (so we can also support scalacheck and similar libraries): in particular, it probably does not belong in ItemizedCodec but should be in a separate typeclass. @esarbe if you don't mind, I'd like to try and work on top of your PR branch.

@esarbe

This comment has been minimized.

Show comment
Hide comment
@esarbe

esarbe Nov 25, 2016

Contributor

@utaal Sure, go ahead! If I can be of any help, just let me know. :D

Contributor

esarbe commented Nov 25, 2016

@utaal Sure, go ahead! If I can be of any help, just let me know. :D

@utaal utaal changed the title from Allow to list all enumeration values to Allow to list all enumeration indices and values Nov 25, 2016

@utaal utaal added the enhancement label Nov 25, 2016

@utaal utaal added this to the 0.2.0 milestone Nov 25, 2016

@utaal

This comment has been minimized.

Show comment
Hide comment
@utaal

utaal Nov 25, 2016

Contributor

Ok, I've merged @esarbe's PR with my modifications.
You can use ItemizedIndex.indexMap to get a Map[T#Index, T] map of (index -> value)s.

Snapshot published:

"io.rbricks" %% "itemized" % "0.2-SNAPSHOT"

Let's try it out, once we're satisfied, I'll release 0.2.0 (possibly with something similar for IndexedCodec).

I'll keep this open in the meantime.

Side-note: the fact that you can allow maintainers to push on PR branches is very neat.

cc/ @esarbe, @pedrorijo91

Contributor

utaal commented Nov 25, 2016

Ok, I've merged @esarbe's PR with my modifications.
You can use ItemizedIndex.indexMap to get a Map[T#Index, T] map of (index -> value)s.

Snapshot published:

"io.rbricks" %% "itemized" % "0.2-SNAPSHOT"

Let's try it out, once we're satisfied, I'll release 0.2.0 (possibly with something similar for IndexedCodec).

I'll keep this open in the meantime.

Side-note: the fact that you can allow maintainers to push on PR branches is very neat.

cc/ @esarbe, @pedrorijo91

@pedrorijo91

This comment has been minimized.

Show comment
Hide comment
@pedrorijo91

pedrorijo91 Nov 26, 2016

getting an sbt.ResolveException: unresolved dependency: io.rbricks#itemized_2.11;0.2-SNAPSHOT: not found

it doesn't seem to be published on maven central either: http://search.maven.org/#search%7Cga%7C1%7Citemized

(solved by publishing locally: sbt +publishLocal)

pedrorijo91 commented Nov 26, 2016

getting an sbt.ResolveException: unresolved dependency: io.rbricks#itemized_2.11;0.2-SNAPSHOT: not found

it doesn't seem to be published on maven central either: http://search.maven.org/#search%7Cga%7C1%7Citemized

(solved by publishing locally: sbt +publishLocal)

@pedrorijo91

This comment has been minimized.

Show comment
Hide comment
@pedrorijo91

pedrorijo91 Nov 26, 2016

i've only now noticed that the new method only works for indexedEnums. Why don't simple enums support a similar method ?

pedrorijo91 commented Nov 26, 2016

i've only now noticed that the new method only works for indexedEnums. Why don't simple enums support a similar method ?

@utaal

This comment has been minimized.

Show comment
Hide comment
@utaal

utaal Nov 26, 2016

Contributor

@pedrorijo91 the snapshots are published in the sonatype snapshot repo; add

resolvers += Resolver.sonatypeRepo("snapshots")

to build.sbt.

Contributor

utaal commented Nov 26, 2016

@pedrorijo91 the snapshots are published in the sonatype snapshot repo; add

resolvers += Resolver.sonatypeRepo("snapshots")

to build.sbt.

@utaal

This comment has been minimized.

Show comment
Hide comment
@utaal

utaal Nov 26, 2016

Contributor

Regarding support for IndexedEnum, I'm taking a look on how to do it cleanly: suggestions welcome!

Contributor

utaal commented Nov 26, 2016

Regarding support for IndexedEnum, I'm taking a look on how to do it cleanly: suggestions welcome!

@utaal

This comment has been minimized.

Show comment
Hide comment
@utaal

utaal Nov 26, 2016

Contributor

@pedrorijo91 here's the current plan #9
You can get to all values with stringMap.values and to all string encodings with stringMap.keys.
Would something like this work for you?

Contributor

utaal commented Nov 26, 2016

@pedrorijo91 here's the current plan #9
You can get to all values with stringMap.values and to all string encodings with stringMap.keys.
Would something like this work for you?

@pedrorijo91

This comment has been minimized.

Show comment
Hide comment
@pedrorijo91

pedrorijo91 Nov 26, 2016

yes, it seems to do the work :)

pedrorijo91 commented Nov 26, 2016

yes, it seems to do the work :)

@utaal utaal closed this Jul 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment