-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Remove filter depth limit (#777)
* Remove deprecated test file It is dependent on package internals and function signatures upon which it relies upon will soon be modified and deleted * Add enumerable.concat * Add enumerable.select * Add enumerable.tryGetFirst * Refactor schema intergration tests Should further improve dev-ex when adding and maintaining schema integration tests. * Make mapping.Children slice of pointers Original struct setup starts to cause issues when the items in the slice need to be mutated * Remove depth restriction in filter clause
- Loading branch information
1 parent
5448e25
commit b9116bc
Showing
12 changed files
with
870 additions
and
1,300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package enumerable | ||
|
||
type enumerableConcat[T any] struct { | ||
sources []Enumerable[T] | ||
currentSourceIndex int | ||
} | ||
|
||
// Concat takes zero to many source `Ènumerable`s and stacks them on top | ||
// of each other, resulting in one enumerable that will iterate through all | ||
// the values in all of the given sources. | ||
func Concat[T any](sources ...Enumerable[T]) Enumerable[T] { | ||
return &enumerableConcat[T]{ | ||
sources: sources, | ||
currentSourceIndex: 0, | ||
} | ||
} | ||
|
||
func (s *enumerableConcat[T]) Next() (bool, error) { | ||
for { | ||
if s.currentSourceIndex >= len(s.sources) { | ||
return false, nil | ||
} | ||
|
||
currentSource := s.sources[s.currentSourceIndex] | ||
hasValue, err := currentSource.Next() | ||
if err != nil { | ||
return false, nil | ||
} | ||
if hasValue { | ||
return true, nil | ||
} | ||
|
||
s.currentSourceIndex += 1 | ||
} | ||
} | ||
|
||
func (s *enumerableConcat[T]) Value() T { | ||
return s.sources[s.currentSourceIndex].Value() | ||
} | ||
|
||
func (s *enumerableConcat[T]) Reset() { | ||
s.currentSourceIndex = 0 | ||
for _, source := range s.sources { | ||
source.Reset() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2022 Democratized Data Foundation | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package enumerable | ||
|
||
type enumerableSelect[TSource any, TResult any] struct { | ||
source Enumerable[TSource] | ||
selector func(TSource) (TResult, error) | ||
currentValue TResult | ||
} | ||
|
||
// Select creates a new `Enumerable` that iterates through each item | ||
// yielded by the given source and then yields the value returned by | ||
// the given selector. | ||
func Select[TSource any, TResult any]( | ||
source Enumerable[TSource], | ||
selector func(TSource) (TResult, error), | ||
) Enumerable[TResult] { | ||
return &enumerableSelect[TSource, TResult]{ | ||
source: source, | ||
selector: selector, | ||
} | ||
} | ||
|
||
func (s *enumerableSelect[TSource, TResult]) Next() (bool, error) { | ||
hasNext, err := s.source.Next() | ||
if !hasNext || err != nil { | ||
return hasNext, err | ||
} | ||
|
||
value := s.source.Value() | ||
// We do this here to keep the work (and errors) in the `Next` call | ||
result, err := s.selector(value) | ||
if err != nil { | ||
return false, nil | ||
} | ||
|
||
s.currentValue = result | ||
return true, nil | ||
} | ||
|
||
func (s *enumerableSelect[TSource, TResult]) Value() TResult { | ||
return s.currentValue | ||
} | ||
|
||
func (s *enumerableSelect[TSource, TResult]) Reset() { | ||
s.source.Reset() | ||
} |
Oops, something went wrong.