Originally created by @ZackarySantana on GitHub (Feb 11, 2024).
Currently, I use this utility function to find the difference A - B
// listDifference gets the elements in A that are not in B.
function listDifference(A: List<Any>, B: List<Any>): List<Any> = A.filter((s) -> !B.contains(s))
It would be a nice to have to be able to do A.difference(B) and have the same resulting list.
I read the contributing to implement this myself but I don't think there's enough docs to do so. I noticed that external (built-in) types (like lists) often have an external modifier for example, and in the docs it doesn't say how that links to anything.
Originally created by @ZackarySantana on GitHub (Feb 11, 2024).
Currently, I use this utility function to find the difference A - B
```
// listDifference gets the elements in A that are not in B.
function listDifference(A: List<Any>, B: List<Any>): List<Any> = A.filter((s) -> !B.contains(s))
```
It would be a nice to have to be able to do A.difference(B) and have the same resulting list.
I read the contributing to implement this myself but I don't think there's enough docs to do so. I noticed that external (built-in) types (like lists) often have an external modifier for example, and in the docs it doesn't say how that links to anything.
@bioball commented on GitHub (Feb 13, 2024):
Fair enough; seems sensible to have this.
FYI: our `Set` API does have a `difference`:
```groovy
s1: Set<Int> = Set(1, 2, 3)
s2: Set<Int> = Set(2, 3, 4)
s3 = s1.difference(s2)
```
Feel free to submit a PR! Take a look at [ListNodes.java](https://github.com/apple/pkl/blob/main/pkl-core/src/main/java/org/pkl/core/stdlib/base/ListNodes.java) for where our List methods are implemented.
You will also need to add tests here: https://github.com/apple/pkl/blob/main/pkl-core/src/test/files/LanguageSnippetTests/input/api/list.pkl.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @ZackarySantana on GitHub (Feb 11, 2024).
Currently, I use this utility function to find the difference A - B
It would be a nice to have to be able to do A.difference(B) and have the same resulting list.
I read the contributing to implement this myself but I don't think there's enough docs to do so. I noticed that external (built-in) types (like lists) often have an external modifier for example, and in the docs it doesn't say how that links to anything.
@bioball commented on GitHub (Feb 13, 2024):
Fair enough; seems sensible to have this.
FYI: our
SetAPI does have adifference:Feel free to submit a PR! Take a look at ListNodes.java for where our List methods are implemented.
You will also need to add tests here: https://github.com/apple/pkl/blob/main/pkl-core/src/test/files/LanguageSnippetTests/input/api/list.pkl.