Improve Flatten function for collections and items
This commit is contained in:
parent
fd7ce7b1fb
commit
947bcada60
13
flatten.go
13
flatten.go
|
@ -111,18 +111,17 @@ func FlattenProperties(it Item) Item {
|
||||||
return it
|
return it
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flatten checks if Item can be flatten to an IRI or array of IRIs and returns it if so
|
// Flatten checks if Item can be flattened to an IRI or array of IRIs and returns it if so
|
||||||
func Flatten(it Item) Item {
|
func Flatten(it Item) Item {
|
||||||
if IsNil(it) {
|
if IsNil(it) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if it.IsCollection() {
|
if it.IsCollection() {
|
||||||
if c, ok := it.(CollectionInterface); ok {
|
OnCollectionIntf(it, func(c CollectionInterface) error {
|
||||||
it = FlattenItemCollection(c.Collection()).Normalize()
|
it = FlattenItemCollection(c.Collection()).Normalize()
|
||||||
}
|
return nil
|
||||||
}
|
})
|
||||||
if len(it.GetLink()) > 0 {
|
|
||||||
return it.GetLink()
|
|
||||||
}
|
|
||||||
return it
|
return it
|
||||||
|
}
|
||||||
|
return it.GetLink()
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue