Skip to content

Commit 24a1c26

Browse files
committed
Update the MapSetDef protocols(use SetDef interface{})
1 parent bb7acc9 commit 24a1c26

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

stream.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ func (streamSelf *StreamDef[T]) Get(i int) T {
243243

244244
// Set
245245

246-
/*
247246
// SetDef Set inspired by Collection utils
248247
type SetDef[T comparable, R comparable] interface {
249248
MapKey(fn TransformerFunctor[T, T]) SetDef[T, R]
@@ -267,7 +266,6 @@ type SetDef[T comparable, R comparable] interface {
267266
AsMap() map[T]R
268267
AsMapSet() *MapSetDef[T, R]
269268
}
270-
*/
271269

272270
// MapSetDef Set inspired by Collection utils
273271
type MapSetDef[T comparable, R comparable] map[T]R
@@ -300,7 +298,7 @@ func SetFromArrayInterface(list []interface{}) *MapSetDef[interface{}, interface
300298
}
301299

302300
// MapKey Map all keys of Set by function
303-
func (mapSetSelf *MapSetDef[T, R]) MapKey(fn TransformerFunctor[T, T]) *MapSetDef[T, R] {
301+
func (mapSetSelf *MapSetDef[T, R]) MapKey(fn TransformerFunctor[T, T]) SetDef[T, R] {
304302
result := make(MapSetDef[T, R], len(*mapSetSelf))
305303
for k, v := range *mapSetSelf {
306304
result[fn(k)] = v
@@ -310,7 +308,7 @@ func (mapSetSelf *MapSetDef[T, R]) MapKey(fn TransformerFunctor[T, T]) *MapSetDe
310308
}
311309

312310
// MapValue Map all values of Set by function
313-
func (mapSetSelf *MapSetDef[T, R]) MapValue(fn TransformerFunctor[R, R]) *MapSetDef[T, R] {
311+
func (mapSetSelf *MapSetDef[T, R]) MapValue(fn TransformerFunctor[R, R]) SetDef[T, R] {
314312
result := make(MapSetDef[T, R], len(*mapSetSelf))
315313
for k, v := range *mapSetSelf {
316314
result[k] = fn(v)
@@ -336,17 +334,17 @@ func (mapSetSelf *MapSetDef[T, R]) ContainsValue(input R) bool {
336334
}
337335

338336
// IsSubsetByKey returns true or false by checking if set1 is a subset of set2
339-
func (mapSetSelf *MapSetDef[T, R]) IsSubsetByKey(input *MapSetDef[T, R]) bool {
337+
func (mapSetSelf *MapSetDef[T, R]) IsSubsetByKey(input SetDef[T, R]) bool {
340338
return IsSubsetMapByKey(*mapSetSelf, input.AsMap())
341339
}
342340

343341
// IsSupersetByKey returns true or false by checking if set1 is a superset of set2
344-
func (mapSetSelf *MapSetDef[T, R]) IsSupersetByKey(input *MapSetDef[T, R]) bool {
342+
func (mapSetSelf *MapSetDef[T, R]) IsSupersetByKey(input SetDef[T, R]) bool {
345343
return IsSupersetMapByKey(*mapSetSelf, input.AsMap())
346344
}
347345

348346
// Add Add items into the Set
349-
func (mapSetSelf *MapSetDef[T, R]) Add(input ...T) *MapSetDef[T, R] {
347+
func (mapSetSelf *MapSetDef[T, R]) Add(input ...T) SetDef[T, R] {
350348
inputLen := len(input)
351349
if inputLen > 0 {
352350
result := mapSetSelf.Clone()
@@ -364,7 +362,7 @@ func (mapSetSelf *MapSetDef[T, R]) Add(input ...T) *MapSetDef[T, R] {
364362
}
365363

366364
// RemoveKeys Remove keys from the Set
367-
func (mapSetSelf *MapSetDef[T, R]) RemoveKeys(input ...T) *MapSetDef[T, R] {
365+
func (mapSetSelf *MapSetDef[T, R]) RemoveKeys(input ...T) SetDef[T, R] {
368366
inputLen := len(input)
369367
if inputLen > 0 {
370368
result := mapSetSelf.Clone()
@@ -379,7 +377,7 @@ func (mapSetSelf *MapSetDef[T, R]) RemoveKeys(input ...T) *MapSetDef[T, R] {
379377
}
380378

381379
// RemoveValues Remove values from the Set
382-
func (mapSetSelf *MapSetDef[T, R]) RemoveValues(input ...R) *MapSetDef[T, R] {
380+
func (mapSetSelf *MapSetDef[T, R]) RemoveValues(input ...R) SetDef[T, R] {
383381
inputLen := len(input)
384382
if inputLen > 0 {
385383
result := mapSetSelf.Clone()
@@ -409,14 +407,14 @@ func (mapSetSelf *MapSetDef[T, R]) Set(key T, value R) {
409407
}
410408

411409
// Clone Clone this Set
412-
func (mapSetSelf *MapSetDef[T, R]) Clone() *MapSetDef[T, R] {
410+
func (mapSetSelf *MapSetDef[T, R]) Clone() SetDef[T, R] {
413411
result := MapSetDef[T, R](DuplicateMap[T, R](*mapSetSelf))
414412

415413
return &result
416414
}
417415

418416
// Union Union an another Set object
419-
func (mapSetSelf *MapSetDef[T, R]) Union(input *MapSetDef[T, R]) *MapSetDef[T, R] {
417+
func (mapSetSelf *MapSetDef[T, R]) Union(input SetDef[T, R]) SetDef[T, R] {
420418
if input == nil || input.Size() == 0 {
421419
return mapSetSelf
422420
}
@@ -427,7 +425,7 @@ func (mapSetSelf *MapSetDef[T, R]) Union(input *MapSetDef[T, R]) *MapSetDef[T, R
427425
}
428426

429427
// Intersection Get the Intersection with this Set and an another Set
430-
func (mapSetSelf *MapSetDef[T, R]) Intersection(input *MapSetDef[T, R]) *MapSetDef[T, R] {
428+
func (mapSetSelf *MapSetDef[T, R]) Intersection(input SetDef[T, R]) SetDef[T, R] {
431429
if input == nil || input.Size() == 0 {
432430
return new(MapSetDef[T, R])
433431
}
@@ -438,7 +436,7 @@ func (mapSetSelf *MapSetDef[T, R]) Intersection(input *MapSetDef[T, R]) *MapSetD
438436
}
439437

440438
// Minus Get all of this Set but not in the given Set
441-
func (mapSetSelf *MapSetDef[T, R]) Minus(input *MapSetDef[T, R]) *MapSetDef[T, R] {
439+
func (mapSetSelf *MapSetDef[T, R]) Minus(input SetDef[T, R]) SetDef[T, R] {
442440
if input == nil || input.Size() == 0 {
443441
return mapSetSelf
444442
}

0 commit comments

Comments
 (0)