Skip to content

Instantly share code, notes, and snippets.

@apstndb
Last active April 19, 2020 06:10
Show Gist options
  • Save apstndb/32e20316081cefd1568fe9ca016be082 to your computer and use it in GitHub Desktop.
Save apstndb/32e20316081cefd1568fe9ca016be082 to your computer and use it in GitHub Desktop.
import "list"
a: [{id: 1}, {id: 2}]
b: [{id: 1}, {id: 1}]
c: [{id: 1}, {id: 2}, {id: 2}]
a_ids:: [x.id for x in a]
a_unique: list.UniqueItems(a_ids)
unique :: {
input : _
output : list.UniqueItems([x.id for x in input])
}
b_unique : (unique & {input: b}).output
c_unique : (unique & {input: c}).output
import "list"
a: [{id: 1}, {id: 2}]
b: [{id: 1}, {id: 2}, {id: 2}]
func1:: {input: _, output: _}
unique_by:: {
f: func1
input: _
output: list.UniqueItems([(f & {input: x}).output for x in input])
}
get_id:: func1 & {
input: _
output: input.id
}
a_unique : (unique_by & {input: a, f: get_id}).output
b_unique : (unique_by & {input: b, f: get_id}).output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment