Skip to content

Commit

Permalink
Remove unnecessary fold in RelExclude
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 committed Jan 13, 2024
1 parent 3be4a5e commit 596a429
Showing 1 changed file with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,21 @@ internal class RelExclude(
input.open()
}

@OptIn(PartiQLValueExperimental::class)
override fun next(): Record? {
val record = input.next() ?: return null
return exclusions.fold(record) { rec, path -> exclude(rec, path) }
exclusions.forEach { path ->
val root = path.root.ref
val value = record.values[root]
record.values[root] = exclude(value, path.steps)
}
return record
}

override fun close() {
input.close()
}

@OptIn(PartiQLValueExperimental::class)
private fun exclude(
record: Record,
path: Rel.Op.Exclude.Path
): Record {
val values = record.values
val value = values.getOrNull(path.root.ref)
val newValues = if (value != null) {
values[path.root.ref] = exclude(value, path.steps)
values
} else {
values
}
return Record(newValues)
}

@OptIn(PartiQLValueExperimental::class)
private fun exclude(
structValue: StructValue<*>,
Expand Down

0 comments on commit 596a429

Please sign in to comment.