package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
var (
_ = bin .Buffer {}
_ = context .Background ()
_ = fmt .Stringer (nil )
_ = strings .Builder {}
_ = errors .Is
_ = multierr .AppendInto
_ = sort .Ints
_ = tdp .Format
_ = tgerr .Error {}
_ = tdjson .Encoder {}
)
type DocumentClassArray []DocumentClass
func (s DocumentClassArray ) Sort (less func (a , b DocumentClass ) bool ) DocumentClassArray {
sort .Slice (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s DocumentClassArray ) SortStable (less func (a , b DocumentClass ) bool ) DocumentClassArray {
sort .SliceStable (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s DocumentClassArray ) Retain (keep func (x DocumentClass ) bool ) DocumentClassArray {
n := 0
for _ , x := range s {
if keep (x ) {
s [n ] = x
n ++
}
}
s = s [:n ]
return s
}
func (s DocumentClassArray ) First () (v DocumentClass , ok bool ) {
if len (s ) < 1 {
return
}
return s [0 ], true
}
func (s DocumentClassArray ) Last () (v DocumentClass , ok bool ) {
if len (s ) < 1 {
return
}
return s [len (s )-1 ], true
}
func (s *DocumentClassArray ) PopFirst () (v DocumentClass , ok bool ) {
if s == nil || len (*s ) < 1 {
return
}
a := *s
v = a [0 ]
copy (a [0 :], a [1 :])
var zero DocumentClass
a [len (a )-1 ] = zero
a = a [:len (a )-1 ]
*s = a
return v , true
}
func (s *DocumentClassArray ) Pop () (v DocumentClass , 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
}
func (s DocumentClassArray ) SortByID () DocumentClassArray {
return s .Sort (func (a , b DocumentClass ) bool {
return a .GetID () < b .GetID ()
})
}
func (s DocumentClassArray ) SortStableByID () DocumentClassArray {
return s .SortStable (func (a , b DocumentClass ) bool {
return a .GetID () < b .GetID ()
})
}
func (s DocumentClassArray ) FillDocumentEmptyMap (to map [int64 ]*DocumentEmpty ) {
for _ , elem := range s {
value , ok := elem .(*DocumentEmpty )
if !ok {
continue
}
to [value .GetID ()] = value
}
}
func (s DocumentClassArray ) DocumentEmptyToMap () map [int64 ]*DocumentEmpty {
r := make (map [int64 ]*DocumentEmpty , len (s ))
s .FillDocumentEmptyMap (r )
return r
}
func (s DocumentClassArray ) AsDocumentEmpty () (to DocumentEmptyArray ) {
for _ , elem := range s {
value , ok := elem .(*DocumentEmpty )
if !ok {
continue
}
to = append (to , *value )
}
return to
}
func (s DocumentClassArray ) FillDocumentMap (to map [int64 ]*Document ) {
for _ , elem := range s {
value , ok := elem .(*Document )
if !ok {
continue
}
to [value .GetID ()] = value
}
}
func (s DocumentClassArray ) DocumentToMap () map [int64 ]*Document {
r := make (map [int64 ]*Document , len (s ))
s .FillDocumentMap (r )
return r
}
func (s DocumentClassArray ) AsDocument () (to DocumentArray ) {
for _ , elem := range s {
value , ok := elem .(*Document )
if !ok {
continue
}
to = append (to , *value )
}
return to
}
func (s DocumentClassArray ) FillNotEmptyMap (to map [int64 ]*Document ) {
for _ , elem := range s {
value , ok := elem .AsNotEmpty ()
if !ok {
continue
}
to [value .GetID ()] = value
}
}
func (s DocumentClassArray ) NotEmptyToMap () map [int64 ]*Document {
r := make (map [int64 ]*Document , len (s ))
s .FillNotEmptyMap (r )
return r
}
func (s DocumentClassArray ) AppendOnlyNotEmpty (to []*Document ) []*Document {
for _ , elem := range s {
value , ok := elem .AsNotEmpty ()
if !ok {
continue
}
to = append (to , value )
}
return to
}
func (s DocumentClassArray ) AsNotEmpty () (to []*Document ) {
return s .AppendOnlyNotEmpty (to )
}
func (s DocumentClassArray ) FirstAsNotEmpty () (v *Document , ok bool ) {
value , ok := s .First ()
if !ok {
return
}
return value .AsNotEmpty ()
}
func (s DocumentClassArray ) LastAsNotEmpty () (v *Document , ok bool ) {
value , ok := s .Last ()
if !ok {
return
}
return value .AsNotEmpty ()
}
func (s *DocumentClassArray ) PopFirstAsNotEmpty () (v *Document , ok bool ) {
value , ok := s .PopFirst ()
if !ok {
return
}
return value .AsNotEmpty ()
}
func (s *DocumentClassArray ) PopAsNotEmpty () (v *Document , ok bool ) {
value , ok := s .Pop ()
if !ok {
return
}
return value .AsNotEmpty ()
}
type DocumentEmptyArray []DocumentEmpty
func (s DocumentEmptyArray ) Sort (less func (a , b DocumentEmpty ) bool ) DocumentEmptyArray {
sort .Slice (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s DocumentEmptyArray ) SortStable (less func (a , b DocumentEmpty ) bool ) DocumentEmptyArray {
sort .SliceStable (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s DocumentEmptyArray ) Retain (keep func (x DocumentEmpty ) bool ) DocumentEmptyArray {
n := 0
for _ , x := range s {
if keep (x ) {
s [n ] = x
n ++
}
}
s = s [:n ]
return s
}
func (s DocumentEmptyArray ) First () (v DocumentEmpty , ok bool ) {
if len (s ) < 1 {
return
}
return s [0 ], true
}
func (s DocumentEmptyArray ) Last () (v DocumentEmpty , ok bool ) {
if len (s ) < 1 {
return
}
return s [len (s )-1 ], true
}
func (s *DocumentEmptyArray ) PopFirst () (v DocumentEmpty , ok bool ) {
if s == nil || len (*s ) < 1 {
return
}
a := *s
v = a [0 ]
copy (a [0 :], a [1 :])
var zero DocumentEmpty
a [len (a )-1 ] = zero
a = a [:len (a )-1 ]
*s = a
return v , true
}
func (s *DocumentEmptyArray ) Pop () (v DocumentEmpty , 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
}
func (s DocumentEmptyArray ) SortByID () DocumentEmptyArray {
return s .Sort (func (a , b DocumentEmpty ) bool {
return a .GetID () < b .GetID ()
})
}
func (s DocumentEmptyArray ) SortStableByID () DocumentEmptyArray {
return s .SortStable (func (a , b DocumentEmpty ) bool {
return a .GetID () < b .GetID ()
})
}
func (s DocumentEmptyArray ) FillMap (to map [int64 ]DocumentEmpty ) {
for _ , value := range s {
to [value .GetID ()] = value
}
}
func (s DocumentEmptyArray ) ToMap () map [int64 ]DocumentEmpty {
r := make (map [int64 ]DocumentEmpty , len (s ))
s .FillMap (r )
return r
}
type DocumentArray []Document
func (s DocumentArray ) Sort (less func (a , b Document ) bool ) DocumentArray {
sort .Slice (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s DocumentArray ) SortStable (less func (a , b Document ) bool ) DocumentArray {
sort .SliceStable (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s DocumentArray ) Retain (keep func (x Document ) bool ) DocumentArray {
n := 0
for _ , x := range s {
if keep (x ) {
s [n ] = x
n ++
}
}
s = s [:n ]
return s
}
func (s DocumentArray ) First () (v Document , ok bool ) {
if len (s ) < 1 {
return
}
return s [0 ], true
}
func (s DocumentArray ) Last () (v Document , ok bool ) {
if len (s ) < 1 {
return
}
return s [len (s )-1 ], true
}
func (s *DocumentArray ) PopFirst () (v Document , ok bool ) {
if s == nil || len (*s ) < 1 {
return
}
a := *s
v = a [0 ]
copy (a [0 :], a [1 :])
var zero Document
a [len (a )-1 ] = zero
a = a [:len (a )-1 ]
*s = a
return v , true
}
func (s *DocumentArray ) Pop () (v Document , 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
}
func (s DocumentArray ) SortByID () DocumentArray {
return s .Sort (func (a , b Document ) bool {
return a .GetID () < b .GetID ()
})
}
func (s DocumentArray ) SortStableByID () DocumentArray {
return s .SortStable (func (a , b Document ) bool {
return a .GetID () < b .GetID ()
})
}
func (s DocumentArray ) SortByDate () DocumentArray {
return s .Sort (func (a , b Document ) bool {
return a .GetDate () < b .GetDate ()
})
}
func (s DocumentArray ) SortStableByDate () DocumentArray {
return s .SortStable (func (a , b Document ) bool {
return a .GetDate () < b .GetDate ()
})
}
func (s DocumentArray ) FillMap (to map [int64 ]Document ) {
for _ , value := range s {
to [value .GetID ()] = value
}
}
func (s DocumentArray ) ToMap () map [int64 ]Document {
r := make (map [int64 ]Document , len (s ))
s .FillMap (r )
return r
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .