Skip to content

Commit

Permalink
#67 Add orEmpty, isEmpty implements
Browse files Browse the repository at this point in the history
  • Loading branch information
meian committed Jan 29, 2022
1 parent 456acc5 commit 75d9070
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions empty.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ func empty[T any]() Iterable[T] {
return emptyIterable[T]{}
}

func orEmpty[T any](itb Iterable[T]) Iterable[T] {
if itb == nil {
return empty[T]()
}
return itb
}

func isEmpty[T any](itb Iterable[T]) bool {
if itb == nil {
return true
}
_, ok := itb.(emptyIterable[T])
return ok
}

func (itb emptyIterable[T]) Iterator() Iterator[T] {
return emptyIter[T]()
}
Expand Down

0 comments on commit 75d9070

Please sign in to comment.