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 apply and at methods to Sized. #120

Closed
milessabin opened this issue Jun 25, 2014 · 3 comments
Closed

Add apply and at methods to Sized. #120

milessabin opened this issue Jun 25, 2014 · 3 comments

Comments

@milessabin
Copy link
Owner

Sized should have at and apply methods analogous to those on HList: they should yield the _n_th element of the collection iff it has at least n elements. For HLists we have,

scala> val l = 1 :: 2 :: 3 :: 4 :: HNil                                                                                                     
l: shapeless.::[Int,shapeless.::[Int,shapeless.::[Int,shapeless.::[Int,shapeless.HNil]]]] = 1 :: 2 :: 3 :: 4 :: HNil                        

scala> l(0)                                                                                                                                 
res0: Int = 1                                                                                                                               

scala> l(3)
res2: Int = 4                                                                                                                               

scala> l(4)
<console>:15: error: could not find implicit value for parameter at: shapeless.ops.hlist.At[shapeless.::[Int,shapeless.::[Int,shapeless.::[Int,shapeless.::[Int,shapeless.HNil]]]],nat_$macro$4.N]
              l(4)
               ^

The same would be useful for Sized.

@wheaties
Copy link
Contributor

What should the "apply" do in this case? I can see there are already several applies within the companion object itself. Seems like it should just take some collection and use the SizedConv to return an Option. This close to the idea?

@milessabin
Copy link
Owner Author

@wheaties I've added a clearer description of the issue :-)

@milessabin
Copy link
Owner Author

Superseded by #153.

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

No branches or pull requests

2 participants