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

Tracking branch for 1.12.x #336

Merged
merged 20 commits into from
Mar 30, 2020
Merged

Tracking branch for 1.12.x #336

merged 20 commits into from
Mar 30, 2020

Conversation

odino
Copy link
Collaborator

@odino odino commented Mar 23, 2020

/cc @abs-lang/contributors

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`.
@odino odino added this to the 1.12.x milestone Mar 23, 2020
odino added 19 commits March 24, 2020 03:14
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"], [{}]]
```
@odino odino merged commit 3ddbae2 into master Mar 30, 2020
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.

None yet

1 participant