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 $isFirst, $isLast #24

Open
brianmhunt opened this issue Jul 15, 2015 · 10 comments
Open

Add $isFirst, $isLast #24

brianmhunt opened this issue Jul 15, 2015 · 10 comments

Comments

@brianmhunt
Copy link
Owner

These can theoretically all be O(1).

@cervengoc
Copy link
Collaborator

What exactly would $atIndex mean?

@brianmhunt
Copy link
Owner Author

@cervengoc A truthy/falsy test e.g. $atIndex(4) returns true if the item is at index 4. I had it in my mind that this could be O(1), but I'm not entirely convinced I'm right. 😁

@cervengoc
Copy link
Collaborator

Well I don't know. At first glance it seems to me that any solution which depends on individual index values other than first or last leads to unavoidable index maintenance in one way or another. And on the other hand, personally I don't like the $atIndex function, I think it's not usable too well and a bit counter-intuitive (one would expect it to be an observable like all others). But that's really kind of a personal preference.

Anyway, please see my comment at the original topic too.

@brianmhunt
Copy link
Owner Author

@cervengoc Yeah, I'm with you. I think it'll just be $isFirst and $isLast

@brianmhunt brianmhunt changed the title Add $isFirst, $isLast and $atIndex Add $isFirst, $isLast Jul 15, 2015
@AdamWillden
Copy link
Contributor

I have just come across a need for isLast but also an isNotLast. Is it worth adding:

  • isNotFirst
  • isNotLast
  • isNotFirstOrLast (a little long and I don't have a need but why not?)

They should all still be O(1) ...or not?

@brianmhunt
Copy link
Owner Author

@AdamWillden They should all be O(1); the isNotLast & isNotFirst are IMHO expressed better as !$isLast and !$isFirst respectively. I.e. there should be no need for property values for these as they can be computed on the fly. At least, that's my thinking. 😄 What do you think?

@IanYates
Copy link

Possibly coming from ignorance, but are $isLast and $isFirst observables or values? If they're observables then !$isLast wouldn't work but !$isLast() would. I see this as being a cousin of KO including both if and ifnot bindings. Is there any drawback to having to evaluate !isLast()

@brianmhunt
Copy link
Owner Author

Thanks @IanYates – Yes, !isLast() is the right syntax. :) It should be an observable (though may in the implementation end up being an opaque defineProperty).

!isLast() ends up being an "implied computed', just as isNotLast would likely be– though with isNotLast there's an extra layer.

I'm not totally averse to adding isNotLast/First, but I don't want to clutter up the API with things that are better written with a simple negation operator.

@AdamWillden
Copy link
Contributor

No problem @brianmhunt. Just floating the idea but what you say makes sense. I think it'd be nicer as an opaque defineProperty

@brianmhunt
Copy link
Owner Author

@AdamWillden Cool. :)

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

No branches or pull requests

4 participants