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 functions to Collection #25

Merged
merged 7 commits into from
Jan 8, 2024

Conversation

Bl00D4NGEL
Copy link
Collaborator

@Bl00D4NGEL Bl00D4NGEL commented Jan 5, 2024

This PR introduces a couple of useful functions to the Collection class.

The introduced functions are:

  • fromIterable - enables users of the collection to construction the collection from an iterable value like iterators, generators, etc.
  • every - Returns true if given callback returns truthy values for all items
  • none - Returns true if given callback returns falsy values for all items
  • some - Returns true if given callback returns truthy values on some items
  • first - Get the first element of the collection that matches a callback, if given. Throws exception if collection is empty or predicate is never satisfied
  • firstOr - Same as first but returns $fallbackValue if collection is empty or predicate is never satisfied
  • last - Get the last element of the collection that matches a callback, if given. Throws exception if collection is empty or predicate is never satisfied
  • lastOr - Same as last but returns $fallbackValue if collection is empty or predicate is never satisfied
  • isEmpty - Returns whether the collection is empty
  • hasItems - Returns whether the collection has items

CHANGELOG.md Outdated Show resolved Hide resolved
@janvt janvt merged commit 0e573c8 into geekcell:main Jan 8, 2024
1 check failed
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

Successfully merging this pull request may close these issues.

3 participants