_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q171700 | UnmarshalJSON | validation | func (e *Email) UnmarshalJSON(data []byte) error {
l := jlexer.Lexer{Data: data}
e.UnmarshalEasyJSON(&l)
return l.Error()
} | go | {
"resource": ""
} |
q171701 | UnmarshalEasyJSON | validation | func (e *Email) UnmarshalEasyJSON(in *jlexer.Lexer) {
if data := in.String(); in.Ok() {
*e = Email(data)
}
} | go | {
"resource": ""
} |
q171702 | SetBSON | validation | func (e *Email) SetBSON(raw bson.Raw) error {
var m bson.M
if err := raw.Unmarshal(&m); err != nil {
return err
}
if data, ok := m["data"].(string); ok {
*e = Email(data)
return nil
}
return errors.New("couldn't unmarshal bson raw value as Email")
} | go | {
"resource": ""
} |
q171703 | DeepCopy | validation | func (e *Email) DeepCopy() *Email {
if e == nil {
return nil
}
out := new(Email)
e.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171704 | MarshalEasyJSON | validation | func (h Hostname) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(h))
} | go | {
"resource": ""
} |
q171705 | SetBSON | validation | func (h *Hostname) SetBSON(raw bson.Raw) error {
var m bson.M
if err := raw.Unmarshal(&m); err != nil {
return err
}
if data, ok := m["data"].(string); ok {
*h = Hostname(data)
return nil
}
return errors.New("couldn't unmarshal bson raw value as Hostname")
} | go | {
"resource": ""
} |
q171706 | DeepCopy | validation | func (h *Hostname) DeepCopy() *Hostname {
if h == nil {
return nil
}
out := new(Hostname)
h.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171707 | MarshalEasyJSON | validation | func (u IPv4) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(u))
} | go | {
"resource": ""
} |
q171708 | DeepCopy | validation | func (u *IPv4) DeepCopy() *IPv4 {
if u == nil {
return nil
}
out := new(IPv4)
u.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171709 | MarshalEasyJSON | validation | func (u IPv6) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(u))
} | go | {
"resource": ""
} |
q171710 | DeepCopy | validation | func (u *IPv6) DeepCopy() *IPv6 {
if u == nil {
return nil
}
out := new(IPv6)
u.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171711 | MarshalEasyJSON | validation | func (u CIDR) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(u))
} | go | {
"resource": ""
} |
q171712 | DeepCopy | validation | func (u *CIDR) DeepCopy() *CIDR {
if u == nil {
return nil
}
out := new(CIDR)
u.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171713 | MarshalEasyJSON | validation | func (u MAC) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(u))
} | go | {
"resource": ""
} |
q171714 | DeepCopy | validation | func (u *MAC) DeepCopy() *MAC {
if u == nil {
return nil
}
out := new(MAC)
u.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171715 | MarshalEasyJSON | validation | func (u UUID) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(u))
} | go | {
"resource": ""
} |
q171716 | SetBSON | validation | func (u *UUID) SetBSON(raw bson.Raw) error {
var m bson.M
if err := raw.Unmarshal(&m); err != nil {
return err
}
if data, ok := m["data"].(string); ok {
*u = UUID(data)
return nil
}
return errors.New("couldn't unmarshal bson raw value as UUID")
} | go | {
"resource": ""
} |
q171717 | DeepCopy | validation | func (u *UUID) DeepCopy() *UUID {
if u == nil {
return nil
}
out := new(UUID)
u.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171718 | MarshalEasyJSON | validation | func (u UUID3) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(u))
} | go | {
"resource": ""
} |
q171719 | DeepCopy | validation | func (u *UUID3) DeepCopy() *UUID3 {
if u == nil {
return nil
}
out := new(UUID3)
u.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171720 | MarshalEasyJSON | validation | func (u UUID4) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(u))
} | go | {
"resource": ""
} |
q171721 | UnmarshalJSON | validation | func (u *UUID4) UnmarshalJSON(data []byte) error {
if string(data) == jsonNull {
return nil
}
l := jlexer.Lexer{Data: data}
u.UnmarshalEasyJSON(&l)
return l.Error()
} | go | {
"resource": ""
} |
q171722 | DeepCopy | validation | func (u *UUID4) DeepCopy() *UUID4 {
if u == nil {
return nil
}
out := new(UUID4)
u.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171723 | MarshalEasyJSON | validation | func (u UUID5) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(u))
} | go | {
"resource": ""
} |
q171724 | DeepCopy | validation | func (u *UUID5) DeepCopy() *UUID5 {
if u == nil {
return nil
}
out := new(UUID5)
u.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171725 | MarshalEasyJSON | validation | func (u ISBN) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(u))
} | go | {
"resource": ""
} |
q171726 | DeepCopy | validation | func (u *ISBN) DeepCopy() *ISBN {
if u == nil {
return nil
}
out := new(ISBN)
u.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171727 | MarshalEasyJSON | validation | func (u ISBN10) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(u))
} | go | {
"resource": ""
} |
q171728 | UnmarshalEasyJSON | validation | func (u *ISBN10) UnmarshalEasyJSON(in *jlexer.Lexer) {
if data := in.String(); in.Ok() {
*u = ISBN10(data)
}
} | go | {
"resource": ""
} |
q171729 | DeepCopy | validation | func (u *ISBN10) DeepCopy() *ISBN10 {
if u == nil {
return nil
}
out := new(ISBN10)
u.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171730 | MarshalEasyJSON | validation | func (u ISBN13) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(u))
} | go | {
"resource": ""
} |
q171731 | DeepCopy | validation | func (u *ISBN13) DeepCopy() *ISBN13 {
if u == nil {
return nil
}
out := new(ISBN13)
u.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171732 | MarshalEasyJSON | validation | func (u CreditCard) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(u))
} | go | {
"resource": ""
} |
q171733 | DeepCopy | validation | func (u *CreditCard) DeepCopy() *CreditCard {
if u == nil {
return nil
}
out := new(CreditCard)
u.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171734 | MarshalEasyJSON | validation | func (u SSN) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(u))
} | go | {
"resource": ""
} |
q171735 | DeepCopy | validation | func (u *SSN) DeepCopy() *SSN {
if u == nil {
return nil
}
out := new(SSN)
u.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171736 | MarshalJSON | validation | func (h HexColor) MarshalJSON() ([]byte, error) {
var w jwriter.Writer
h.MarshalEasyJSON(&w)
return w.BuildBytes()
} | go | {
"resource": ""
} |
q171737 | MarshalEasyJSON | validation | func (h HexColor) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(h))
} | go | {
"resource": ""
} |
q171738 | UnmarshalJSON | validation | func (h *HexColor) UnmarshalJSON(data []byte) error {
l := jlexer.Lexer{Data: data}
h.UnmarshalEasyJSON(&l)
return l.Error()
} | go | {
"resource": ""
} |
q171739 | UnmarshalEasyJSON | validation | func (h *HexColor) UnmarshalEasyJSON(in *jlexer.Lexer) {
if data := in.String(); in.Ok() {
*h = HexColor(data)
}
} | go | {
"resource": ""
} |
q171740 | DeepCopy | validation | func (h *HexColor) DeepCopy() *HexColor {
if h == nil {
return nil
}
out := new(HexColor)
h.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171741 | MarshalEasyJSON | validation | func (r RGBColor) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(r))
} | go | {
"resource": ""
} |
q171742 | UnmarshalJSON | validation | func (r *RGBColor) UnmarshalJSON(data []byte) error {
l := jlexer.Lexer{Data: data}
r.UnmarshalEasyJSON(&l)
return l.Error()
} | go | {
"resource": ""
} |
q171743 | UnmarshalEasyJSON | validation | func (r *RGBColor) UnmarshalEasyJSON(in *jlexer.Lexer) {
if data := in.String(); in.Ok() {
*r = RGBColor(data)
}
} | go | {
"resource": ""
} |
q171744 | DeepCopy | validation | func (r *RGBColor) DeepCopy() *RGBColor {
if r == nil {
return nil
}
out := new(RGBColor)
r.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171745 | MarshalJSON | validation | func (r Password) MarshalJSON() ([]byte, error) {
var w jwriter.Writer
r.MarshalEasyJSON(&w)
return w.BuildBytes()
} | go | {
"resource": ""
} |
q171746 | MarshalEasyJSON | validation | func (r Password) MarshalEasyJSON(w *jwriter.Writer) {
w.String(string(r))
} | go | {
"resource": ""
} |
q171747 | SetBSON | validation | func (r *Password) SetBSON(raw bson.Raw) error {
var m bson.M
if err := raw.Unmarshal(&m); err != nil {
return err
}
if data, ok := m["data"].(string); ok {
*r = Password(data)
return nil
}
return errors.New("couldn't unmarshal bson raw value as Password")
} | go | {
"resource": ""
} |
q171748 | DeepCopy | validation | func (r *Password) DeepCopy() *Password {
if r == nil {
return nil
}
out := new(Password)
r.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171749 | IsDateTime | validation | func IsDateTime(str string) bool {
if len(str) < 4 {
return false
}
s := strings.Split(strings.ToLower(str), "t")
if len(s) < 2 || !IsDate(s[0]) {
return false
}
matches := rxDateTime.FindAllStringSubmatch(s[1], -1)
if len(matches) == 0 || len(matches[0]) == 0 {
return false
}
m := matches[0]
res := m[... | go | {
"resource": ""
} |
q171750 | ParseDateTime | validation | func ParseDateTime(data string) (DateTime, error) {
if data == "" {
return NewDateTime(), nil
}
var lastError error
for _, layout := range dateTimeFormats {
dd, err := time.Parse(layout, data)
if err != nil {
lastError = err
continue
}
lastError = nil
return DateTime(dd), nil
}
return DateTime{}... | go | {
"resource": ""
} |
q171751 | UnmarshalText | validation | func (t *DateTime) UnmarshalText(text []byte) error {
tt, err := ParseDateTime(string(text))
if err != nil {
return err
}
*t = tt
return nil
} | go | {
"resource": ""
} |
q171752 | Scan | validation | func (t *DateTime) Scan(raw interface{}) error {
// TODO: case int64: and case float64: ?
switch v := raw.(type) {
case []byte:
return t.UnmarshalText(v)
case string:
return t.UnmarshalText([]byte(v))
case time.Time:
*t = DateTime(v)
case nil:
*t = DateTime{}
default:
return fmt.Errorf("cannot sql.Scan... | go | {
"resource": ""
} |
q171753 | Value | validation | func (t DateTime) Value() (driver.Value, error) {
return driver.Value(t.String()), nil
} | go | {
"resource": ""
} |
q171754 | MarshalJSON | validation | func (t DateTime) MarshalJSON() ([]byte, error) {
var w jwriter.Writer
t.MarshalEasyJSON(&w)
return w.BuildBytes()
} | go | {
"resource": ""
} |
q171755 | MarshalEasyJSON | validation | func (t DateTime) MarshalEasyJSON(w *jwriter.Writer) {
w.String(time.Time(t).Format(MarshalFormat))
} | go | {
"resource": ""
} |
q171756 | UnmarshalJSON | validation | func (t *DateTime) UnmarshalJSON(data []byte) error {
if string(data) == jsonNull {
return nil
}
l := jlexer.Lexer{Data: data}
t.UnmarshalEasyJSON(&l)
return l.Error()
} | go | {
"resource": ""
} |
q171757 | UnmarshalEasyJSON | validation | func (t *DateTime) UnmarshalEasyJSON(in *jlexer.Lexer) {
if data := in.String(); in.Ok() {
tt, err := ParseDateTime(data)
if err != nil {
in.AddError(err)
return
}
*t = tt
}
} | go | {
"resource": ""
} |
q171758 | SetBSON | validation | func (t *DateTime) SetBSON(raw bson.Raw) error {
var m bson.M
if err := raw.Unmarshal(&m); err != nil {
return err
}
if data, ok := m["data"].(string); ok {
var err error
*t, err = ParseDateTime(data)
return err
}
return errors.New("couldn't unmarshal bson raw value as Duration")
} | go | {
"resource": ""
} |
q171759 | DeepCopy | validation | func (t *DateTime) DeepCopy() *DateTime {
if t == nil {
return nil
}
out := new(DateTime)
t.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171760 | IsDuration | validation | func IsDuration(str string) bool {
_, err := ParseDuration(str)
return err == nil
} | go | {
"resource": ""
} |
q171761 | ParseDuration | validation | func ParseDuration(cand string) (time.Duration, error) {
if dur, err := time.ParseDuration(cand); err == nil {
return dur, nil
}
var dur time.Duration
ok := false
for _, match := range durationMatcher.FindAllStringSubmatch(cand, -1) {
factor, err := strconv.Atoi(match[2]) // converts string to int
if err !... | go | {
"resource": ""
} |
q171762 | Scan | validation | func (d *Duration) Scan(raw interface{}) error {
switch v := raw.(type) {
// TODO: case []byte: // ?
case int64:
*d = Duration(v)
case float64:
*d = Duration(int64(v))
case nil:
*d = Duration(0)
default:
return fmt.Errorf("cannot sql.Scan() strfmt.Duration from: %#v", v)
}
return nil
} | go | {
"resource": ""
} |
q171763 | Value | validation | func (d Duration) Value() (driver.Value, error) {
return driver.Value(int64(d)), nil
} | go | {
"resource": ""
} |
q171764 | MarshalJSON | validation | func (d Duration) MarshalJSON() ([]byte, error) {
var w jwriter.Writer
d.MarshalEasyJSON(&w)
return w.BuildBytes()
} | go | {
"resource": ""
} |
q171765 | MarshalEasyJSON | validation | func (d Duration) MarshalEasyJSON(w *jwriter.Writer) {
w.String(time.Duration(d).String())
} | go | {
"resource": ""
} |
q171766 | UnmarshalJSON | validation | func (d *Duration) UnmarshalJSON(data []byte) error {
l := jlexer.Lexer{Data: data}
d.UnmarshalEasyJSON(&l)
return l.Error()
} | go | {
"resource": ""
} |
q171767 | UnmarshalEasyJSON | validation | func (d *Duration) UnmarshalEasyJSON(in *jlexer.Lexer) {
if data := in.String(); in.Ok() {
tt, err := ParseDuration(data)
if err != nil {
in.AddError(err)
return
}
*d = Duration(tt)
}
} | go | {
"resource": ""
} |
q171768 | SetBSON | validation | func (d *Duration) SetBSON(raw bson.Raw) error {
var m bson.M
if err := raw.Unmarshal(&m); err != nil {
return err
}
if data, ok := m["data"].(int64); ok {
*d = Duration(data)
return nil
}
return errors.New("couldn't unmarshal bson raw value as Duration")
} | go | {
"resource": ""
} |
q171769 | DeepCopy | validation | func (d *Duration) DeepCopy() *Duration {
if d == nil {
return nil
}
out := new(Duration)
d.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171770 | DateValue | validation | func DateValue(v *strfmt.Date) strfmt.Date {
if v == nil {
return strfmt.Date{}
}
return *v
} | go | {
"resource": ""
} |
q171771 | IsDate | validation | func IsDate(str string) bool {
_, err := time.Parse(RFC3339FullDate, str)
return err == nil
} | go | {
"resource": ""
} |
q171772 | UnmarshalText | validation | func (d *Date) UnmarshalText(text []byte) error {
if len(text) == 0 {
return nil
}
dd, err := time.Parse(RFC3339FullDate, string(text))
if err != nil {
return err
}
*d = Date(dd)
return nil
} | go | {
"resource": ""
} |
q171773 | Scan | validation | func (d *Date) Scan(raw interface{}) error {
switch v := raw.(type) {
case []byte:
return d.UnmarshalText(v)
case string:
return d.UnmarshalText([]byte(v))
case time.Time:
*d = Date(v)
return nil
case nil:
*d = Date{}
return nil
default:
return fmt.Errorf("cannot sql.Scan() strfmt.Date from: %#v", v... | go | {
"resource": ""
} |
q171774 | Value | validation | func (d Date) Value() (driver.Value, error) {
return driver.Value(d.String()), nil
} | go | {
"resource": ""
} |
q171775 | MarshalEasyJSON | validation | func (d Date) MarshalEasyJSON(w *jwriter.Writer) {
w.String(time.Time(d).Format(RFC3339FullDate))
} | go | {
"resource": ""
} |
q171776 | UnmarshalJSON | validation | func (d *Date) UnmarshalJSON(data []byte) error {
if string(data) == jsonNull {
return nil
}
l := jlexer.Lexer{Data: data}
d.UnmarshalEasyJSON(&l)
return l.Error()
} | go | {
"resource": ""
} |
q171777 | UnmarshalEasyJSON | validation | func (d *Date) UnmarshalEasyJSON(in *jlexer.Lexer) {
if data := in.String(); in.Ok() {
tt, err := time.Parse(RFC3339FullDate, data)
if err != nil {
in.AddError(err)
return
}
*d = Date(tt)
}
} | go | {
"resource": ""
} |
q171778 | SetBSON | validation | func (d *Date) SetBSON(raw bson.Raw) error {
var m bson.M
if err := raw.Unmarshal(&m); err != nil {
return err
}
if data, ok := m["data"].(string); ok {
rd, err := time.Parse(RFC3339FullDate, data)
*d = Date(rd)
return err
}
return errors.New("couldn't unmarshal bson raw value as Date")
} | go | {
"resource": ""
} |
q171779 | DeepCopy | validation | func (d *Date) DeepCopy() *Date {
if d == nil {
return nil
}
out := new(Date)
d.DeepCopyInto(out)
return out
} | go | {
"resource": ""
} |
q171780 | DateTimeValue | validation | func DateTimeValue(v *strfmt.DateTime) strfmt.DateTime {
if v == nil {
return strfmt.DateTime{}
}
return *v
} | go | {
"resource": ""
} |
q171781 | NewSeededFormats | validation | func NewSeededFormats(seeds []knownFormat, normalizer NameNormalizer) Registry {
if normalizer == nil {
normalizer = DefaultNameNormalizer
}
// copy here, don't modify original
d := append([]knownFormat(nil), seeds...)
return &defaultFormats{
data: d,
normalizeName: normalizer,
}
} | go | {
"resource": ""
} |
q171782 | Add | validation | func (f *defaultFormats) Add(name string, strfmt Format, validator Validator) bool {
f.Lock()
defer f.Unlock()
nme := f.normalizeName(name)
tpe := reflect.TypeOf(strfmt)
if tpe.Kind() == reflect.Ptr {
tpe = tpe.Elem()
}
for i := range f.data {
v := &f.data[i]
if v.Name == nme {
v.Type = tpe
v.Vali... | go | {
"resource": ""
} |
q171783 | GetType | validation | func (f *defaultFormats) GetType(name string) (reflect.Type, bool) {
f.Lock()
defer f.Unlock()
nme := f.normalizeName(name)
for _, v := range f.data {
if v.Name == nme {
return v.Type, true
}
}
return nil, false
} | go | {
"resource": ""
} |
q171784 | DelByName | validation | func (f *defaultFormats) DelByName(name string) bool {
f.Lock()
defer f.Unlock()
nme := f.normalizeName(name)
for i, v := range f.data {
if v.Name == nme {
f.data[i] = knownFormat{} // release
f.data = append(f.data[:i], f.data[i+1:]...)
return true
}
}
return false
} | go | {
"resource": ""
} |
q171785 | DelByFormat | validation | func (f *defaultFormats) DelByFormat(strfmt Format) bool {
f.Lock()
defer f.Unlock()
tpe := reflect.TypeOf(strfmt)
if tpe.Kind() == reflect.Ptr {
tpe = tpe.Elem()
}
for i, v := range f.data {
if v.Type == tpe {
f.data[i] = knownFormat{} // release
f.data = append(f.data[:i], f.data[i+1:]...)
return... | go | {
"resource": ""
} |
q171786 | ContainsName | validation | func (f *defaultFormats) ContainsName(name string) bool {
f.Lock()
defer f.Unlock()
nme := f.normalizeName(name)
for _, v := range f.data {
if v.Name == nme {
return true
}
}
return false
} | go | {
"resource": ""
} |
q171787 | ContainsFormat | validation | func (f *defaultFormats) ContainsFormat(strfmt Format) bool {
f.Lock()
defer f.Unlock()
tpe := reflect.TypeOf(strfmt)
if tpe.Kind() == reflect.Ptr {
tpe = tpe.Elem()
}
for _, v := range f.data {
if v.Type == tpe {
return true
}
}
return false
} | go | {
"resource": ""
} |
q171788 | Parse | validation | func (f *defaultFormats) Parse(name, data string) (interface{}, error) {
f.Lock()
defer f.Unlock()
nme := f.normalizeName(name)
for _, v := range f.data {
if v.Name == nme {
nw := reflect.New(v.Type).Interface()
if dec, ok := nw.(encoding.TextUnmarshaler); ok {
if err := dec.UnmarshalText([]byte(data));... | go | {
"resource": ""
} |
q171789 | Sequence | validation | func Sequence(filters ...Filter) Filter {
if len(filters) == 1 {
return filters[0]
}
return FilterFunc(func(arg Arg) error {
e := &filterErrors{}
in := arg.In
for _, f := range filters {
c := make(chan string, channelBuffer)
go runFilter(f, Arg{In: in, Out: c}, e)
in = c
}
for s := range in {
... | go | {
"resource": ""
} |
q171790 | Contents | validation | func Contents(filters ...Filter) ([]string, error) {
var result []string
err := ForEach(Sequence(filters...), func(s string) {
result = append(result, s)
})
if err != nil {
result = nil // Discard results on error
}
return result, err
} | go | {
"resource": ""
} |
q171791 | Items | validation | func Items(items ...string) Filter {
return FilterFunc(func(arg Arg) error {
for _, s := range items {
arg.Out <- s
}
return nil
})
} | go | {
"resource": ""
} |
q171792 | Repeat | validation | func Repeat(s string, n int) Filter {
return FilterFunc(func(arg Arg) error {
for i := 0; i < n; i++ {
arg.Out <- s
}
return nil
})
} | go | {
"resource": ""
} |
q171793 | Numbers | validation | func Numbers(x, y int) Filter {
return FilterFunc(func(arg Arg) error {
for i := x; i <= y; i++ {
arg.Out <- fmt.Sprint(i)
}
return nil
})
} | go | {
"resource": ""
} |
q171794 | Uniq | validation | func Uniq() Filter {
return FilterFunc(func(arg Arg) error {
first := true
last := ""
for s := range arg.In {
if first || last != s {
arg.Out <- s
}
last = s
first = false
}
return nil
})
} | go | {
"resource": ""
} |
q171795 | UniqWithCount | validation | func UniqWithCount() Filter {
return FilterFunc(func(arg Arg) error {
current := ""
count := 0
for s := range arg.In {
if s != current {
if count > 0 {
arg.Out <- fmt.Sprintf("%d %s", count, current)
}
count = 0
current = s
}
count++
}
if count > 0 {
arg.Out <- fmt.Sprintf("%... | go | {
"resource": ""
} |
q171796 | Reverse | validation | func Reverse() Filter {
return FilterFunc(func(arg Arg) error {
var data []string
for s := range arg.In {
data = append(data, s)
}
for i := len(data) - 1; i >= 0; i-- {
arg.Out <- data[i]
}
return nil
})
} | go | {
"resource": ""
} |
q171797 | SampleWithSeed | validation | func SampleWithSeed(n int, seed int64) Filter {
return FilterFunc(func(arg Arg) error {
// Could speed this up by using Algorithm Z from Vitter.
r := rand.New(rand.NewSource(seed))
reservoir := make([]string, 0, n)
i := 0
for s := range arg.In {
if i < n {
reservoir = append(reservoir, s)
} else {
... | go | {
"resource": ""
} |
q171798 | First | validation | func First(n int) Filter {
return FilterFunc(func(arg Arg) error {
seen := 0
for s := range arg.In {
if seen >= n {
break
}
arg.Out <- s
seen++
}
return nil
})
} | go | {
"resource": ""
} |
q171799 | Last | validation | func Last(n int) Filter {
return FilterFunc(func(arg Arg) error {
r := newRing(n)
for s := range arg.In {
r.pushBack(s)
}
for !r.empty() {
arg.Out <- r.popFront()
}
return nil
})
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.