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 JSONValueClassArray []JSONValueClass
func (s JSONValueClassArray ) Sort (less func (a , b JSONValueClass ) bool ) JSONValueClassArray {
sort .Slice (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s JSONValueClassArray ) SortStable (less func (a , b JSONValueClass ) bool ) JSONValueClassArray {
sort .SliceStable (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s JSONValueClassArray ) Retain (keep func (x JSONValueClass ) bool ) JSONValueClassArray {
n := 0
for _ , x := range s {
if keep (x ) {
s [n ] = x
n ++
}
}
s = s [:n ]
return s
}
func (s JSONValueClassArray ) First () (v JSONValueClass , ok bool ) {
if len (s ) < 1 {
return
}
return s [0 ], true
}
func (s JSONValueClassArray ) Last () (v JSONValueClass , ok bool ) {
if len (s ) < 1 {
return
}
return s [len (s )-1 ], true
}
func (s *JSONValueClassArray ) PopFirst () (v JSONValueClass , ok bool ) {
if s == nil || len (*s ) < 1 {
return
}
a := *s
v = a [0 ]
copy (a [0 :], a [1 :])
var zero JSONValueClass
a [len (a )-1 ] = zero
a = a [:len (a )-1 ]
*s = a
return v , true
}
func (s *JSONValueClassArray ) Pop () (v JSONValueClass , 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 JSONValueClassArray ) AsJSONBool () (to JSONBoolArray ) {
for _ , elem := range s {
value , ok := elem .(*JSONBool )
if !ok {
continue
}
to = append (to , *value )
}
return to
}
func (s JSONValueClassArray ) AsJSONNumber () (to JSONNumberArray ) {
for _ , elem := range s {
value , ok := elem .(*JSONNumber )
if !ok {
continue
}
to = append (to , *value )
}
return to
}
func (s JSONValueClassArray ) AsJSONString () (to JSONStringArray ) {
for _ , elem := range s {
value , ok := elem .(*JSONString )
if !ok {
continue
}
to = append (to , *value )
}
return to
}
func (s JSONValueClassArray ) AsJSONArray () (to JSONArrayArray ) {
for _ , elem := range s {
value , ok := elem .(*JSONArray )
if !ok {
continue
}
to = append (to , *value )
}
return to
}
func (s JSONValueClassArray ) AsJSONObject () (to JSONObjectArray ) {
for _ , elem := range s {
value , ok := elem .(*JSONObject )
if !ok {
continue
}
to = append (to , *value )
}
return to
}
type JSONBoolArray []JSONBool
func (s JSONBoolArray ) Sort (less func (a , b JSONBool ) bool ) JSONBoolArray {
sort .Slice (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s JSONBoolArray ) SortStable (less func (a , b JSONBool ) bool ) JSONBoolArray {
sort .SliceStable (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s JSONBoolArray ) Retain (keep func (x JSONBool ) bool ) JSONBoolArray {
n := 0
for _ , x := range s {
if keep (x ) {
s [n ] = x
n ++
}
}
s = s [:n ]
return s
}
func (s JSONBoolArray ) First () (v JSONBool , ok bool ) {
if len (s ) < 1 {
return
}
return s [0 ], true
}
func (s JSONBoolArray ) Last () (v JSONBool , ok bool ) {
if len (s ) < 1 {
return
}
return s [len (s )-1 ], true
}
func (s *JSONBoolArray ) PopFirst () (v JSONBool , ok bool ) {
if s == nil || len (*s ) < 1 {
return
}
a := *s
v = a [0 ]
copy (a [0 :], a [1 :])
var zero JSONBool
a [len (a )-1 ] = zero
a = a [:len (a )-1 ]
*s = a
return v , true
}
func (s *JSONBoolArray ) Pop () (v JSONBool , 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
}
type JSONNumberArray []JSONNumber
func (s JSONNumberArray ) Sort (less func (a , b JSONNumber ) bool ) JSONNumberArray {
sort .Slice (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s JSONNumberArray ) SortStable (less func (a , b JSONNumber ) bool ) JSONNumberArray {
sort .SliceStable (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s JSONNumberArray ) Retain (keep func (x JSONNumber ) bool ) JSONNumberArray {
n := 0
for _ , x := range s {
if keep (x ) {
s [n ] = x
n ++
}
}
s = s [:n ]
return s
}
func (s JSONNumberArray ) First () (v JSONNumber , ok bool ) {
if len (s ) < 1 {
return
}
return s [0 ], true
}
func (s JSONNumberArray ) Last () (v JSONNumber , ok bool ) {
if len (s ) < 1 {
return
}
return s [len (s )-1 ], true
}
func (s *JSONNumberArray ) PopFirst () (v JSONNumber , ok bool ) {
if s == nil || len (*s ) < 1 {
return
}
a := *s
v = a [0 ]
copy (a [0 :], a [1 :])
var zero JSONNumber
a [len (a )-1 ] = zero
a = a [:len (a )-1 ]
*s = a
return v , true
}
func (s *JSONNumberArray ) Pop () (v JSONNumber , 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
}
type JSONStringArray []JSONString
func (s JSONStringArray ) Sort (less func (a , b JSONString ) bool ) JSONStringArray {
sort .Slice (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s JSONStringArray ) SortStable (less func (a , b JSONString ) bool ) JSONStringArray {
sort .SliceStable (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s JSONStringArray ) Retain (keep func (x JSONString ) bool ) JSONStringArray {
n := 0
for _ , x := range s {
if keep (x ) {
s [n ] = x
n ++
}
}
s = s [:n ]
return s
}
func (s JSONStringArray ) First () (v JSONString , ok bool ) {
if len (s ) < 1 {
return
}
return s [0 ], true
}
func (s JSONStringArray ) Last () (v JSONString , ok bool ) {
if len (s ) < 1 {
return
}
return s [len (s )-1 ], true
}
func (s *JSONStringArray ) PopFirst () (v JSONString , ok bool ) {
if s == nil || len (*s ) < 1 {
return
}
a := *s
v = a [0 ]
copy (a [0 :], a [1 :])
var zero JSONString
a [len (a )-1 ] = zero
a = a [:len (a )-1 ]
*s = a
return v , true
}
func (s *JSONStringArray ) Pop () (v JSONString , 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
}
type JSONArrayArray []JSONArray
func (s JSONArrayArray ) Sort (less func (a , b JSONArray ) bool ) JSONArrayArray {
sort .Slice (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s JSONArrayArray ) SortStable (less func (a , b JSONArray ) bool ) JSONArrayArray {
sort .SliceStable (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s JSONArrayArray ) Retain (keep func (x JSONArray ) bool ) JSONArrayArray {
n := 0
for _ , x := range s {
if keep (x ) {
s [n ] = x
n ++
}
}
s = s [:n ]
return s
}
func (s JSONArrayArray ) First () (v JSONArray , ok bool ) {
if len (s ) < 1 {
return
}
return s [0 ], true
}
func (s JSONArrayArray ) Last () (v JSONArray , ok bool ) {
if len (s ) < 1 {
return
}
return s [len (s )-1 ], true
}
func (s *JSONArrayArray ) PopFirst () (v JSONArray , ok bool ) {
if s == nil || len (*s ) < 1 {
return
}
a := *s
v = a [0 ]
copy (a [0 :], a [1 :])
var zero JSONArray
a [len (a )-1 ] = zero
a = a [:len (a )-1 ]
*s = a
return v , true
}
func (s *JSONArrayArray ) Pop () (v JSONArray , 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
}
type JSONObjectArray []JSONObject
func (s JSONObjectArray ) Sort (less func (a , b JSONObject ) bool ) JSONObjectArray {
sort .Slice (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s JSONObjectArray ) SortStable (less func (a , b JSONObject ) bool ) JSONObjectArray {
sort .SliceStable (s , func (i , j int ) bool {
return less (s [i ], s [j ])
})
return s
}
func (s JSONObjectArray ) Retain (keep func (x JSONObject ) bool ) JSONObjectArray {
n := 0
for _ , x := range s {
if keep (x ) {
s [n ] = x
n ++
}
}
s = s [:n ]
return s
}
func (s JSONObjectArray ) First () (v JSONObject , ok bool ) {
if len (s ) < 1 {
return
}
return s [0 ], true
}
func (s JSONObjectArray ) Last () (v JSONObject , ok bool ) {
if len (s ) < 1 {
return
}
return s [len (s )-1 ], true
}
func (s *JSONObjectArray ) PopFirst () (v JSONObject , ok bool ) {
if s == nil || len (*s ) < 1 {
return
}
a := *s
v = a [0 ]
copy (a [0 :], a [1 :])
var zero JSONObject
a [len (a )-1 ] = zero
a = a [:len (a )-1 ]
*s = a
return v , true
}
func (s *JSONObjectArray ) Pop () (v JSONObject , 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
}
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 .