-
Notifications
You must be signed in to change notification settings - Fork 35
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
Tracking branch for 1.12.x #336
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Now we're using build flags and removed references to the version in the docs. Releasing is just a matter of updating the `VERSION` file and `make release`.
Everything in its own module, and every function has its own test. Should be much easier to locate / navigate stuff.
Splits the array into chunks of the given size: ```bash [1, 2, 3].chunk(2) # [[1, 2], [3]] [1, 2, 3].chunk(10) # [[1,2,3]] [1, 2, 3].chunk(1.2) # argument to chunk must be a positive integer, got '1.2' ```
Checks whether the number is between `min` and `max`: ``` bash 10.between(0, 100) # true 10.between(10, 100) # true 10.between(11, 100) # false ```
Clamps the number between min and max: ``` bash 10.clamp(0, 100) # 10 10.clamp(0, 5) # 5 10.clamp(50, 100) # 50 1.5.clamp(2.5, 3) # 2.5 ```
Converts the string to camelCase: ```bash "a short sentence".camel() # aShortSentence ``` Converts the string to snake_case: ```bash "a short sentence".snake() # a_short_sentence ``` Converts the string to kebab-case: ```bash "a short sentence".snake() # a-short-sentence ```
A shorthand syntax supports passing a hash and comparing elements to the given hash: ```bash [null, {"key": "val", "test": 123}].find({"key": "val"}) # {"key": "val", "test": 123} ```
Computes the intersection between 2 arrays: ```bash [1, 2, 3].intersect([]) # [] [1, 2, 3].intersect([3]) # [3] [1, 2, 3].intersect([3, 1]) # [1, 3] [1, 2, 3].intersect([1, 2, 3, 4]) # [1, 2, 3] ```
Computes the difference between 2 arrays (elements that are only on either of the 2): ```bash [1, 2, 3].diff([]) # [1, 2, 3] [1, 2, 3].diff([3]) # [1, 2] [1, 2, 3].diff([3, 1]) # [2] [1, 2, 3].diff([1, 2, 3, 4]) # [4] ```
Computes the difference between 2 arrays, returning elements that are only on the first array: ```bash [1, 2, 3].diff([]) # [1, 2, 3] [1, 2, 3].diff([3]) # [1, 2] [1, 2, 3].diff([3, 1]) # [2] [1, 2, 3].diff([1, 2, 3, 4]) # [] ``` For symmetric difference see [diff_symmetric(...)](#diff_symmetricarray) Computes the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) between 2 arrays (elements that are only on either of the 2): ```bash [1, 2, 3].diff([]) # [1, 2, 3] [1, 2, 3].diff([3]) # [1, 2] [1, 2, 3].diff([3, 1]) # [2] [1, 2, 3].diff([1, 2, 3, 4]) # [4] ```
Computes the [union](https://en.wikipedia.org/wiki/Union_(set_theory)) between 2 arrays: ```bash [1, 2, 3].union([1, 2, 3, 4]) # [1, 2, 3, 4] [1, 2, 3].union([3]) # [1, 2, 3] [].union([3, 1]) # [3, 1] [1, 2].union([3, 4]) # [1, 2, 3, 4] ```
Flattens an array a single level deep: ```bash [[1, 2], 3, [4]].flatten([1, 2, 3, 4]) # [1, 2, 3, 4] [[1, 2, 3, 4]].flatten([1, 2, 3, 4]) # [1, 2, 3, 4] ```
Flattens an array recursively until no member is an array: ```py [[[1, 2], [[[[3]]]], [4]]].flatten_deep() # [1, 2, 3, 4] [[1, [2, 3], 4]].flatten_deep() # [1, 2, 3, 4] ```
```py [].max() # NULL [0, 5, -10, 100].max() # 100 ```
Finds the lowest number in an array: ```py [].min() # NULL [0, 5, -10, 100].min() # -10 ```
Reduces the array to a value by iterating through its elements and applying `fn` to them: ```py [1, 2, 3, 4].reduce(f(value, element) { return value + element }, 0) # 10 [1, 2, 3, 4].reduce(f(value, element) { return value + element }, 10) # 20 ```
Partitions the array by applying `fn` to all of its elements: ```py f odd(n) { return !!(n % 2) } [0, 1, 2, 3, 4, 5].partition(odd) # [[0, 2, 4], [1, 3, 5]] [1, "1", {}].partition(str) # [[1, "1"], [{}]] ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
/cc @abs-lang/contributors