7a04f298d2
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
744 lines
18 KiB
Go
744 lines
18 KiB
Go
//go:build !no_gotd_slices
|
|
// +build !no_gotd_slices
|
|
|
|
// Code generated by gotdgen, DO NOT EDIT.
|
|
|
|
package tg
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
|
|
"go.uber.org/multierr"
|
|
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/tdjson"
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/tdp"
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
|
|
)
|
|
|
|
// No-op definition for keeping imports.
|
|
var (
|
|
_ = bin.Buffer{}
|
|
_ = context.Background()
|
|
_ = fmt.Stringer(nil)
|
|
_ = strings.Builder{}
|
|
_ = errors.Is
|
|
_ = multierr.AppendInto
|
|
_ = sort.Ints
|
|
_ = tdp.Format
|
|
_ = tgerr.Error{}
|
|
_ = tdjson.Encoder{}
|
|
)
|
|
|
|
// ChannelParticipantClassArray is adapter for slice of ChannelParticipantClass.
|
|
type ChannelParticipantClassArray []ChannelParticipantClass
|
|
|
|
// Sort sorts slice of ChannelParticipantClass.
|
|
func (s ChannelParticipantClassArray) Sort(less func(a, b ChannelParticipantClass) bool) ChannelParticipantClassArray {
|
|
sort.Slice(s, func(i, j int) bool {
|
|
return less(s[i], s[j])
|
|
})
|
|
return s
|
|
}
|
|
|
|
// SortStable sorts slice of ChannelParticipantClass.
|
|
func (s ChannelParticipantClassArray) SortStable(less func(a, b ChannelParticipantClass) bool) ChannelParticipantClassArray {
|
|
sort.SliceStable(s, func(i, j int) bool {
|
|
return less(s[i], s[j])
|
|
})
|
|
return s
|
|
}
|
|
|
|
// Retain filters in-place slice of ChannelParticipantClass.
|
|
func (s ChannelParticipantClassArray) Retain(keep func(x ChannelParticipantClass) bool) ChannelParticipantClassArray {
|
|
n := 0
|
|
for _, x := range s {
|
|
if keep(x) {
|
|
s[n] = x
|
|
n++
|
|
}
|
|
}
|
|
s = s[:n]
|
|
|
|
return s
|
|
}
|
|
|
|
// First returns first element of slice (if exists).
|
|
func (s ChannelParticipantClassArray) First() (v ChannelParticipantClass, ok bool) {
|
|
if len(s) < 1 {
|
|
return
|
|
}
|
|
return s[0], true
|
|
}
|
|
|
|
// Last returns last element of slice (if exists).
|
|
func (s ChannelParticipantClassArray) Last() (v ChannelParticipantClass, ok bool) {
|
|
if len(s) < 1 {
|
|
return
|
|
}
|
|
return s[len(s)-1], true
|
|
}
|
|
|
|
// PopFirst returns first element of slice (if exists) and deletes it.
|
|
func (s *ChannelParticipantClassArray) PopFirst() (v ChannelParticipantClass, ok bool) {
|
|
if s == nil || len(*s) < 1 {
|
|
return
|
|
}
|
|
|
|
a := *s
|
|
v = a[0]
|
|
|
|
// Delete by index from SliceTricks.
|
|
copy(a[0:], a[1:])
|
|
var zero ChannelParticipantClass
|
|
a[len(a)-1] = zero
|
|
a = a[:len(a)-1]
|
|
*s = a
|
|
|
|
return v, true
|
|
}
|
|
|
|
// Pop returns last element of slice (if exists) and deletes it.
|
|
func (s *ChannelParticipantClassArray) Pop() (v ChannelParticipantClass, ok bool) {
|
|
if s == nil || len(*s) < 1 {
|
|
return
|
|
}
|
|
|
|
a := *s
|
|
v = a[len(a)-1]
|
|
a = a[:len(a)-1]
|
|
*s = a
|
|
|
|
return v, true
|
|
}
|
|
|
|
// AsChannelParticipant returns copy with only ChannelParticipant constructors.
|
|
func (s ChannelParticipantClassArray) AsChannelParticipant() (to ChannelParticipantArray) {
|
|
for _, elem := range s {
|
|
value, ok := elem.(*ChannelParticipant)
|
|
if !ok {
|
|
continue
|
|
}
|
|
to = append(to, *value)
|
|
}
|
|
|
|
return to
|
|
}
|
|
|
|
// AsChannelParticipantSelf returns copy with only ChannelParticipantSelf constructors.
|
|
func (s ChannelParticipantClassArray) AsChannelParticipantSelf() (to ChannelParticipantSelfArray) {
|
|
for _, elem := range s {
|
|
value, ok := elem.(*ChannelParticipantSelf)
|
|
if !ok {
|
|
continue
|
|
}
|
|
to = append(to, *value)
|
|
}
|
|
|
|
return to
|
|
}
|
|
|
|
// AsChannelParticipantCreator returns copy with only ChannelParticipantCreator constructors.
|
|
func (s ChannelParticipantClassArray) AsChannelParticipantCreator() (to ChannelParticipantCreatorArray) {
|
|
for _, elem := range s {
|
|
value, ok := elem.(*ChannelParticipantCreator)
|
|
if !ok {
|
|
continue
|
|
}
|
|
to = append(to, *value)
|
|
}
|
|
|
|
return to
|
|
}
|
|
|
|
// AsChannelParticipantAdmin returns copy with only ChannelParticipantAdmin constructors.
|
|
func (s ChannelParticipantClassArray) AsChannelParticipantAdmin() (to ChannelParticipantAdminArray) {
|
|
for _, elem := range s {
|
|
value, ok := elem.(*ChannelParticipantAdmin)
|
|
if !ok {
|
|
continue
|
|
}
|
|
to = append(to, *value)
|
|
}
|
|
|
|
return to
|
|
}
|
|
|
|
// AsChannelParticipantBanned returns copy with only ChannelParticipantBanned constructors.
|
|
func (s ChannelParticipantClassArray) AsChannelParticipantBanned() (to ChannelParticipantBannedArray) {
|
|
for _, elem := range s {
|
|
value, ok := elem.(*ChannelParticipantBanned)
|
|
if !ok {
|
|
continue
|
|
}
|
|
to = append(to, *value)
|
|
}
|
|
|
|
return to
|
|
}
|
|
|
|
// AsChannelParticipantLeft returns copy with only ChannelParticipantLeft constructors.
|
|
func (s ChannelParticipantClassArray) AsChannelParticipantLeft() (to ChannelParticipantLeftArray) {
|
|
for _, elem := range s {
|
|
value, ok := elem.(*ChannelParticipantLeft)
|
|
if !ok {
|
|
continue
|
|
}
|
|
to = append(to, *value)
|
|
}
|
|
|
|
return to
|
|
}
|
|
|
|
// ChannelParticipantArray is adapter for slice of ChannelParticipant.
|
|
type ChannelParticipantArray []ChannelParticipant
|
|
|
|
// Sort sorts slice of ChannelParticipant.
|
|
func (s ChannelParticipantArray) Sort(less func(a, b ChannelParticipant) bool) ChannelParticipantArray {
|
|
sort.Slice(s, func(i, j int) bool {
|
|
return less(s[i], s[j])
|
|
})
|
|
return s
|
|
}
|
|
|
|
// SortStable sorts slice of ChannelParticipant.
|
|
func (s ChannelParticipantArray) SortStable(less func(a, b ChannelParticipant) bool) ChannelParticipantArray {
|
|
sort.SliceStable(s, func(i, j int) bool {
|
|
return less(s[i], s[j])
|
|
})
|
|
return s
|
|
}
|
|
|
|
// Retain filters in-place slice of ChannelParticipant.
|
|
func (s ChannelParticipantArray) Retain(keep func(x ChannelParticipant) bool) ChannelParticipantArray {
|
|
n := 0
|
|
for _, x := range s {
|
|
if keep(x) {
|
|
s[n] = x
|
|
n++
|
|
}
|
|
}
|
|
s = s[:n]
|
|
|
|
return s
|
|
}
|
|
|
|
// First returns first element of slice (if exists).
|
|
func (s ChannelParticipantArray) First() (v ChannelParticipant, ok bool) {
|
|
if len(s) < 1 {
|
|
return
|
|
}
|
|
return s[0], true
|
|
}
|
|
|
|
// Last returns last element of slice (if exists).
|
|
func (s ChannelParticipantArray) Last() (v ChannelParticipant, ok bool) {
|
|
if len(s) < 1 {
|
|
return
|
|
}
|
|
return s[len(s)-1], true
|
|
}
|
|
|
|
// PopFirst returns first element of slice (if exists) and deletes it.
|
|
func (s *ChannelParticipantArray) PopFirst() (v ChannelParticipant, ok bool) {
|
|
if s == nil || len(*s) < 1 {
|
|
return
|
|
}
|
|
|
|
a := *s
|
|
v = a[0]
|
|
|
|
// Delete by index from SliceTricks.
|
|
copy(a[0:], a[1:])
|
|
var zero ChannelParticipant
|
|
a[len(a)-1] = zero
|
|
a = a[:len(a)-1]
|
|
*s = a
|
|
|
|
return v, true
|
|
}
|
|
|
|
// Pop returns last element of slice (if exists) and deletes it.
|
|
func (s *ChannelParticipantArray) Pop() (v ChannelParticipant, ok bool) {
|
|
if s == nil || len(*s) < 1 {
|
|
return
|
|
}
|
|
|
|
a := *s
|
|
v = a[len(a)-1]
|
|
a = a[:len(a)-1]
|
|
*s = a
|
|
|
|
return v, true
|
|
}
|
|
|
|
// SortByDate sorts slice of ChannelParticipant by Date.
|
|
func (s ChannelParticipantArray) SortByDate() ChannelParticipantArray {
|
|
return s.Sort(func(a, b ChannelParticipant) bool {
|
|
return a.GetDate() < b.GetDate()
|
|
})
|
|
}
|
|
|
|
// SortStableByDate sorts slice of ChannelParticipant by Date.
|
|
func (s ChannelParticipantArray) SortStableByDate() ChannelParticipantArray {
|
|
return s.SortStable(func(a, b ChannelParticipant) bool {
|
|
return a.GetDate() < b.GetDate()
|
|
})
|
|
}
|
|
|
|
// ChannelParticipantSelfArray is adapter for slice of ChannelParticipantSelf.
|
|
type ChannelParticipantSelfArray []ChannelParticipantSelf
|
|
|
|
// Sort sorts slice of ChannelParticipantSelf.
|
|
func (s ChannelParticipantSelfArray) Sort(less func(a, b ChannelParticipantSelf) bool) ChannelParticipantSelfArray {
|
|
sort.Slice(s, func(i, j int) bool {
|
|
return less(s[i], s[j])
|
|
})
|
|
return s
|
|
}
|
|
|
|
// SortStable sorts slice of ChannelParticipantSelf.
|
|
func (s ChannelParticipantSelfArray) SortStable(less func(a, b ChannelParticipantSelf) bool) ChannelParticipantSelfArray {
|
|
sort.SliceStable(s, func(i, j int) bool {
|
|
return less(s[i], s[j])
|
|
})
|
|
return s
|
|
}
|
|
|
|
// Retain filters in-place slice of ChannelParticipantSelf.
|
|
func (s ChannelParticipantSelfArray) Retain(keep func(x ChannelParticipantSelf) bool) ChannelParticipantSelfArray {
|
|
n := 0
|
|
for _, x := range s {
|
|
if keep(x) {
|
|
s[n] = x
|
|
n++
|
|
}
|
|
}
|
|
s = s[:n]
|
|
|
|
return s
|
|
}
|
|
|
|
// First returns first element of slice (if exists).
|
|
func (s ChannelParticipantSelfArray) First() (v ChannelParticipantSelf, ok bool) {
|
|
if len(s) < 1 {
|
|
return
|
|
}
|
|
return s[0], true
|
|
}
|
|
|
|
// Last returns last element of slice (if exists).
|
|
func (s ChannelParticipantSelfArray) Last() (v ChannelParticipantSelf, ok bool) {
|
|
if len(s) < 1 {
|
|
return
|
|
}
|
|
return s[len(s)-1], true
|
|
}
|
|
|
|
// PopFirst returns first element of slice (if exists) and deletes it.
|
|
func (s *ChannelParticipantSelfArray) PopFirst() (v ChannelParticipantSelf, ok bool) {
|
|
if s == nil || len(*s) < 1 {
|
|
return
|
|
}
|
|
|
|
a := *s
|
|
v = a[0]
|
|
|
|
// Delete by index from SliceTricks.
|
|
copy(a[0:], a[1:])
|
|
var zero ChannelParticipantSelf
|
|
a[len(a)-1] = zero
|
|
a = a[:len(a)-1]
|
|
*s = a
|
|
|
|
return v, true
|
|
}
|
|
|
|
// Pop returns last element of slice (if exists) and deletes it.
|
|
func (s *ChannelParticipantSelfArray) Pop() (v ChannelParticipantSelf, ok bool) {
|
|
if s == nil || len(*s) < 1 {
|
|
return
|
|
}
|
|
|
|
a := *s
|
|
v = a[len(a)-1]
|
|
a = a[:len(a)-1]
|
|
*s = a
|
|
|
|
return v, true
|
|
}
|
|
|
|
// SortByDate sorts slice of ChannelParticipantSelf by Date.
|
|
func (s ChannelParticipantSelfArray) SortByDate() ChannelParticipantSelfArray {
|
|
return s.Sort(func(a, b ChannelParticipantSelf) bool {
|
|
return a.GetDate() < b.GetDate()
|
|
})
|
|
}
|
|
|
|
// SortStableByDate sorts slice of ChannelParticipantSelf by Date.
|
|
func (s ChannelParticipantSelfArray) SortStableByDate() ChannelParticipantSelfArray {
|
|
return s.SortStable(func(a, b ChannelParticipantSelf) bool {
|
|
return a.GetDate() < b.GetDate()
|
|
})
|
|
}
|
|
|
|
// ChannelParticipantCreatorArray is adapter for slice of ChannelParticipantCreator.
|
|
type ChannelParticipantCreatorArray []ChannelParticipantCreator
|
|
|
|
// Sort sorts slice of ChannelParticipantCreator.
|
|
func (s ChannelParticipantCreatorArray) Sort(less func(a, b ChannelParticipantCreator) bool) ChannelParticipantCreatorArray {
|
|
sort.Slice(s, func(i, j int) bool {
|
|
return less(s[i], s[j])
|
|
})
|
|
return s
|
|
}
|
|
|
|
// SortStable sorts slice of ChannelParticipantCreator.
|
|
func (s ChannelParticipantCreatorArray) SortStable(less func(a, b ChannelParticipantCreator) bool) ChannelParticipantCreatorArray {
|
|
sort.SliceStable(s, func(i, j int) bool {
|
|
return less(s[i], s[j])
|
|
})
|
|
return s
|
|
}
|
|
|
|
// Retain filters in-place slice of ChannelParticipantCreator.
|
|
func (s ChannelParticipantCreatorArray) Retain(keep func(x ChannelParticipantCreator) bool) ChannelParticipantCreatorArray {
|
|
n := 0
|
|
for _, x := range s {
|
|
if keep(x) {
|
|
s[n] = x
|
|
n++
|
|
}
|
|
}
|
|
s = s[:n]
|
|
|
|
return s
|
|
}
|
|
|
|
// First returns first element of slice (if exists).
|
|
func (s ChannelParticipantCreatorArray) First() (v ChannelParticipantCreator, ok bool) {
|
|
if len(s) < 1 {
|
|
return
|
|
}
|
|
return s[0], true
|
|
}
|
|
|
|
// Last returns last element of slice (if exists).
|
|
func (s ChannelParticipantCreatorArray) Last() (v ChannelParticipantCreator, ok bool) {
|
|
if len(s) < 1 {
|
|
return
|
|
}
|
|
return s[len(s)-1], true
|
|
}
|
|
|
|
// PopFirst returns first element of slice (if exists) and deletes it.
|
|
func (s *ChannelParticipantCreatorArray) PopFirst() (v ChannelParticipantCreator, ok bool) {
|
|
if s == nil || len(*s) < 1 {
|
|
return
|
|
}
|
|
|
|
a := *s
|
|
v = a[0]
|
|
|
|
// Delete by index from SliceTricks.
|
|
copy(a[0:], a[1:])
|
|
var zero ChannelParticipantCreator
|
|
a[len(a)-1] = zero
|
|
a = a[:len(a)-1]
|
|
*s = a
|
|
|
|
return v, true
|
|
}
|
|
|
|
// Pop returns last element of slice (if exists) and deletes it.
|
|
func (s *ChannelParticipantCreatorArray) Pop() (v ChannelParticipantCreator, ok bool) {
|
|
if s == nil || len(*s) < 1 {
|
|
return
|
|
}
|
|
|
|
a := *s
|
|
v = a[len(a)-1]
|
|
a = a[:len(a)-1]
|
|
*s = a
|
|
|
|
return v, true
|
|
}
|
|
|
|
// ChannelParticipantAdminArray is adapter for slice of ChannelParticipantAdmin.
|
|
type ChannelParticipantAdminArray []ChannelParticipantAdmin
|
|
|
|
// Sort sorts slice of ChannelParticipantAdmin.
|
|
func (s ChannelParticipantAdminArray) Sort(less func(a, b ChannelParticipantAdmin) bool) ChannelParticipantAdminArray {
|
|
sort.Slice(s, func(i, j int) bool {
|
|
return less(s[i], s[j])
|
|
})
|
|
return s
|
|
}
|
|
|
|
// SortStable sorts slice of ChannelParticipantAdmin.
|
|
func (s ChannelParticipantAdminArray) SortStable(less func(a, b ChannelParticipantAdmin) bool) ChannelParticipantAdminArray {
|
|
sort.SliceStable(s, func(i, j int) bool {
|
|
return less(s[i], s[j])
|
|
})
|
|
return s
|
|
}
|
|
|
|
// Retain filters in-place slice of ChannelParticipantAdmin.
|
|
func (s ChannelParticipantAdminArray) Retain(keep func(x ChannelParticipantAdmin) bool) ChannelParticipantAdminArray {
|
|
n := 0
|
|
for _, x := range s {
|
|
if keep(x) {
|
|
s[n] = x
|
|
n++
|
|
}
|
|
}
|
|
s = s[:n]
|
|
|
|
return s
|
|
}
|
|
|
|
// First returns first element of slice (if exists).
|
|
func (s ChannelParticipantAdminArray) First() (v ChannelParticipantAdmin, ok bool) {
|
|
if len(s) < 1 {
|
|
return
|
|
}
|
|
return s[0], true
|
|
}
|
|
|
|
// Last returns last element of slice (if exists).
|
|
func (s ChannelParticipantAdminArray) Last() (v ChannelParticipantAdmin, ok bool) {
|
|
if len(s) < 1 {
|
|
return
|
|
}
|
|
return s[len(s)-1], true
|
|
}
|
|
|
|
// PopFirst returns first element of slice (if exists) and deletes it.
|
|
func (s *ChannelParticipantAdminArray) PopFirst() (v ChannelParticipantAdmin, ok bool) {
|
|
if s == nil || len(*s) < 1 {
|
|
return
|
|
}
|
|
|
|
a := *s
|
|
v = a[0]
|
|
|
|
// Delete by index from SliceTricks.
|
|
copy(a[0:], a[1:])
|
|
var zero ChannelParticipantAdmin
|
|
a[len(a)-1] = zero
|
|
a = a[:len(a)-1]
|
|
*s = a
|
|
|
|
return v, true
|
|
}
|
|
|
|
// Pop returns last element of slice (if exists) and deletes it.
|
|
func (s *ChannelParticipantAdminArray) Pop() (v ChannelParticipantAdmin, ok bool) {
|
|
if s == nil || len(*s) < 1 {
|
|
return
|
|
}
|
|
|
|
a := *s
|
|
v = a[len(a)-1]
|
|
a = a[:len(a)-1]
|
|
*s = a
|
|
|
|
return v, true
|
|
}
|
|
|
|
// SortByDate sorts slice of ChannelParticipantAdmin by Date.
|
|
func (s ChannelParticipantAdminArray) SortByDate() ChannelParticipantAdminArray {
|
|
return s.Sort(func(a, b ChannelParticipantAdmin) bool {
|
|
return a.GetDate() < b.GetDate()
|
|
})
|
|
}
|
|
|
|
// SortStableByDate sorts slice of ChannelParticipantAdmin by Date.
|
|
func (s ChannelParticipantAdminArray) SortStableByDate() ChannelParticipantAdminArray {
|
|
return s.SortStable(func(a, b ChannelParticipantAdmin) bool {
|
|
return a.GetDate() < b.GetDate()
|
|
})
|
|
}
|
|
|
|
// ChannelParticipantBannedArray is adapter for slice of ChannelParticipantBanned.
|
|
type ChannelParticipantBannedArray []ChannelParticipantBanned
|
|
|
|
// Sort sorts slice of ChannelParticipantBanned.
|
|
func (s ChannelParticipantBannedArray) Sort(less func(a, b ChannelParticipantBanned) bool) ChannelParticipantBannedArray {
|
|
sort.Slice(s, func(i, j int) bool {
|
|
return less(s[i], s[j])
|
|
})
|
|
return s
|
|
}
|
|
|
|
// SortStable sorts slice of ChannelParticipantBanned.
|
|
func (s ChannelParticipantBannedArray) SortStable(less func(a, b ChannelParticipantBanned) bool) ChannelParticipantBannedArray {
|
|
sort.SliceStable(s, func(i, j int) bool {
|
|
return less(s[i], s[j])
|
|
})
|
|
return s
|
|
}
|
|
|
|
// Retain filters in-place slice of ChannelParticipantBanned.
|
|
func (s ChannelParticipantBannedArray) Retain(keep func(x ChannelParticipantBanned) bool) ChannelParticipantBannedArray {
|
|
n := 0
|
|
for _, x := range s {
|
|
if keep(x) {
|
|
s[n] = x
|
|
n++
|
|
}
|
|
}
|
|
s = s[:n]
|
|
|
|
return s
|
|
}
|
|
|
|
// First returns first element of slice (if exists).
|
|
func (s ChannelParticipantBannedArray) First() (v ChannelParticipantBanned, ok bool) {
|
|
if len(s) < 1 {
|
|
return
|
|
}
|
|
return s[0], true
|
|
}
|
|
|
|
// Last returns last element of slice (if exists).
|
|
func (s ChannelParticipantBannedArray) Last() (v ChannelParticipantBanned, ok bool) {
|
|
if len(s) < 1 {
|
|
return
|
|
}
|
|
return s[len(s)-1], true
|
|
}
|
|
|
|
// PopFirst returns first element of slice (if exists) and deletes it.
|
|
func (s *ChannelParticipantBannedArray) PopFirst() (v ChannelParticipantBanned, ok bool) {
|
|
if s == nil || len(*s) < 1 {
|
|
return
|
|
}
|
|
|
|
a := *s
|
|
v = a[0]
|
|
|
|
// Delete by index from SliceTricks.
|
|
copy(a[0:], a[1:])
|
|
var zero ChannelParticipantBanned
|
|
a[len(a)-1] = zero
|
|
a = a[:len(a)-1]
|
|
*s = a
|
|
|
|
return v, true
|
|
}
|
|
|
|
// Pop returns last element of slice (if exists) and deletes it.
|
|
func (s *ChannelParticipantBannedArray) Pop() (v ChannelParticipantBanned, ok bool) {
|
|
if s == nil || len(*s) < 1 {
|
|
return
|
|
}
|
|
|
|
a := *s
|
|
v = a[len(a)-1]
|
|
a = a[:len(a)-1]
|
|
*s = a
|
|
|
|
return v, true
|
|
}
|
|
|
|
// SortByDate sorts slice of ChannelParticipantBanned by Date.
|
|
func (s ChannelParticipantBannedArray) SortByDate() ChannelParticipantBannedArray {
|
|
return s.Sort(func(a, b ChannelParticipantBanned) bool {
|
|
return a.GetDate() < b.GetDate()
|
|
})
|
|
}
|
|
|
|
// SortStableByDate sorts slice of ChannelParticipantBanned by Date.
|
|
func (s ChannelParticipantBannedArray) SortStableByDate() ChannelParticipantBannedArray {
|
|
return s.SortStable(func(a, b ChannelParticipantBanned) bool {
|
|
return a.GetDate() < b.GetDate()
|
|
})
|
|
}
|
|
|
|
// ChannelParticipantLeftArray is adapter for slice of ChannelParticipantLeft.
|
|
type ChannelParticipantLeftArray []ChannelParticipantLeft
|
|
|
|
// Sort sorts slice of ChannelParticipantLeft.
|
|
func (s ChannelParticipantLeftArray) Sort(less func(a, b ChannelParticipantLeft) bool) ChannelParticipantLeftArray {
|
|
sort.Slice(s, func(i, j int) bool {
|
|
return less(s[i], s[j])
|
|
})
|
|
return s
|
|
}
|
|
|
|
// SortStable sorts slice of ChannelParticipantLeft.
|
|
func (s ChannelParticipantLeftArray) SortStable(less func(a, b ChannelParticipantLeft) bool) ChannelParticipantLeftArray {
|
|
sort.SliceStable(s, func(i, j int) bool {
|
|
return less(s[i], s[j])
|
|
})
|
|
return s
|
|
}
|
|
|
|
// Retain filters in-place slice of ChannelParticipantLeft.
|
|
func (s ChannelParticipantLeftArray) Retain(keep func(x ChannelParticipantLeft) bool) ChannelParticipantLeftArray {
|
|
n := 0
|
|
for _, x := range s {
|
|
if keep(x) {
|
|
s[n] = x
|
|
n++
|
|
}
|
|
}
|
|
s = s[:n]
|
|
|
|
return s
|
|
}
|
|
|
|
// First returns first element of slice (if exists).
|
|
func (s ChannelParticipantLeftArray) First() (v ChannelParticipantLeft, ok bool) {
|
|
if len(s) < 1 {
|
|
return
|
|
}
|
|
return s[0], true
|
|
}
|
|
|
|
// Last returns last element of slice (if exists).
|
|
func (s ChannelParticipantLeftArray) Last() (v ChannelParticipantLeft, ok bool) {
|
|
if len(s) < 1 {
|
|
return
|
|
}
|
|
return s[len(s)-1], true
|
|
}
|
|
|
|
// PopFirst returns first element of slice (if exists) and deletes it.
|
|
func (s *ChannelParticipantLeftArray) PopFirst() (v ChannelParticipantLeft, ok bool) {
|
|
if s == nil || len(*s) < 1 {
|
|
return
|
|
}
|
|
|
|
a := *s
|
|
v = a[0]
|
|
|
|
// Delete by index from SliceTricks.
|
|
copy(a[0:], a[1:])
|
|
var zero ChannelParticipantLeft
|
|
a[len(a)-1] = zero
|
|
a = a[:len(a)-1]
|
|
*s = a
|
|
|
|
return v, true
|
|
}
|
|
|
|
// Pop returns last element of slice (if exists) and deletes it.
|
|
func (s *ChannelParticipantLeftArray) Pop() (v ChannelParticipantLeft, ok bool) {
|
|
if s == nil || len(*s) < 1 {
|
|
return
|
|
}
|
|
|
|
a := *s
|
|
v = a[len(a)-1]
|
|
a = a[:len(a)-1]
|
|
*s = a
|
|
|
|
return v, true
|
|
}
|