From 947bcada60f7b71756a55353ba959e72375b8619 Mon Sep 17 00:00:00 2001 From: mariusor Date: Wed, 23 Mar 2022 16:19:40 +0100 Subject: [PATCH] Improve Flatten function for collections and items --- flatten.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/flatten.go b/flatten.go index 66c5828..b758424 100644 --- a/flatten.go +++ b/flatten.go @@ -111,18 +111,17 @@ func FlattenProperties(it Item) Item { 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 { if IsNil(it) { return nil } if it.IsCollection() { - if c, ok := it.(CollectionInterface); ok { + OnCollectionIntf(it, func(c CollectionInterface) error { it = FlattenItemCollection(c.Collection()).Normalize() - } + return nil + }) + return it } - if len(it.GetLink()) > 0 { - return it.GetLink() - } - return it + return it.GetLink() }