repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
armon/go-metrics
inmem.go
Ingest
func (a *AggregateSample) Ingest(v float64, rateDenom float64) { a.Count++ a.Sum += v a.SumSq += (v * v) if v < a.Min || a.Count == 1 { a.Min = v } if v > a.Max || a.Count == 1 { a.Max = v } a.Rate = float64(a.Sum) / rateDenom a.LastUpdated = time.Now() }
go
func (a *AggregateSample) Ingest(v float64, rateDenom float64) { a.Count++ a.Sum += v a.SumSq += (v * v) if v < a.Min || a.Count == 1 { a.Min = v } if v > a.Max || a.Count == 1 { a.Max = v } a.Rate = float64(a.Sum) / rateDenom a.LastUpdated = time.Now() }
[ "func", "(", "a", "*", "AggregateSample", ")", "Ingest", "(", "v", "float64", ",", "rateDenom", "float64", ")", "{", "a", ".", "Count", "++", "\n", "a", ".", "Sum", "+=", "v", "\n", "a", ".", "SumSq", "+=", "(", "v", "*", "v", ")", "\n", "if", ...
// Ingest is used to update a sample
[ "Ingest", "is", "used", "to", "update", "a", "sample" ]
ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5
https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem.go#L100-L112
train
armon/go-metrics
inmem.go
NewInmemSink
func NewInmemSink(interval, retain time.Duration) *InmemSink { rateTimeUnit := time.Second i := &InmemSink{ interval: interval, retain: retain, maxIntervals: int(retain / interval), rateDenom: float64(interval.Nanoseconds()) / float64(rateTimeUnit.Nanoseconds()), } i.intervals = make([]*IntervalMetrics, 0, i.maxIntervals) return i }
go
func NewInmemSink(interval, retain time.Duration) *InmemSink { rateTimeUnit := time.Second i := &InmemSink{ interval: interval, retain: retain, maxIntervals: int(retain / interval), rateDenom: float64(interval.Nanoseconds()) / float64(rateTimeUnit.Nanoseconds()), } i.intervals = make([]*IntervalMetrics, 0, i.maxIntervals) return i }
[ "func", "NewInmemSink", "(", "interval", ",", "retain", "time", ".", "Duration", ")", "*", "InmemSink", "{", "rateTimeUnit", ":=", "time", ".", "Second", "\n", "i", ":=", "&", "InmemSink", "{", "interval", ":", "interval", ",", "retain", ":", "retain", "...
// NewInmemSink is used to construct a new in-memory sink. // Uses an aggregation interval and maximum retention period.
[ "NewInmemSink", "is", "used", "to", "construct", "a", "new", "in", "-", "memory", "sink", ".", "Uses", "an", "aggregation", "interval", "and", "maximum", "retention", "period", "." ]
ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5
https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem.go#L145-L155
train
armon/go-metrics
inmem.go
Data
func (i *InmemSink) Data() []*IntervalMetrics { // Get the current interval, forces creation i.getInterval() i.intervalLock.RLock() defer i.intervalLock.RUnlock() n := len(i.intervals) intervals := make([]*IntervalMetrics, n) copy(intervals[:n-1], i.intervals[:n-1]) current := i.intervals[n-1] // make its own copy for current interval intervals[n-1] = &IntervalMetrics{} copyCurrent := intervals[n-1] current.RLock() *copyCurrent = *current copyCurrent.Gauges = make(map[string]GaugeValue, len(current.Gauges)) for k, v := range current.Gauges { copyCurrent.Gauges[k] = v } // saved values will be not change, just copy its link copyCurrent.Points = make(map[string][]float32, len(current.Points)) for k, v := range current.Points { copyCurrent.Points[k] = v } copyCurrent.Counters = make(map[string]SampledValue, len(current.Counters)) for k, v := range current.Counters { copyCurrent.Counters[k] = v.deepCopy() } copyCurrent.Samples = make(map[string]SampledValue, len(current.Samples)) for k, v := range current.Samples { copyCurrent.Samples[k] = v.deepCopy() } current.RUnlock() return intervals }
go
func (i *InmemSink) Data() []*IntervalMetrics { // Get the current interval, forces creation i.getInterval() i.intervalLock.RLock() defer i.intervalLock.RUnlock() n := len(i.intervals) intervals := make([]*IntervalMetrics, n) copy(intervals[:n-1], i.intervals[:n-1]) current := i.intervals[n-1] // make its own copy for current interval intervals[n-1] = &IntervalMetrics{} copyCurrent := intervals[n-1] current.RLock() *copyCurrent = *current copyCurrent.Gauges = make(map[string]GaugeValue, len(current.Gauges)) for k, v := range current.Gauges { copyCurrent.Gauges[k] = v } // saved values will be not change, just copy its link copyCurrent.Points = make(map[string][]float32, len(current.Points)) for k, v := range current.Points { copyCurrent.Points[k] = v } copyCurrent.Counters = make(map[string]SampledValue, len(current.Counters)) for k, v := range current.Counters { copyCurrent.Counters[k] = v.deepCopy() } copyCurrent.Samples = make(map[string]SampledValue, len(current.Samples)) for k, v := range current.Samples { copyCurrent.Samples[k] = v.deepCopy() } current.RUnlock() return intervals }
[ "func", "(", "i", "*", "InmemSink", ")", "Data", "(", ")", "[", "]", "*", "IntervalMetrics", "{", "// Get the current interval, forces creation", "i", ".", "getInterval", "(", ")", "\n\n", "i", ".", "intervalLock", ".", "RLock", "(", ")", "\n", "defer", "i...
// Data is used to retrieve all the aggregated metrics // Intervals may be in use, and a read lock should be acquired
[ "Data", "is", "used", "to", "retrieve", "all", "the", "aggregated", "metrics", "Intervals", "may", "be", "in", "use", "and", "a", "read", "lock", "should", "be", "acquired" ]
ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5
https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem.go#L228-L267
train
armon/go-metrics
inmem.go
getInterval
func (i *InmemSink) getInterval() *IntervalMetrics { intv := time.Now().Truncate(i.interval) if m := i.getExistingInterval(intv); m != nil { return m } return i.createInterval(intv) }
go
func (i *InmemSink) getInterval() *IntervalMetrics { intv := time.Now().Truncate(i.interval) if m := i.getExistingInterval(intv); m != nil { return m } return i.createInterval(intv) }
[ "func", "(", "i", "*", "InmemSink", ")", "getInterval", "(", ")", "*", "IntervalMetrics", "{", "intv", ":=", "time", ".", "Now", "(", ")", ".", "Truncate", "(", "i", ".", "interval", ")", "\n", "if", "m", ":=", "i", ".", "getExistingInterval", "(", ...
// getInterval returns the current interval to write to
[ "getInterval", "returns", "the", "current", "interval", "to", "write", "to" ]
ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5
https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem.go#L304-L310
train
armon/go-metrics
inmem_endpoint.go
deepCopy
func (source *SampledValue) deepCopy() SampledValue { dest := *source if source.AggregateSample != nil { dest.AggregateSample = &AggregateSample{} *dest.AggregateSample = *source.AggregateSample } return dest }
go
func (source *SampledValue) deepCopy() SampledValue { dest := *source if source.AggregateSample != nil { dest.AggregateSample = &AggregateSample{} *dest.AggregateSample = *source.AggregateSample } return dest }
[ "func", "(", "source", "*", "SampledValue", ")", "deepCopy", "(", ")", "SampledValue", "{", "dest", ":=", "*", "source", "\n", "if", "source", ".", "AggregateSample", "!=", "nil", "{", "dest", ".", "AggregateSample", "=", "&", "AggregateSample", "{", "}", ...
// deepCopy allocates a new instance of AggregateSample
[ "deepCopy", "allocates", "a", "new", "instance", "of", "AggregateSample" ]
ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5
https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem_endpoint.go#L45-L52
train
armon/go-metrics
inmem_endpoint.go
DisplayMetrics
func (i *InmemSink) DisplayMetrics(resp http.ResponseWriter, req *http.Request) (interface{}, error) { data := i.Data() var interval *IntervalMetrics n := len(data) switch { case n == 0: return nil, fmt.Errorf("no metric intervals have been initialized yet") case n == 1: // Show the current interval if it's all we have interval = data[0] default: // Show the most recent finished interval if we have one interval = data[n-2] } interval.RLock() defer interval.RUnlock() summary := MetricsSummary{ Timestamp: interval.Interval.Round(time.Second).UTC().String(), Gauges: make([]GaugeValue, 0, len(interval.Gauges)), Points: make([]PointValue, 0, len(interval.Points)), } // Format and sort the output of each metric type, so it gets displayed in a // deterministic order. for name, points := range interval.Points { summary.Points = append(summary.Points, PointValue{name, points}) } sort.Slice(summary.Points, func(i, j int) bool { return summary.Points[i].Name < summary.Points[j].Name }) for hash, value := range interval.Gauges { value.Hash = hash value.DisplayLabels = make(map[string]string) for _, label := range value.Labels { value.DisplayLabels[label.Name] = label.Value } value.Labels = nil summary.Gauges = append(summary.Gauges, value) } sort.Slice(summary.Gauges, func(i, j int) bool { return summary.Gauges[i].Hash < summary.Gauges[j].Hash }) summary.Counters = formatSamples(interval.Counters) summary.Samples = formatSamples(interval.Samples) return summary, nil }
go
func (i *InmemSink) DisplayMetrics(resp http.ResponseWriter, req *http.Request) (interface{}, error) { data := i.Data() var interval *IntervalMetrics n := len(data) switch { case n == 0: return nil, fmt.Errorf("no metric intervals have been initialized yet") case n == 1: // Show the current interval if it's all we have interval = data[0] default: // Show the most recent finished interval if we have one interval = data[n-2] } interval.RLock() defer interval.RUnlock() summary := MetricsSummary{ Timestamp: interval.Interval.Round(time.Second).UTC().String(), Gauges: make([]GaugeValue, 0, len(interval.Gauges)), Points: make([]PointValue, 0, len(interval.Points)), } // Format and sort the output of each metric type, so it gets displayed in a // deterministic order. for name, points := range interval.Points { summary.Points = append(summary.Points, PointValue{name, points}) } sort.Slice(summary.Points, func(i, j int) bool { return summary.Points[i].Name < summary.Points[j].Name }) for hash, value := range interval.Gauges { value.Hash = hash value.DisplayLabels = make(map[string]string) for _, label := range value.Labels { value.DisplayLabels[label.Name] = label.Value } value.Labels = nil summary.Gauges = append(summary.Gauges, value) } sort.Slice(summary.Gauges, func(i, j int) bool { return summary.Gauges[i].Hash < summary.Gauges[j].Hash }) summary.Counters = formatSamples(interval.Counters) summary.Samples = formatSamples(interval.Samples) return summary, nil }
[ "func", "(", "i", "*", "InmemSink", ")", "DisplayMetrics", "(", "resp", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "data", ":=", "i", ".", "Data", "(", ")", "\n\n...
// DisplayMetrics returns a summary of the metrics from the most recent finished interval.
[ "DisplayMetrics", "returns", "a", "summary", "of", "the", "metrics", "from", "the", "most", "recent", "finished", "interval", "." ]
ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5
https://github.com/armon/go-metrics/blob/ec5e00d3c878b2a97bbe0884ef45ffd1b4f669f5/inmem_endpoint.go#L55-L107
train
levigross/grequests
session.go
NewSession
func NewSession(ro *RequestOptions) *Session { if ro == nil { ro = &RequestOptions{} } ro.UseCookieJar = true return &Session{RequestOptions: ro, HTTPClient: BuildHTTPClient(*ro)} }
go
func NewSession(ro *RequestOptions) *Session { if ro == nil { ro = &RequestOptions{} } ro.UseCookieJar = true return &Session{RequestOptions: ro, HTTPClient: BuildHTTPClient(*ro)} }
[ "func", "NewSession", "(", "ro", "*", "RequestOptions", ")", "*", "Session", "{", "if", "ro", "==", "nil", "{", "ro", "=", "&", "RequestOptions", "{", "}", "\n", "}", "\n\n", "ro", ".", "UseCookieJar", "=", "true", "\n\n", "return", "&", "Session", "...
// NewSession returns a session struct which enables can be used to maintain establish a persistent state with the // server // This function will set UseCookieJar to true as that is the purpose of using the session
[ "NewSession", "returns", "a", "session", "struct", "which", "enables", "can", "be", "used", "to", "maintain", "establish", "a", "persistent", "state", "with", "the", "server", "This", "function", "will", "set", "UseCookieJar", "to", "true", "as", "that", "is",...
37c80f76a0dae6ed656cbc830643ba53f45fc79c
https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/session.go#L18-L26
train
levigross/grequests
session.go
combineRequestOptions
func (s *Session) combineRequestOptions(ro *RequestOptions) *RequestOptions { if ro == nil { ro = &RequestOptions{} } if ro.UserAgent == "" && s.RequestOptions.UserAgent != "" { ro.UserAgent = s.RequestOptions.UserAgent } if ro.Host == "" && s.RequestOptions.Host != "" { ro.Host = s.RequestOptions.Host } if ro.Auth == nil && s.RequestOptions.Auth != nil { ro.Auth = s.RequestOptions.Auth } if len(s.RequestOptions.Headers) > 0 || len(ro.Headers) > 0 { headers := make(map[string]string) for k, v := range s.RequestOptions.Headers { headers[k] = v } for k, v := range ro.Headers { headers[k] = v } ro.Headers = headers } return ro }
go
func (s *Session) combineRequestOptions(ro *RequestOptions) *RequestOptions { if ro == nil { ro = &RequestOptions{} } if ro.UserAgent == "" && s.RequestOptions.UserAgent != "" { ro.UserAgent = s.RequestOptions.UserAgent } if ro.Host == "" && s.RequestOptions.Host != "" { ro.Host = s.RequestOptions.Host } if ro.Auth == nil && s.RequestOptions.Auth != nil { ro.Auth = s.RequestOptions.Auth } if len(s.RequestOptions.Headers) > 0 || len(ro.Headers) > 0 { headers := make(map[string]string) for k, v := range s.RequestOptions.Headers { headers[k] = v } for k, v := range ro.Headers { headers[k] = v } ro.Headers = headers } return ro }
[ "func", "(", "s", "*", "Session", ")", "combineRequestOptions", "(", "ro", "*", "RequestOptions", ")", "*", "RequestOptions", "{", "if", "ro", "==", "nil", "{", "ro", "=", "&", "RequestOptions", "{", "}", "\n", "}", "\n\n", "if", "ro", ".", "UserAgent"...
// Combine session options and request options // 1. UserAgent // 2. Host // 3. Auth // 4. Headers
[ "Combine", "session", "options", "and", "request", "options", "1", ".", "UserAgent", "2", ".", "Host", "3", ".", "Auth", "4", ".", "Headers" ]
37c80f76a0dae6ed656cbc830643ba53f45fc79c
https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/session.go#L33-L61
train
levigross/grequests
request.go
DoRegularRequest
func DoRegularRequest(requestVerb, url string, ro *RequestOptions) (*Response, error) { return buildResponse(buildRequest(requestVerb, url, ro, nil)) }
go
func DoRegularRequest(requestVerb, url string, ro *RequestOptions) (*Response, error) { return buildResponse(buildRequest(requestVerb, url, ro, nil)) }
[ "func", "DoRegularRequest", "(", "requestVerb", ",", "url", "string", ",", "ro", "*", "RequestOptions", ")", "(", "*", "Response", ",", "error", ")", "{", "return", "buildResponse", "(", "buildRequest", "(", "requestVerb", ",", "url", ",", "ro", ",", "nil"...
// DoRegularRequest adds generic test functionality
[ "DoRegularRequest", "adds", "generic", "test", "functionality" ]
37c80f76a0dae6ed656cbc830643ba53f45fc79c
https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/request.go#L144-L146
train
levigross/grequests
request.go
buildRequest
func buildRequest(httpMethod, url string, ro *RequestOptions, httpClient *http.Client) (*http.Response, error) { if ro == nil { ro = &RequestOptions{} } if ro.CookieJar != nil { ro.UseCookieJar = true } // Create our own HTTP client if httpClient == nil { httpClient = BuildHTTPClient(*ro) } var err error // we don't want to shadow url so we won't use := switch { case len(ro.Params) != 0: if url, err = buildURLParams(url, ro.Params); err != nil { return nil, err } case ro.QueryStruct != nil: if url, err = buildURLStruct(url, ro.QueryStruct); err != nil { return nil, err } } // Build the request req, err := buildHTTPRequest(httpMethod, url, ro) if err != nil { return nil, err } // Do we need to add any HTTP headers or Basic Auth? addHTTPHeaders(ro, req) addCookies(ro, req) addRedirectFunctionality(httpClient, ro) if ro.Context != nil { req = req.WithContext(ro.Context) } if ro.BeforeRequest != nil { if err := ro.BeforeRequest(req); err != nil { return nil, err } } return httpClient.Do(req) }
go
func buildRequest(httpMethod, url string, ro *RequestOptions, httpClient *http.Client) (*http.Response, error) { if ro == nil { ro = &RequestOptions{} } if ro.CookieJar != nil { ro.UseCookieJar = true } // Create our own HTTP client if httpClient == nil { httpClient = BuildHTTPClient(*ro) } var err error // we don't want to shadow url so we won't use := switch { case len(ro.Params) != 0: if url, err = buildURLParams(url, ro.Params); err != nil { return nil, err } case ro.QueryStruct != nil: if url, err = buildURLStruct(url, ro.QueryStruct); err != nil { return nil, err } } // Build the request req, err := buildHTTPRequest(httpMethod, url, ro) if err != nil { return nil, err } // Do we need to add any HTTP headers or Basic Auth? addHTTPHeaders(ro, req) addCookies(ro, req) addRedirectFunctionality(httpClient, ro) if ro.Context != nil { req = req.WithContext(ro.Context) } if ro.BeforeRequest != nil { if err := ro.BeforeRequest(req); err != nil { return nil, err } } return httpClient.Do(req) }
[ "func", "buildRequest", "(", "httpMethod", ",", "url", "string", ",", "ro", "*", "RequestOptions", ",", "httpClient", "*", "http", ".", "Client", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "if", "ro", "==", "nil", "{", "ro", "=",...
// buildRequest is where most of the magic happens for request processing
[ "buildRequest", "is", "where", "most", "of", "the", "magic", "happens", "for", "request", "processing" ]
37c80f76a0dae6ed656cbc830643ba53f45fc79c
https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/request.go#L159-L210
train
levigross/grequests
request.go
BuildHTTPClient
func BuildHTTPClient(ro RequestOptions) *http.Client { if ro.HTTPClient != nil { return ro.HTTPClient } // Does the user want to change the defaults? if !ro.dontUseDefaultClient() { return http.DefaultClient } // Using the user config for tls timeout or default if ro.TLSHandshakeTimeout == 0 { ro.TLSHandshakeTimeout = tlsHandshakeTimeout } // Using the user config for dial timeout or default if ro.DialTimeout == 0 { ro.DialTimeout = dialTimeout } // Using the user config for dial keep alive or default if ro.DialKeepAlive == 0 { ro.DialKeepAlive = dialKeepAlive } if ro.RequestTimeout == 0 { ro.RequestTimeout = requestTimeout } var cookieJar http.CookieJar if ro.UseCookieJar { if ro.CookieJar != nil { cookieJar = ro.CookieJar } else { // The function does not return an error ever... so we are just ignoring it cookieJar, _ = cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) } } return &http.Client{ Jar: cookieJar, Transport: createHTTPTransport(ro), Timeout: ro.RequestTimeout, } }
go
func BuildHTTPClient(ro RequestOptions) *http.Client { if ro.HTTPClient != nil { return ro.HTTPClient } // Does the user want to change the defaults? if !ro.dontUseDefaultClient() { return http.DefaultClient } // Using the user config for tls timeout or default if ro.TLSHandshakeTimeout == 0 { ro.TLSHandshakeTimeout = tlsHandshakeTimeout } // Using the user config for dial timeout or default if ro.DialTimeout == 0 { ro.DialTimeout = dialTimeout } // Using the user config for dial keep alive or default if ro.DialKeepAlive == 0 { ro.DialKeepAlive = dialKeepAlive } if ro.RequestTimeout == 0 { ro.RequestTimeout = requestTimeout } var cookieJar http.CookieJar if ro.UseCookieJar { if ro.CookieJar != nil { cookieJar = ro.CookieJar } else { // The function does not return an error ever... so we are just ignoring it cookieJar, _ = cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) } } return &http.Client{ Jar: cookieJar, Transport: createHTTPTransport(ro), Timeout: ro.RequestTimeout, } }
[ "func", "BuildHTTPClient", "(", "ro", "RequestOptions", ")", "*", "http", ".", "Client", "{", "if", "ro", ".", "HTTPClient", "!=", "nil", "{", "return", "ro", ".", "HTTPClient", "\n", "}", "\n\n", "// Does the user want to change the defaults?", "if", "!", "ro...
// BuildHTTPClient is a function that will return a custom HTTP client based on the request options provided // the check is in UseDefaultClient
[ "BuildHTTPClient", "is", "a", "function", "that", "will", "return", "a", "custom", "HTTP", "client", "based", "on", "the", "request", "options", "provided", "the", "check", "is", "in", "UseDefaultClient" ]
37c80f76a0dae6ed656cbc830643ba53f45fc79c
https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/request.go#L456-L502
train
levigross/grequests
response.go
Read
func (r *Response) Read(p []byte) (n int, err error) { if r.Error != nil { return -1, r.Error } return r.RawResponse.Body.Read(p) }
go
func (r *Response) Read(p []byte) (n int, err error) { if r.Error != nil { return -1, r.Error } return r.RawResponse.Body.Read(p) }
[ "func", "(", "r", "*", "Response", ")", "Read", "(", "p", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "if", "r", ".", "Error", "!=", "nil", "{", "return", "-", "1", ",", "r", ".", "Error", "\n", "}", "\n\n", "retu...
// Read is part of our ability to support io.ReadCloser if someone wants to make use of the raw body
[ "Read", "is", "part", "of", "our", "ability", "to", "support", "io", ".", "ReadCloser", "if", "someone", "wants", "to", "make", "use", "of", "the", "raw", "body" ]
37c80f76a0dae6ed656cbc830643ba53f45fc79c
https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/response.go#L55-L62
train
levigross/grequests
response.go
Close
func (r *Response) Close() error { if r.Error != nil { return r.Error } io.Copy(ioutil.Discard, r) return r.RawResponse.Body.Close() }
go
func (r *Response) Close() error { if r.Error != nil { return r.Error } io.Copy(ioutil.Discard, r) return r.RawResponse.Body.Close() }
[ "func", "(", "r", "*", "Response", ")", "Close", "(", ")", "error", "{", "if", "r", ".", "Error", "!=", "nil", "{", "return", "r", ".", "Error", "\n", "}", "\n\n", "io", ".", "Copy", "(", "ioutil", ".", "Discard", ",", "r", ")", "\n\n", "return...
// Close is part of our ability to support io.ReadCloser if someone wants to make use of the raw body
[ "Close", "is", "part", "of", "our", "ability", "to", "support", "io", ".", "ReadCloser", "if", "someone", "wants", "to", "make", "use", "of", "the", "raw", "body" ]
37c80f76a0dae6ed656cbc830643ba53f45fc79c
https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/response.go#L65-L74
train
levigross/grequests
response.go
DownloadToFile
func (r *Response) DownloadToFile(fileName string) error { if r.Error != nil { return r.Error } fd, err := os.Create(fileName) if err != nil { return err } defer r.Close() // This is a noop if we use the internal ByteBuffer defer fd.Close() if _, err := io.Copy(fd, r.getInternalReader()); err != nil && err != io.EOF { return err } return nil }
go
func (r *Response) DownloadToFile(fileName string) error { if r.Error != nil { return r.Error } fd, err := os.Create(fileName) if err != nil { return err } defer r.Close() // This is a noop if we use the internal ByteBuffer defer fd.Close() if _, err := io.Copy(fd, r.getInternalReader()); err != nil && err != io.EOF { return err } return nil }
[ "func", "(", "r", "*", "Response", ")", "DownloadToFile", "(", "fileName", "string", ")", "error", "{", "if", "r", ".", "Error", "!=", "nil", "{", "return", "r", ".", "Error", "\n", "}", "\n\n", "fd", ",", "err", ":=", "os", ".", "Create", "(", "...
// DownloadToFile allows you to download the contents of the response to a file
[ "DownloadToFile", "allows", "you", "to", "download", "the", "contents", "of", "the", "response", "to", "a", "file" ]
37c80f76a0dae6ed656cbc830643ba53f45fc79c
https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/response.go#L77-L97
train
levigross/grequests
response.go
JSON
func (r *Response) JSON(userStruct interface{}) error { if r.Error != nil { return r.Error } jsonDecoder := json.NewDecoder(r.getInternalReader()) defer r.Close() return jsonDecoder.Decode(&userStruct) }
go
func (r *Response) JSON(userStruct interface{}) error { if r.Error != nil { return r.Error } jsonDecoder := json.NewDecoder(r.getInternalReader()) defer r.Close() return jsonDecoder.Decode(&userStruct) }
[ "func", "(", "r", "*", "Response", ")", "JSON", "(", "userStruct", "interface", "{", "}", ")", "error", "{", "if", "r", ".", "Error", "!=", "nil", "{", "return", "r", ".", "Error", "\n", "}", "\n\n", "jsonDecoder", ":=", "json", ".", "NewDecoder", ...
// JSON is a method that will populate a struct that is provided `userStruct` with the JSON returned within the // response body
[ "JSON", "is", "a", "method", "that", "will", "populate", "a", "struct", "that", "is", "provided", "userStruct", "with", "the", "JSON", "returned", "within", "the", "response", "body" ]
37c80f76a0dae6ed656cbc830643ba53f45fc79c
https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/response.go#L130-L140
train
levigross/grequests
response.go
String
func (r *Response) String() string { if r.Error != nil { return "" } r.populateResponseByteBuffer() return r.internalByteBuffer.String() }
go
func (r *Response) String() string { if r.Error != nil { return "" } r.populateResponseByteBuffer() return r.internalByteBuffer.String() }
[ "func", "(", "r", "*", "Response", ")", "String", "(", ")", "string", "{", "if", "r", ".", "Error", "!=", "nil", "{", "return", "\"", "\"", "\n", "}", "\n\n", "r", ".", "populateResponseByteBuffer", "(", ")", "\n\n", "return", "r", ".", "internalByte...
// String returns the response as a string
[ "String", "returns", "the", "response", "as", "a", "string" ]
37c80f76a0dae6ed656cbc830643ba53f45fc79c
https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/response.go#L188-L196
train
levigross/grequests
file_upload.go
FileUploadFromDisk
func FileUploadFromDisk(fileName string) ([]FileUpload, error) { fd, err := os.Open(fileName) if err != nil { return nil, err } return []FileUpload{{FileContents: fd, FileName: fileName}}, nil }
go
func FileUploadFromDisk(fileName string) ([]FileUpload, error) { fd, err := os.Open(fileName) if err != nil { return nil, err } return []FileUpload{{FileContents: fd, FileName: fileName}}, nil }
[ "func", "FileUploadFromDisk", "(", "fileName", "string", ")", "(", "[", "]", "FileUpload", ",", "error", ")", "{", "fd", ",", "err", ":=", "os", ".", "Open", "(", "fileName", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", ...
// FileUploadFromDisk allows you to create a FileUpload struct slice by just specifying a location on the disk
[ "FileUploadFromDisk", "allows", "you", "to", "create", "a", "FileUpload", "struct", "slice", "by", "just", "specifying", "a", "location", "on", "the", "disk" ]
37c80f76a0dae6ed656cbc830643ba53f45fc79c
https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/file_upload.go#L28-L37
train
levigross/grequests
file_upload.go
FileUploadFromGlob
func FileUploadFromGlob(fileSystemGlob string) ([]FileUpload, error) { files, err := filepath.Glob(fileSystemGlob) if err != nil { return nil, err } if len(files) == 0 { return nil, errors.New("grequests: No files have been returned in the glob") } filesToUpload := make([]FileUpload, 0, len(files)) for _, f := range files { if s, err := os.Stat(f); err != nil || s.IsDir() { continue } // ignoring error because I can stat the file fd, _ := os.Open(f) filesToUpload = append(filesToUpload, FileUpload{FileContents: fd, FileName: filepath.Base(fd.Name())}) } return filesToUpload, nil }
go
func FileUploadFromGlob(fileSystemGlob string) ([]FileUpload, error) { files, err := filepath.Glob(fileSystemGlob) if err != nil { return nil, err } if len(files) == 0 { return nil, errors.New("grequests: No files have been returned in the glob") } filesToUpload := make([]FileUpload, 0, len(files)) for _, f := range files { if s, err := os.Stat(f); err != nil || s.IsDir() { continue } // ignoring error because I can stat the file fd, _ := os.Open(f) filesToUpload = append(filesToUpload, FileUpload{FileContents: fd, FileName: filepath.Base(fd.Name())}) } return filesToUpload, nil }
[ "func", "FileUploadFromGlob", "(", "fileSystemGlob", "string", ")", "(", "[", "]", "FileUpload", ",", "error", ")", "{", "files", ",", "err", ":=", "filepath", ".", "Glob", "(", "fileSystemGlob", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil...
// FileUploadFromGlob allows you to create a FileUpload struct slice by just specifying a glob location on the disk // this function will gloss over all errors in the files and only upload the files that don't return errors from the glob
[ "FileUploadFromGlob", "allows", "you", "to", "create", "a", "FileUpload", "struct", "slice", "by", "just", "specifying", "a", "glob", "location", "on", "the", "disk", "this", "function", "will", "gloss", "over", "all", "errors", "in", "the", "files", "and", ...
37c80f76a0dae6ed656cbc830643ba53f45fc79c
https://github.com/levigross/grequests/blob/37c80f76a0dae6ed656cbc830643ba53f45fc79c/file_upload.go#L41-L68
train
ahmetb/go-linq
orderby.go
OrderBy
func (q Query) OrderBy(selector func(interface{}) interface{}) OrderedQuery { return OrderedQuery{ orders: []order{{selector: selector}}, original: q, Query: Query{ Iterate: func() Iterator { items := q.sort([]order{{selector: selector}}) len := len(items) index := 0 return func() (item interface{}, ok bool) { ok = index < len if ok { item = items[index] index++ } return } }, }, } }
go
func (q Query) OrderBy(selector func(interface{}) interface{}) OrderedQuery { return OrderedQuery{ orders: []order{{selector: selector}}, original: q, Query: Query{ Iterate: func() Iterator { items := q.sort([]order{{selector: selector}}) len := len(items) index := 0 return func() (item interface{}, ok bool) { ok = index < len if ok { item = items[index] index++ } return } }, }, } }
[ "func", "(", "q", "Query", ")", "OrderBy", "(", "selector", "func", "(", "interface", "{", "}", ")", "interface", "{", "}", ")", "OrderedQuery", "{", "return", "OrderedQuery", "{", "orders", ":", "[", "]", "order", "{", "{", "selector", ":", "selector"...
// OrderBy sorts the elements of a collection in ascending order. Elements are // sorted according to a key.
[ "OrderBy", "sorts", "the", "elements", "of", "a", "collection", "in", "ascending", "order", ".", "Elements", "are", "sorted", "according", "to", "a", "key", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/orderby.go#L21-L43
train
ahmetb/go-linq
orderby.go
ThenByDescending
func (oq OrderedQuery) ThenByDescending(selector func(interface{}) interface{}) OrderedQuery { return OrderedQuery{ orders: append(oq.orders, order{selector: selector, desc: true}), original: oq.original, Query: Query{ Iterate: func() Iterator { items := oq.original.sort(append(oq.orders, order{selector: selector, desc: true})) len := len(items) index := 0 return func() (item interface{}, ok bool) { ok = index < len if ok { item = items[index] index++ } return } }, }, } }
go
func (oq OrderedQuery) ThenByDescending(selector func(interface{}) interface{}) OrderedQuery { return OrderedQuery{ orders: append(oq.orders, order{selector: selector, desc: true}), original: oq.original, Query: Query{ Iterate: func() Iterator { items := oq.original.sort(append(oq.orders, order{selector: selector, desc: true})) len := len(items) index := 0 return func() (item interface{}, ok bool) { ok = index < len if ok { item = items[index] index++ } return } }, }, } }
[ "func", "(", "oq", "OrderedQuery", ")", "ThenByDescending", "(", "selector", "func", "(", "interface", "{", "}", ")", "interface", "{", "}", ")", "OrderedQuery", "{", "return", "OrderedQuery", "{", "orders", ":", "append", "(", "oq", ".", "orders", ",", ...
// ThenByDescending performs a subsequent ordering of the elements in a // collection in descending order. This method enables you to specify multiple // sort criteria by applying any number of ThenBy or ThenByDescending methods.
[ "ThenByDescending", "performs", "a", "subsequent", "ordering", "of", "the", "elements", "in", "a", "collection", "in", "descending", "order", ".", "This", "method", "enables", "you", "to", "specify", "multiple", "sort", "criteria", "by", "applying", "any", "numb...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/orderby.go#L161-L183
train
ahmetb/go-linq
orderby.go
Sort
func (q Query) Sort(less func(i, j interface{}) bool) Query { return Query{ Iterate: func() Iterator { items := q.lessSort(less) len := len(items) index := 0 return func() (item interface{}, ok bool) { ok = index < len if ok { item = items[index] index++ } return } }, } }
go
func (q Query) Sort(less func(i, j interface{}) bool) Query { return Query{ Iterate: func() Iterator { items := q.lessSort(less) len := len(items) index := 0 return func() (item interface{}, ok bool) { ok = index < len if ok { item = items[index] index++ } return } }, } }
[ "func", "(", "q", "Query", ")", "Sort", "(", "less", "func", "(", "i", ",", "j", "interface", "{", "}", ")", "bool", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "items", ":=", "q", ".", "lessSort"...
// Sort returns a new query by sorting elements with provided less function in // ascending order. The comparer function should return true if the parameter i // is less than j. While this method is uglier than chaining OrderBy, // OrderByDescending, ThenBy and ThenByDescending methods, it's performance is // much better.
[ "Sort", "returns", "a", "new", "query", "by", "sorting", "elements", "with", "provided", "less", "function", "in", "ascending", "order", ".", "The", "comparer", "function", "should", "return", "true", "if", "the", "parameter", "i", "is", "less", "than", "j",...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/orderby.go#L211-L229
train
ahmetb/go-linq
join.go
Join
func (q Query) Join(inner Query, outerKeySelector func(interface{}) interface{}, innerKeySelector func(interface{}) interface{}, resultSelector func(outer interface{}, inner interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { outernext := q.Iterate() innernext := inner.Iterate() innerLookup := make(map[interface{}][]interface{}) for innerItem, ok := innernext(); ok; innerItem, ok = innernext() { innerKey := innerKeySelector(innerItem) innerLookup[innerKey] = append(innerLookup[innerKey], innerItem) } var outerItem interface{} var innerGroup []interface{} innerLen, innerIndex := 0, 0 return func() (item interface{}, ok bool) { if innerIndex >= innerLen { has := false for !has { outerItem, ok = outernext() if !ok { return } innerGroup, has = innerLookup[outerKeySelector(outerItem)] innerLen = len(innerGroup) innerIndex = 0 } } item = resultSelector(outerItem, innerGroup[innerIndex]) innerIndex++ return item, true } }, } }
go
func (q Query) Join(inner Query, outerKeySelector func(interface{}) interface{}, innerKeySelector func(interface{}) interface{}, resultSelector func(outer interface{}, inner interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { outernext := q.Iterate() innernext := inner.Iterate() innerLookup := make(map[interface{}][]interface{}) for innerItem, ok := innernext(); ok; innerItem, ok = innernext() { innerKey := innerKeySelector(innerItem) innerLookup[innerKey] = append(innerLookup[innerKey], innerItem) } var outerItem interface{} var innerGroup []interface{} innerLen, innerIndex := 0, 0 return func() (item interface{}, ok bool) { if innerIndex >= innerLen { has := false for !has { outerItem, ok = outernext() if !ok { return } innerGroup, has = innerLookup[outerKeySelector(outerItem)] innerLen = len(innerGroup) innerIndex = 0 } } item = resultSelector(outerItem, innerGroup[innerIndex]) innerIndex++ return item, true } }, } }
[ "func", "(", "q", "Query", ")", "Join", "(", "inner", "Query", ",", "outerKeySelector", "func", "(", "interface", "{", "}", ")", "interface", "{", "}", ",", "innerKeySelector", "func", "(", "interface", "{", "}", ")", "interface", "{", "}", ",", "resul...
// Join correlates the elements of two collection based on matching keys. // // A join refers to the operation of correlating the elements of two sources of // information based on a common key. Join brings the two information sources // and the keys by which they are matched together in one method call. This // differs from the use of SelectMany, which requires more than one method call // to perform the same operation. // // Join preserves the order of the elements of outer collection, and for each of // these elements, the order of the matching elements of inner.
[ "Join", "correlates", "the", "elements", "of", "two", "collection", "based", "on", "matching", "keys", ".", "A", "join", "refers", "to", "the", "operation", "of", "correlating", "the", "elements", "of", "two", "sources", "of", "information", "based", "on", "...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/join.go#L13-L54
train
ahmetb/go-linq
skip.go
Skip
func (q Query) Skip(count int) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() n := count return func() (item interface{}, ok bool) { for ; n > 0; n-- { item, ok = next() if !ok { return } } return next() } }, } }
go
func (q Query) Skip(count int) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() n := count return func() (item interface{}, ok bool) { for ; n > 0; n-- { item, ok = next() if !ok { return } } return next() } }, } }
[ "func", "(", "q", "Query", ")", "Skip", "(", "count", "int", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n", "n", ":=", "count", "\n\n", "return", "f...
// Skip bypasses a specified number of elements in a collection and then returns // the remaining elements.
[ "Skip", "bypasses", "a", "specified", "number", "of", "elements", "in", "a", "collection", "and", "then", "returns", "the", "remaining", "elements", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/skip.go#L5-L23
train
ahmetb/go-linq
skip.go
SkipWhile
func (q Query) SkipWhile(predicate func(interface{}) bool) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() ready := false return func() (item interface{}, ok bool) { for !ready { item, ok = next() if !ok { return } ready = !predicate(item) if ready { return } } return next() } }, } }
go
func (q Query) SkipWhile(predicate func(interface{}) bool) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() ready := false return func() (item interface{}, ok bool) { for !ready { item, ok = next() if !ok { return } ready = !predicate(item) if ready { return } } return next() } }, } }
[ "func", "(", "q", "Query", ")", "SkipWhile", "(", "predicate", "func", "(", "interface", "{", "}", ")", "bool", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", "Iterate", "(", ")...
// SkipWhile bypasses elements in a collection as long as a specified condition // is true and then returns the remaining elements. // // This method tests each element by using predicate and skips the element if // the result is true. After the predicate function returns false for an // element, that element and the remaining elements in source are returned and // there are no more invocations of predicate.
[ "SkipWhile", "bypasses", "elements", "in", "a", "collection", "as", "long", "as", "a", "specified", "condition", "is", "true", "and", "then", "returns", "the", "remaining", "elements", ".", "This", "method", "tests", "each", "element", "by", "using", "predicat...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/skip.go#L32-L55
train
ahmetb/go-linq
skip.go
SkipWhileIndexed
func (q Query) SkipWhileIndexed(predicate func(int, interface{}) bool) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() ready := false index := 0 return func() (item interface{}, ok bool) { for !ready { item, ok = next() if !ok { return } ready = !predicate(index, item) if ready { return } index++ } return next() } }, } }
go
func (q Query) SkipWhileIndexed(predicate func(int, interface{}) bool) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() ready := false index := 0 return func() (item interface{}, ok bool) { for !ready { item, ok = next() if !ok { return } ready = !predicate(index, item) if ready { return } index++ } return next() } }, } }
[ "func", "(", "q", "Query", ")", "SkipWhileIndexed", "(", "predicate", "func", "(", "int", ",", "interface", "{", "}", ")", "bool", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", ...
// SkipWhileIndexed bypasses elements in a collection as long as a specified // condition is true and then returns the remaining elements. The element's // index is used in the logic of the predicate function. // // This method tests each element by using predicate and skips the element if // the result is true. After the predicate function returns false for an // element, that element and the remaining elements in source are returned and // there are no more invocations of predicate.
[ "SkipWhileIndexed", "bypasses", "elements", "in", "a", "collection", "as", "long", "as", "a", "specified", "condition", "is", "true", "and", "then", "returns", "the", "remaining", "elements", ".", "The", "element", "s", "index", "is", "used", "in", "the", "l...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/skip.go#L87-L113
train
ahmetb/go-linq
take.go
TakeWhile
func (q Query) TakeWhile(predicate func(interface{}) bool) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() done := false return func() (item interface{}, ok bool) { if done { return } item, ok = next() if !ok { done = true return } if predicate(item) { return } done = true return nil, false } }, } }
go
func (q Query) TakeWhile(predicate func(interface{}) bool) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() done := false return func() (item interface{}, ok bool) { if done { return } item, ok = next() if !ok { done = true return } if predicate(item) { return } done = true return nil, false } }, } }
[ "func", "(", "q", "Query", ")", "TakeWhile", "(", "predicate", "func", "(", "interface", "{", "}", ")", "bool", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", "Iterate", "(", ")...
// TakeWhile returns elements from a collection as long as a specified condition // is true, and then skips the remaining elements.
[ "TakeWhile", "returns", "elements", "from", "a", "collection", "as", "long", "as", "a", "specified", "condition", "is", "true", "and", "then", "skips", "the", "remaining", "elements", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/take.go#L25-L51
train
ahmetb/go-linq
take.go
TakeWhileIndexed
func (q Query) TakeWhileIndexed(predicate func(int, interface{}) bool) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() done := false index := 0 return func() (item interface{}, ok bool) { if done { return } item, ok = next() if !ok { done = true return } if predicate(index, item) { index++ return } done = true return nil, false } }, } }
go
func (q Query) TakeWhileIndexed(predicate func(int, interface{}) bool) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() done := false index := 0 return func() (item interface{}, ok bool) { if done { return } item, ok = next() if !ok { done = true return } if predicate(index, item) { index++ return } done = true return nil, false } }, } }
[ "func", "(", "q", "Query", ")", "TakeWhileIndexed", "(", "predicate", "func", "(", "int", ",", "interface", "{", "}", ")", "bool", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", ...
// TakeWhileIndexed returns elements from a collection as long as a specified // condition is true. The element's index is used in the logic of the predicate // function. The first argument of predicate represents the zero-based index of // the element within collection. The second argument represents the element to // test.
[ "TakeWhileIndexed", "returns", "elements", "from", "a", "collection", "as", "long", "as", "a", "specified", "condition", "is", "true", ".", "The", "element", "s", "index", "is", "used", "in", "the", "logic", "of", "the", "predicate", "function", ".", "The", ...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/take.go#L80-L108
train
ahmetb/go-linq
except.go
Except
func (q Query) Except(q2 Query) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() next2 := q2.Iterate() set := make(map[interface{}]bool) for i, ok := next2(); ok; i, ok = next2() { set[i] = true } return func() (item interface{}, ok bool) { for item, ok = next(); ok; item, ok = next() { if _, has := set[item]; !has { return } } return } }, } }
go
func (q Query) Except(q2 Query) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() next2 := q2.Iterate() set := make(map[interface{}]bool) for i, ok := next2(); ok; i, ok = next2() { set[i] = true } return func() (item interface{}, ok bool) { for item, ok = next(); ok; item, ok = next() { if _, has := set[item]; !has { return } } return } }, } }
[ "func", "(", "q", "Query", ")", "Except", "(", "q2", "Query", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n\n", "next2", ":=", "q2", ".", "Iterate", ...
// Except produces the set difference of two sequences. The set difference is // the members of the first sequence that don't appear in the second sequence.
[ "Except", "produces", "the", "set", "difference", "of", "two", "sequences", ".", "The", "set", "difference", "is", "the", "members", "of", "the", "first", "sequence", "that", "don", "t", "appear", "in", "the", "second", "sequence", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/except.go#L5-L27
train
ahmetb/go-linq
selectmany.go
SelectMany
func (q Query) SelectMany(selector func(interface{}) Query) Query { return Query{ Iterate: func() Iterator { outernext := q.Iterate() var inner interface{} var innernext Iterator return func() (item interface{}, ok bool) { for !ok { if inner == nil { inner, ok = outernext() if !ok { return } innernext = selector(inner).Iterate() } item, ok = innernext() if !ok { inner = nil } } return } }, } }
go
func (q Query) SelectMany(selector func(interface{}) Query) Query { return Query{ Iterate: func() Iterator { outernext := q.Iterate() var inner interface{} var innernext Iterator return func() (item interface{}, ok bool) { for !ok { if inner == nil { inner, ok = outernext() if !ok { return } innernext = selector(inner).Iterate() } item, ok = innernext() if !ok { inner = nil } } return } }, } }
[ "func", "(", "q", "Query", ")", "SelectMany", "(", "selector", "func", "(", "interface", "{", "}", ")", "Query", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "outernext", ":=", "q", ".", "Iterate", "("...
// SelectMany projects each element of a collection to a Query, iterates and // flattens the resulting collection into one collection.
[ "SelectMany", "projects", "each", "element", "of", "a", "collection", "to", "a", "Query", "iterates", "and", "flattens", "the", "resulting", "collection", "into", "one", "collection", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/selectmany.go#L5-L33
train
ahmetb/go-linq
selectmany.go
SelectManyIndexed
func (q Query) SelectManyIndexed(selector func(int, interface{}) Query) Query { return Query{ Iterate: func() Iterator { outernext := q.Iterate() index := 0 var inner interface{} var innernext Iterator return func() (item interface{}, ok bool) { for !ok { if inner == nil { inner, ok = outernext() if !ok { return } innernext = selector(index, inner).Iterate() index++ } item, ok = innernext() if !ok { inner = nil } } return } }, } }
go
func (q Query) SelectManyIndexed(selector func(int, interface{}) Query) Query { return Query{ Iterate: func() Iterator { outernext := q.Iterate() index := 0 var inner interface{} var innernext Iterator return func() (item interface{}, ok bool) { for !ok { if inner == nil { inner, ok = outernext() if !ok { return } innernext = selector(index, inner).Iterate() index++ } item, ok = innernext() if !ok { inner = nil } } return } }, } }
[ "func", "(", "q", "Query", ")", "SelectManyIndexed", "(", "selector", "func", "(", "int", ",", "interface", "{", "}", ")", "Query", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "outernext", ":=", "q", ...
// SelectManyIndexed projects each element of a collection to a Query, iterates // and flattens the resulting collection into one collection. // // The first argument to selector represents the zero-based index of that // element in the source collection. This can be useful if the elements are in a // known order and you want to do something with an element at a particular // index, for example. It can also be useful if you want to retrieve the index // of one or more elements. The second argument to selector represents the // element to process.
[ "SelectManyIndexed", "projects", "each", "element", "of", "a", "collection", "to", "a", "Query", "iterates", "and", "flattens", "the", "resulting", "collection", "into", "one", "collection", ".", "The", "first", "argument", "to", "selector", "represents", "the", ...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/selectmany.go#L66-L96
train
ahmetb/go-linq
selectmany.go
SelectManyBy
func (q Query) SelectManyBy(selector func(interface{}) Query, resultSelector func(interface{}, interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { outernext := q.Iterate() var outer interface{} var innernext Iterator return func() (item interface{}, ok bool) { for !ok { if outer == nil { outer, ok = outernext() if !ok { return } innernext = selector(outer).Iterate() } item, ok = innernext() if !ok { outer = nil } } item = resultSelector(item, outer) return } }, } }
go
func (q Query) SelectManyBy(selector func(interface{}) Query, resultSelector func(interface{}, interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { outernext := q.Iterate() var outer interface{} var innernext Iterator return func() (item interface{}, ok bool) { for !ok { if outer == nil { outer, ok = outernext() if !ok { return } innernext = selector(outer).Iterate() } item, ok = innernext() if !ok { outer = nil } } item = resultSelector(item, outer) return } }, } }
[ "func", "(", "q", "Query", ")", "SelectManyBy", "(", "selector", "func", "(", "interface", "{", "}", ")", "Query", ",", "resultSelector", "func", "(", "interface", "{", "}", ",", "interface", "{", "}", ")", "interface", "{", "}", ")", "Query", "{", "...
// SelectManyBy projects each element of a collection to a Query, iterates and // flattens the resulting collection into one collection, and invokes a result // selector function on each element therein.
[ "SelectManyBy", "projects", "each", "element", "of", "a", "collection", "to", "a", "Query", "iterates", "and", "flattens", "the", "resulting", "collection", "into", "one", "collection", "and", "invokes", "a", "result", "selector", "function", "on", "each", "elem...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/selectmany.go#L123-L154
train
ahmetb/go-linq
selectmany.go
SelectManyByIndexed
func (q Query) SelectManyByIndexed(selector func(int, interface{}) Query, resultSelector func(interface{}, interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { outernext := q.Iterate() index := 0 var outer interface{} var innernext Iterator return func() (item interface{}, ok bool) { for !ok { if outer == nil { outer, ok = outernext() if !ok { return } innernext = selector(index, outer).Iterate() index++ } item, ok = innernext() if !ok { outer = nil } } item = resultSelector(item, outer) return } }, } }
go
func (q Query) SelectManyByIndexed(selector func(int, interface{}) Query, resultSelector func(interface{}, interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { outernext := q.Iterate() index := 0 var outer interface{} var innernext Iterator return func() (item interface{}, ok bool) { for !ok { if outer == nil { outer, ok = outernext() if !ok { return } innernext = selector(index, outer).Iterate() index++ } item, ok = innernext() if !ok { outer = nil } } item = resultSelector(item, outer) return } }, } }
[ "func", "(", "q", "Query", ")", "SelectManyByIndexed", "(", "selector", "func", "(", "int", ",", "interface", "{", "}", ")", "Query", ",", "resultSelector", "func", "(", "interface", "{", "}", ",", "interface", "{", "}", ")", "interface", "{", "}", ")"...
// SelectManyByIndexed projects each element of a collection to a Query, // iterates and flattens the resulting collection into one collection, and // invokes a result selector function on each element therein. The index of each // source element is used in the intermediate projected form of that element.
[ "SelectManyByIndexed", "projects", "each", "element", "of", "a", "collection", "to", "a", "Query", "iterates", "and", "flattens", "the", "resulting", "collection", "into", "one", "collection", "and", "invokes", "a", "result", "selector", "function", "on", "each", ...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/selectmany.go#L196-L229
train
ahmetb/go-linq
where.go
Where
func (q Query) Where(predicate func(interface{}) bool) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() return func() (item interface{}, ok bool) { for item, ok = next(); ok; item, ok = next() { if predicate(item) { return } } return } }, } }
go
func (q Query) Where(predicate func(interface{}) bool) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() return func() (item interface{}, ok bool) { for item, ok = next(); ok; item, ok = next() { if predicate(item) { return } } return } }, } }
[ "func", "(", "q", "Query", ")", "Where", "(", "predicate", "func", "(", "interface", "{", "}", ")", "bool", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", "Iterate", "(", ")", ...
// Where filters a collection of values based on a predicate.
[ "Where", "filters", "a", "collection", "of", "values", "based", "on", "a", "predicate", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/where.go#L4-L20
train
ahmetb/go-linq
where.go
WhereIndexed
func (q Query) WhereIndexed(predicate func(int, interface{}) bool) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() index := 0 return func() (item interface{}, ok bool) { for item, ok = next(); ok; item, ok = next() { if predicate(index, item) { return } index++ } return } }, } }
go
func (q Query) WhereIndexed(predicate func(int, interface{}) bool) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() index := 0 return func() (item interface{}, ok bool) { for item, ok = next(); ok; item, ok = next() { if predicate(index, item) { return } index++ } return } }, } }
[ "func", "(", "q", "Query", ")", "WhereIndexed", "(", "predicate", "func", "(", "int", ",", "interface", "{", "}", ")", "bool", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", "It...
// WhereIndexed filters a collection of values based on a predicate. Each // element's index is used in the logic of the predicate function. // // The first argument represents the zero-based index of the element within // collection. The second argument of predicate represents the element to test.
[ "WhereIndexed", "filters", "a", "collection", "of", "values", "based", "on", "a", "predicate", ".", "Each", "element", "s", "index", "is", "used", "in", "the", "logic", "of", "the", "predicate", "function", ".", "The", "first", "argument", "represents", "the...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/where.go#L49-L68
train
ahmetb/go-linq
groupjoin.go
GroupJoin
func (q Query) GroupJoin(inner Query, outerKeySelector func(interface{}) interface{}, innerKeySelector func(interface{}) interface{}, resultSelector func(outer interface{}, inners []interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { outernext := q.Iterate() innernext := inner.Iterate() innerLookup := make(map[interface{}][]interface{}) for innerItem, ok := innernext(); ok; innerItem, ok = innernext() { innerKey := innerKeySelector(innerItem) innerLookup[innerKey] = append(innerLookup[innerKey], innerItem) } return func() (item interface{}, ok bool) { if item, ok = outernext(); !ok { return } if group, has := innerLookup[outerKeySelector(item)]; !has { item = resultSelector(item, []interface{}{}) } else { item = resultSelector(item, group) } return } }, } }
go
func (q Query) GroupJoin(inner Query, outerKeySelector func(interface{}) interface{}, innerKeySelector func(interface{}) interface{}, resultSelector func(outer interface{}, inners []interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { outernext := q.Iterate() innernext := inner.Iterate() innerLookup := make(map[interface{}][]interface{}) for innerItem, ok := innernext(); ok; innerItem, ok = innernext() { innerKey := innerKeySelector(innerItem) innerLookup[innerKey] = append(innerLookup[innerKey], innerItem) } return func() (item interface{}, ok bool) { if item, ok = outernext(); !ok { return } if group, has := innerLookup[outerKeySelector(item)]; !has { item = resultSelector(item, []interface{}{}) } else { item = resultSelector(item, group) } return } }, } }
[ "func", "(", "q", "Query", ")", "GroupJoin", "(", "inner", "Query", ",", "outerKeySelector", "func", "(", "interface", "{", "}", ")", "interface", "{", "}", ",", "innerKeySelector", "func", "(", "interface", "{", "}", ")", "interface", "{", "}", ",", "...
// GroupJoin correlates the elements of two collections based on key equality, // and groups the results. // // This method produces hierarchical results, which means that elements from // outer query are paired with collections of matching elements from inner. // GroupJoin enables you to base your results on a whole set of matches for each // element of outer query. // // The resultSelector function is called only one time for each outer element // together with a collection of all the inner elements that match the outer // element. This differs from the Join method, in which the result selector // function is invoked on pairs that contain one element from outer and one // element from inner. // // GroupJoin preserves the order of the elements of outer, and for each element // of outer, the order of the matching elements from inner.
[ "GroupJoin", "correlates", "the", "elements", "of", "two", "collections", "based", "on", "key", "equality", "and", "groups", "the", "results", ".", "This", "method", "produces", "hierarchical", "results", "which", "means", "that", "elements", "from", "outer", "q...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/groupjoin.go#L21-L52
train
ahmetb/go-linq
distinct.go
Distinct
func (q Query) Distinct() Query { return Query{ Iterate: func() Iterator { next := q.Iterate() set := make(map[interface{}]bool) return func() (item interface{}, ok bool) { for item, ok = next(); ok; item, ok = next() { if _, has := set[item]; !has { set[item] = true return } } return } }, } }
go
func (q Query) Distinct() Query { return Query{ Iterate: func() Iterator { next := q.Iterate() set := make(map[interface{}]bool) return func() (item interface{}, ok bool) { for item, ok = next(); ok; item, ok = next() { if _, has := set[item]; !has { set[item] = true return } } return } }, } }
[ "func", "(", "q", "Query", ")", "Distinct", "(", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n", "set", ":=", "make", "(", "map", "[", "interface", "...
// Distinct method returns distinct elements from a collection. The result is an // unordered collection that contains no duplicate values.
[ "Distinct", "method", "returns", "distinct", "elements", "from", "a", "collection", ".", "The", "result", "is", "an", "unordered", "collection", "that", "contains", "no", "duplicate", "values", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/distinct.go#L5-L23
train
ahmetb/go-linq
distinct.go
DistinctBy
func (q Query) DistinctBy(selector func(interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() set := make(map[interface{}]bool) return func() (item interface{}, ok bool) { for item, ok = next(); ok; item, ok = next() { s := selector(item) if _, has := set[s]; !has { set[s] = true return } } return } }, } }
go
func (q Query) DistinctBy(selector func(interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() set := make(map[interface{}]bool) return func() (item interface{}, ok bool) { for item, ok = next(); ok; item, ok = next() { s := selector(item) if _, has := set[s]; !has { set[s] = true return } } return } }, } }
[ "func", "(", "q", "Query", ")", "DistinctBy", "(", "selector", "func", "(", "interface", "{", "}", ")", "interface", "{", "}", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", "It...
// DistinctBy method returns distinct elements from a collection. This method // executes selector function for each element to determine a value to compare. // The result is an unordered collection that contains no duplicate values.
[ "DistinctBy", "method", "returns", "distinct", "elements", "from", "a", "collection", ".", "This", "method", "executes", "selector", "function", "for", "each", "element", "to", "determine", "a", "value", "to", "compare", ".", "The", "result", "is", "an", "unor...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/distinct.go#L56-L75
train
ahmetb/go-linq
groupby.go
GroupBy
func (q Query) GroupBy(keySelector func(interface{}) interface{}, elementSelector func(interface{}) interface{}) Query { return Query{ func() Iterator { next := q.Iterate() set := make(map[interface{}][]interface{}) for item, ok := next(); ok; item, ok = next() { key := keySelector(item) set[key] = append(set[key], elementSelector(item)) } len := len(set) idx := 0 groups := make([]Group, len) for k, v := range set { groups[idx] = Group{k, v} idx++ } index := 0 return func() (item interface{}, ok bool) { ok = index < len if ok { item = groups[index] index++ } return } }, } }
go
func (q Query) GroupBy(keySelector func(interface{}) interface{}, elementSelector func(interface{}) interface{}) Query { return Query{ func() Iterator { next := q.Iterate() set := make(map[interface{}][]interface{}) for item, ok := next(); ok; item, ok = next() { key := keySelector(item) set[key] = append(set[key], elementSelector(item)) } len := len(set) idx := 0 groups := make([]Group, len) for k, v := range set { groups[idx] = Group{k, v} idx++ } index := 0 return func() (item interface{}, ok bool) { ok = index < len if ok { item = groups[index] index++ } return } }, } }
[ "func", "(", "q", "Query", ")", "GroupBy", "(", "keySelector", "func", "(", "interface", "{", "}", ")", "interface", "{", "}", ",", "elementSelector", "func", "(", "interface", "{", "}", ")", "interface", "{", "}", ")", "Query", "{", "return", "Query",...
// GroupBy method groups the elements of a collection according to a specified // key selector function and projects the elements for each group by using a // specified function.
[ "GroupBy", "method", "groups", "the", "elements", "of", "a", "collection", "according", "to", "a", "specified", "key", "selector", "function", "and", "projects", "the", "elements", "for", "each", "group", "by", "using", "a", "specified", "function", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/groupby.go#L12-L45
train
ahmetb/go-linq
result.go
All
func (q Query) All(predicate func(interface{}) bool) bool { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { if !predicate(item) { return false } } return true }
go
func (q Query) All(predicate func(interface{}) bool) bool { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { if !predicate(item) { return false } } return true }
[ "func", "(", "q", "Query", ")", "All", "(", "predicate", "func", "(", "interface", "{", "}", ")", "bool", ")", "bool", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n\n", "for", "item", ",", "ok", ":=", "next", "(", ")", ";", "ok", ";", ...
// All determines whether all elements of a collection satisfy a condition.
[ "All", "determines", "whether", "all", "elements", "of", "a", "collection", "satisfy", "a", "condition", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L9-L19
train
ahmetb/go-linq
result.go
Average
func (q Query) Average() (r float64) { next := q.Iterate() item, ok := next() if !ok { return math.NaN() } n := 1 switch item.(type) { case int, int8, int16, int32, int64: conv := getIntConverter(item) sum := conv(item) for item, ok = next(); ok; item, ok = next() { sum += conv(item) n++ } r = float64(sum) case uint, uint8, uint16, uint32, uint64: conv := getUIntConverter(item) sum := conv(item) for item, ok = next(); ok; item, ok = next() { sum += conv(item) n++ } r = float64(sum) default: conv := getFloatConverter(item) r = conv(item) for item, ok = next(); ok; item, ok = next() { r += conv(item) n++ } } return r / float64(n) }
go
func (q Query) Average() (r float64) { next := q.Iterate() item, ok := next() if !ok { return math.NaN() } n := 1 switch item.(type) { case int, int8, int16, int32, int64: conv := getIntConverter(item) sum := conv(item) for item, ok = next(); ok; item, ok = next() { sum += conv(item) n++ } r = float64(sum) case uint, uint8, uint16, uint32, uint64: conv := getUIntConverter(item) sum := conv(item) for item, ok = next(); ok; item, ok = next() { sum += conv(item) n++ } r = float64(sum) default: conv := getFloatConverter(item) r = conv(item) for item, ok = next(); ok; item, ok = next() { r += conv(item) n++ } } return r / float64(n) }
[ "func", "(", "q", "Query", ")", "Average", "(", ")", "(", "r", "float64", ")", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n", "item", ",", "ok", ":=", "next", "(", ")", "\n", "if", "!", "ok", "{", "return", "math", ".", "NaN", "(", ...
// Average computes the average of a collection of numeric values.
[ "Average", "computes", "the", "average", "of", "a", "collection", "of", "numeric", "values", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L84-L124
train
ahmetb/go-linq
result.go
Contains
func (q Query) Contains(value interface{}) bool { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { if item == value { return true } } return false }
go
func (q Query) Contains(value interface{}) bool { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { if item == value { return true } } return false }
[ "func", "(", "q", "Query", ")", "Contains", "(", "value", "interface", "{", "}", ")", "bool", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n\n", "for", "item", ",", "ok", ":=", "next", "(", ")", ";", "ok", ";", "item", ",", "ok", "=", ...
// Contains determines whether a collection contains a specified element.
[ "Contains", "determines", "whether", "a", "collection", "contains", "a", "specified", "element", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L127-L137
train
ahmetb/go-linq
result.go
Count
func (q Query) Count() (r int) { next := q.Iterate() for _, ok := next(); ok; _, ok = next() { r++ } return }
go
func (q Query) Count() (r int) { next := q.Iterate() for _, ok := next(); ok; _, ok = next() { r++ } return }
[ "func", "(", "q", "Query", ")", "Count", "(", ")", "(", "r", "int", ")", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n\n", "for", "_", ",", "ok", ":=", "next", "(", ")", ";", "ok", ";", "_", ",", "ok", "=", "next", "(", ")", "{", ...
// Count returns the number of elements in a collection.
[ "Count", "returns", "the", "number", "of", "elements", "in", "a", "collection", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L140-L148
train
ahmetb/go-linq
result.go
CountWith
func (q Query) CountWith(predicate func(interface{}) bool) (r int) { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { if predicate(item) { r++ } } return }
go
func (q Query) CountWith(predicate func(interface{}) bool) (r int) { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { if predicate(item) { r++ } } return }
[ "func", "(", "q", "Query", ")", "CountWith", "(", "predicate", "func", "(", "interface", "{", "}", ")", "bool", ")", "(", "r", "int", ")", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n\n", "for", "item", ",", "ok", ":=", "next", "(", ")...
// CountWith returns a number that represents how many elements in the specified // collection satisfy a condition.
[ "CountWith", "returns", "a", "number", "that", "represents", "how", "many", "elements", "in", "the", "specified", "collection", "satisfy", "a", "condition", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L152-L162
train
ahmetb/go-linq
result.go
FirstWith
func (q Query) FirstWith(predicate func(interface{}) bool) interface{} { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { if predicate(item) { return item } } return nil }
go
func (q Query) FirstWith(predicate func(interface{}) bool) interface{} { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { if predicate(item) { return item } } return nil }
[ "func", "(", "q", "Query", ")", "FirstWith", "(", "predicate", "func", "(", "interface", "{", "}", ")", "bool", ")", "interface", "{", "}", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n\n", "for", "item", ",", "ok", ":=", "next", "(", ")"...
// FirstWith returns the first element of a collection that satisfies a // specified condition.
[ "FirstWith", "returns", "the", "first", "element", "of", "a", "collection", "that", "satisfies", "a", "specified", "condition", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L194-L204
train
ahmetb/go-linq
result.go
ForEach
func (q Query) ForEach(action func(interface{})) { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { action(item) } }
go
func (q Query) ForEach(action func(interface{})) { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { action(item) } }
[ "func", "(", "q", "Query", ")", "ForEach", "(", "action", "func", "(", "interface", "{", "}", ")", ")", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n\n", "for", "item", ",", "ok", ":=", "next", "(", ")", ";", "ok", ";", "item", ",", "...
// ForEach performs the specified action on each element of a collection.
[ "ForEach", "performs", "the", "specified", "action", "on", "each", "element", "of", "a", "collection", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L229-L235
train
ahmetb/go-linq
result.go
ForEachIndexed
func (q Query) ForEachIndexed(action func(int, interface{})) { next := q.Iterate() index := 0 for item, ok := next(); ok; item, ok = next() { action(index, item) index++ } }
go
func (q Query) ForEachIndexed(action func(int, interface{})) { next := q.Iterate() index := 0 for item, ok := next(); ok; item, ok = next() { action(index, item) index++ } }
[ "func", "(", "q", "Query", ")", "ForEachIndexed", "(", "action", "func", "(", "int", ",", "interface", "{", "}", ")", ")", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n", "index", ":=", "0", "\n\n", "for", "item", ",", "ok", ":=", "next",...
// ForEachIndexed performs the specified action on each element of a collection. // // The first argument to action represents the zero-based index of that // element in the source collection. This can be useful if the elements are in a // known order and you want to do something with an element at a particular // index, for example. It can also be useful if you want to retrieve the index // of one or more elements. The second argument to action represents the // element to process.
[ "ForEachIndexed", "performs", "the", "specified", "action", "on", "each", "element", "of", "a", "collection", ".", "The", "first", "argument", "to", "action", "represents", "the", "zero", "-", "based", "index", "of", "that", "element", "in", "the", "source", ...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L267-L275
train
ahmetb/go-linq
result.go
Last
func (q Query) Last() (r interface{}) { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { r = item } return }
go
func (q Query) Last() (r interface{}) { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { r = item } return }
[ "func", "(", "q", "Query", ")", "Last", "(", ")", "(", "r", "interface", "{", "}", ")", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n\n", "for", "item", ",", "ok", ":=", "next", "(", ")", ";", "ok", ";", "item", ",", "ok", "=", "nex...
// Last returns the last element of a collection.
[ "Last", "returns", "the", "last", "element", "of", "a", "collection", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L300-L308
train
ahmetb/go-linq
result.go
LastWith
func (q Query) LastWith(predicate func(interface{}) bool) (r interface{}) { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { if predicate(item) { r = item } } return }
go
func (q Query) LastWith(predicate func(interface{}) bool) (r interface{}) { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { if predicate(item) { r = item } } return }
[ "func", "(", "q", "Query", ")", "LastWith", "(", "predicate", "func", "(", "interface", "{", "}", ")", "bool", ")", "(", "r", "interface", "{", "}", ")", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n\n", "for", "item", ",", "ok", ":=", ...
// LastWith returns the last element of a collection that satisfies a specified // condition.
[ "LastWith", "returns", "the", "last", "element", "of", "a", "collection", "that", "satisfies", "a", "specified", "condition", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L312-L322
train
ahmetb/go-linq
result.go
Min
func (q Query) Min() (r interface{}) { next := q.Iterate() item, ok := next() if !ok { return nil } compare := getComparer(item) r = item for item, ok := next(); ok; item, ok = next() { if compare(item, r) < 0 { r = item } } return }
go
func (q Query) Min() (r interface{}) { next := q.Iterate() item, ok := next() if !ok { return nil } compare := getComparer(item) r = item for item, ok := next(); ok; item, ok = next() { if compare(item, r) < 0 { r = item } } return }
[ "func", "(", "q", "Query", ")", "Min", "(", ")", "(", "r", "interface", "{", "}", ")", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n", "item", ",", "ok", ":=", "next", "(", ")", "\n", "if", "!", "ok", "{", "return", "nil", "\n", "}"...
// Min returns the minimum value in a collection of values.
[ "Min", "returns", "the", "minimum", "value", "in", "a", "collection", "of", "values", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L367-L384
train
ahmetb/go-linq
result.go
Results
func (q Query) Results() (r []interface{}) { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { r = append(r, item) } return }
go
func (q Query) Results() (r []interface{}) { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { r = append(r, item) } return }
[ "func", "(", "q", "Query", ")", "Results", "(", ")", "(", "r", "[", "]", "interface", "{", "}", ")", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n\n", "for", "item", ",", "ok", ":=", "next", "(", ")", ";", "ok", ";", "item", ",", "o...
// Results iterates over a collection and returnes slice of interfaces
[ "Results", "iterates", "over", "a", "collection", "and", "returnes", "slice", "of", "interfaces" ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L387-L395
train
ahmetb/go-linq
result.go
SequenceEqual
func (q Query) SequenceEqual(q2 Query) bool { next := q.Iterate() next2 := q2.Iterate() for item, ok := next(); ok; item, ok = next() { item2, ok2 := next2() if !ok2 || item != item2 { return false } } _, ok2 := next2() return !ok2 }
go
func (q Query) SequenceEqual(q2 Query) bool { next := q.Iterate() next2 := q2.Iterate() for item, ok := next(); ok; item, ok = next() { item2, ok2 := next2() if !ok2 || item != item2 { return false } } _, ok2 := next2() return !ok2 }
[ "func", "(", "q", "Query", ")", "SequenceEqual", "(", "q2", "Query", ")", "bool", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n", "next2", ":=", "q2", ".", "Iterate", "(", ")", "\n\n", "for", "item", ",", "ok", ":=", "next", "(", ")", "...
// SequenceEqual determines whether two collections are equal.
[ "SequenceEqual", "determines", "whether", "two", "collections", "are", "equal", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L398-L411
train
ahmetb/go-linq
result.go
Single
func (q Query) Single() interface{} { next := q.Iterate() item, ok := next() if !ok { return nil } _, ok = next() if ok { return nil } return item }
go
func (q Query) Single() interface{} { next := q.Iterate() item, ok := next() if !ok { return nil } _, ok = next() if ok { return nil } return item }
[ "func", "(", "q", "Query", ")", "Single", "(", ")", "interface", "{", "}", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n", "item", ",", "ok", ":=", "next", "(", ")", "\n", "if", "!", "ok", "{", "return", "nil", "\n", "}", "\n\n", "_",...
// Single returns the only element of a collection, and nil if there is not // exactly one element in the collection.
[ "Single", "returns", "the", "only", "element", "of", "a", "collection", "and", "nil", "if", "there", "is", "not", "exactly", "one", "element", "in", "the", "collection", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L415-L428
train
ahmetb/go-linq
result.go
SingleWith
func (q Query) SingleWith(predicate func(interface{}) bool) (r interface{}) { next := q.Iterate() found := false for item, ok := next(); ok; item, ok = next() { if predicate(item) { if found { return nil } found = true r = item } } return }
go
func (q Query) SingleWith(predicate func(interface{}) bool) (r interface{}) { next := q.Iterate() found := false for item, ok := next(); ok; item, ok = next() { if predicate(item) { if found { return nil } found = true r = item } } return }
[ "func", "(", "q", "Query", ")", "SingleWith", "(", "predicate", "func", "(", "interface", "{", "}", ")", "bool", ")", "(", "r", "interface", "{", "}", ")", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n", "found", ":=", "false", "\n\n", "f...
// SingleWith returns the only element of a collection that satisfies a // specified condition, and nil if more than one such element exists.
[ "SingleWith", "returns", "the", "only", "element", "of", "a", "collection", "that", "satisfies", "a", "specified", "condition", "and", "nil", "if", "more", "than", "one", "such", "element", "exists", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L432-L448
train
ahmetb/go-linq
result.go
ToChannel
func (q Query) ToChannel(result chan<- interface{}) { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { result <- item } close(result) }
go
func (q Query) ToChannel(result chan<- interface{}) { next := q.Iterate() for item, ok := next(); ok; item, ok = next() { result <- item } close(result) }
[ "func", "(", "q", "Query", ")", "ToChannel", "(", "result", "chan", "<-", "interface", "{", "}", ")", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n\n", "for", "item", ",", "ok", ":=", "next", "(", ")", ";", "ok", ";", "item", ",", "ok",...
// ToChannel iterates over a collection and outputs each element to a channel, // then closes it.
[ "ToChannel", "iterates", "over", "a", "collection", "and", "outputs", "each", "element", "to", "a", "channel", "then", "closes", "it", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L537-L545
train
ahmetb/go-linq
result.go
ToMap
func (q Query) ToMap(result interface{}) { q.ToMapBy( result, func(i interface{}) interface{} { return i.(KeyValue).Key }, func(i interface{}) interface{} { return i.(KeyValue).Value }) }
go
func (q Query) ToMap(result interface{}) { q.ToMapBy( result, func(i interface{}) interface{} { return i.(KeyValue).Key }, func(i interface{}) interface{} { return i.(KeyValue).Value }) }
[ "func", "(", "q", "Query", ")", "ToMap", "(", "result", "interface", "{", "}", ")", "{", "q", ".", "ToMapBy", "(", "result", ",", "func", "(", "i", "interface", "{", "}", ")", "interface", "{", "}", "{", "return", "i", ".", "(", "KeyValue", ")", ...
// ToMap iterates over a collection and populates result map with elements. // Collection elements have to be of KeyValue type to use this method. To // populate a map with elements of different type use ToMapBy method. ToMap // doesn't empty the result map before populating it.
[ "ToMap", "iterates", "over", "a", "collection", "and", "populates", "result", "map", "with", "elements", ".", "Collection", "elements", "have", "to", "be", "of", "KeyValue", "type", "to", "use", "this", "method", ".", "To", "populate", "a", "map", "with", ...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L551-L560
train
ahmetb/go-linq
result.go
ToMapBy
func (q Query) ToMapBy(result interface{}, keySelector func(interface{}) interface{}, valueSelector func(interface{}) interface{}) { res := reflect.ValueOf(result) m := reflect.Indirect(res) next := q.Iterate() for item, ok := next(); ok; item, ok = next() { key := reflect.ValueOf(keySelector(item)) value := reflect.ValueOf(valueSelector(item)) m.SetMapIndex(key, value) } res.Elem().Set(m) }
go
func (q Query) ToMapBy(result interface{}, keySelector func(interface{}) interface{}, valueSelector func(interface{}) interface{}) { res := reflect.ValueOf(result) m := reflect.Indirect(res) next := q.Iterate() for item, ok := next(); ok; item, ok = next() { key := reflect.ValueOf(keySelector(item)) value := reflect.ValueOf(valueSelector(item)) m.SetMapIndex(key, value) } res.Elem().Set(m) }
[ "func", "(", "q", "Query", ")", "ToMapBy", "(", "result", "interface", "{", "}", ",", "keySelector", "func", "(", "interface", "{", "}", ")", "interface", "{", "}", ",", "valueSelector", "func", "(", "interface", "{", "}", ")", "interface", "{", "}", ...
// ToMapBy iterates over a collection and populates the result map with // elements. Functions keySelector and valueSelector are executed for each // element of the collection to generate key and value for the map. Generated // key and value types must be assignable to the map's key and value types. // ToMapBy doesn't empty the result map before populating it.
[ "ToMapBy", "iterates", "over", "a", "collection", "and", "populates", "the", "result", "map", "with", "elements", ".", "Functions", "keySelector", "and", "valueSelector", "are", "executed", "for", "each", "element", "of", "the", "collection", "to", "generate", "...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L567-L582
train
ahmetb/go-linq
result.go
ToSlice
func (q Query) ToSlice(v interface{}) { res := reflect.ValueOf(v) slice := reflect.Indirect(res) cap := slice.Cap() res.Elem().Set(slice.Slice(0, cap)) // make len(slice)==cap(slice) from now on next := q.Iterate() index := 0 for item, ok := next(); ok; item, ok = next() { if index >= cap { slice, cap = grow(slice) } slice.Index(index).Set(reflect.ValueOf(item)) index++ } // reslice the len(res)==cap(res) actual res size res.Elem().Set(slice.Slice(0, index)) }
go
func (q Query) ToSlice(v interface{}) { res := reflect.ValueOf(v) slice := reflect.Indirect(res) cap := slice.Cap() res.Elem().Set(slice.Slice(0, cap)) // make len(slice)==cap(slice) from now on next := q.Iterate() index := 0 for item, ok := next(); ok; item, ok = next() { if index >= cap { slice, cap = grow(slice) } slice.Index(index).Set(reflect.ValueOf(item)) index++ } // reslice the len(res)==cap(res) actual res size res.Elem().Set(slice.Slice(0, index)) }
[ "func", "(", "q", "Query", ")", "ToSlice", "(", "v", "interface", "{", "}", ")", "{", "res", ":=", "reflect", ".", "ValueOf", "(", "v", ")", "\n", "slice", ":=", "reflect", ".", "Indirect", "(", "res", ")", "\n\n", "cap", ":=", "slice", ".", "Cap...
// ToSlice iterates over a collection and saves the results in the slice pointed // by v. It overwrites the existing slice, starting from index 0. // // If the slice pointed by v has sufficient capacity, v will be pointed to a // resliced slice. If it does not, a new underlying array will be allocated and // v will point to it.
[ "ToSlice", "iterates", "over", "a", "collection", "and", "saves", "the", "results", "in", "the", "slice", "pointed", "by", "v", ".", "It", "overwrites", "the", "existing", "slice", "starting", "from", "index", "0", ".", "If", "the", "slice", "pointed", "by...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/result.go#L625-L644
train
ahmetb/go-linq
union.go
Union
func (q Query) Union(q2 Query) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() next2 := q2.Iterate() set := make(map[interface{}]bool) use1 := true return func() (item interface{}, ok bool) { if use1 { for item, ok = next(); ok; item, ok = next() { if _, has := set[item]; !has { set[item] = true return } } use1 = false } for item, ok = next2(); ok; item, ok = next2() { if _, has := set[item]; !has { set[item] = true return } } return } }, } }
go
func (q Query) Union(q2 Query) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() next2 := q2.Iterate() set := make(map[interface{}]bool) use1 := true return func() (item interface{}, ok bool) { if use1 { for item, ok = next(); ok; item, ok = next() { if _, has := set[item]; !has { set[item] = true return } } use1 = false } for item, ok = next2(); ok; item, ok = next2() { if _, has := set[item]; !has { set[item] = true return } } return } }, } }
[ "func", "(", "q", "Query", ")", "Union", "(", "q2", "Query", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n", "next2", ":=", "q2", ".", "Iterate", "("...
// Union produces the set union of two collections. // // This method excludes duplicates from the return set. This is different // behavior to the Concat method, which returns all the elements in the input // collection including duplicates.
[ "Union", "produces", "the", "set", "union", "of", "two", "collections", ".", "This", "method", "excludes", "duplicates", "from", "the", "return", "set", ".", "This", "is", "different", "behavior", "to", "the", "Concat", "method", "which", "returns", "all", "...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/union.go#L8-L40
train
ahmetb/go-linq
select.go
Select
func (q Query) Select(selector func(interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() return func() (item interface{}, ok bool) { var it interface{} it, ok = next() if ok { item = selector(it) } return } }, } }
go
func (q Query) Select(selector func(interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() return func() (item interface{}, ok bool) { var it interface{} it, ok = next() if ok { item = selector(it) } return } }, } }
[ "func", "(", "q", "Query", ")", "Select", "(", "selector", "func", "(", "interface", "{", "}", ")", "interface", "{", "}", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", "Iterat...
// Select projects each element of a collection into a new form. Returns a query // with the result of invoking the transform function on each element of // original source. // // This projection method requires the transform function, selector, to produce // one value for each value in the source collection. If selector returns a // value that is itself a collection, it is up to the consumer to traverse the // subcollections manually. In such a situation, it might be better for your // query to return a single coalesced collection of values. To achieve this, use // the SelectMany method instead of Select. Although SelectMany works similarly // to Select, it differs in that the transform function returns a collection // that is then expanded by SelectMany before it is returned.
[ "Select", "projects", "each", "element", "of", "a", "collection", "into", "a", "new", "form", ".", "Returns", "a", "query", "with", "the", "result", "of", "invoking", "the", "transform", "function", "on", "each", "element", "of", "original", "source", ".", ...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/select.go#L15-L31
train
ahmetb/go-linq
select.go
SelectIndexed
func (q Query) SelectIndexed(selector func(int, interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() index := 0 return func() (item interface{}, ok bool) { var it interface{} it, ok = next() if ok { item = selector(index, it) index++ } return } }, } }
go
func (q Query) SelectIndexed(selector func(int, interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() index := 0 return func() (item interface{}, ok bool) { var it interface{} it, ok = next() if ok { item = selector(index, it) index++ } return } }, } }
[ "func", "(", "q", "Query", ")", "SelectIndexed", "(", "selector", "func", "(", "int", ",", "interface", "{", "}", ")", "interface", "{", "}", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", ...
// SelectIndexed projects each element of a collection into a new form by // incorporating the element's index. Returns a query with the result of // invoking the transform function on each element of original source. // // The first argument to selector represents the zero-based index of that // element in the source collection. This can be useful if the elements are in a // known order and you want to do something with an element at a particular // index, for example. It can also be useful if you want to retrieve the index // of one or more elements. The second argument to selector represents the // element to process. // // This projection method requires the transform function, selector, to produce // one value for each value in the source collection. If selector returns a // value that is itself a collection, it is up to the consumer to traverse the // subcollections manually. In such a situation, it might be better for your // query to return a single coalesced collection of values. To achieve this, use // the SelectMany method instead of Select. Although SelectMany works similarly // to Select, it differs in that the transform function returns a collection // that is then expanded by SelectMany before it is returned.
[ "SelectIndexed", "projects", "each", "element", "of", "a", "collection", "into", "a", "new", "form", "by", "incorporating", "the", "element", "s", "index", ".", "Returns", "a", "query", "with", "the", "result", "of", "invoking", "the", "transform", "function",...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/select.go#L72-L90
train
ahmetb/go-linq
reverse.go
Reverse
func (q Query) Reverse() Query { return Query{ Iterate: func() Iterator { next := q.Iterate() items := []interface{}{} for item, ok := next(); ok; item, ok = next() { items = append(items, item) } index := len(items) - 1 return func() (item interface{}, ok bool) { if index < 0 { return } item, ok = items[index], true index-- return } }, } }
go
func (q Query) Reverse() Query { return Query{ Iterate: func() Iterator { next := q.Iterate() items := []interface{}{} for item, ok := next(); ok; item, ok = next() { items = append(items, item) } index := len(items) - 1 return func() (item interface{}, ok bool) { if index < 0 { return } item, ok = items[index], true index-- return } }, } }
[ "func", "(", "q", "Query", ")", "Reverse", "(", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n\n", "items", ":=", "[", "]", "interface", "{", "}", "{"...
// Reverse inverts the order of the elements in a collection. // // Unlike OrderBy, this sorting method does not consider the actual values // themselves in determining the order. Rather, it just returns the elements in // the reverse order from which they are produced by the underlying source.
[ "Reverse", "inverts", "the", "order", "of", "the", "elements", "in", "a", "collection", ".", "Unlike", "OrderBy", "this", "sorting", "method", "does", "not", "consider", "the", "actual", "values", "themselves", "in", "determining", "the", "order", ".", "Rather...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/reverse.go#L8-L30
train
ahmetb/go-linq
zip.go
Zip
func (q Query) Zip(q2 Query, resultSelector func(interface{}, interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { next1 := q.Iterate() next2 := q2.Iterate() return func() (item interface{}, ok bool) { item1, ok1 := next1() item2, ok2 := next2() if ok1 && ok2 { return resultSelector(item1, item2), true } return nil, false } }, } }
go
func (q Query) Zip(q2 Query, resultSelector func(interface{}, interface{}) interface{}) Query { return Query{ Iterate: func() Iterator { next1 := q.Iterate() next2 := q2.Iterate() return func() (item interface{}, ok bool) { item1, ok1 := next1() item2, ok2 := next2() if ok1 && ok2 { return resultSelector(item1, item2), true } return nil, false } }, } }
[ "func", "(", "q", "Query", ")", "Zip", "(", "q2", "Query", ",", "resultSelector", "func", "(", "interface", "{", "}", ",", "interface", "{", "}", ")", "interface", "{", "}", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")...
// Zip applies a specified function to the corresponding elements of two // collections, producing a collection of the results. // // The method steps through the two input collections, applying function // resultSelector to corresponding elements of the two collections. The method // returns a collection of the values that are returned by resultSelector. If // the input collections do not have the same number of elements, the method // combines elements until it reaches the end of one of the collections. For // example, if one collection has three elements and the other one has four, the // result collection has only three elements.
[ "Zip", "applies", "a", "specified", "function", "to", "the", "corresponding", "elements", "of", "two", "collections", "producing", "a", "collection", "of", "the", "results", ".", "The", "method", "steps", "through", "the", "two", "input", "collections", "applyin...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/zip.go#L13-L33
train
ahmetb/go-linq
from.go
From
func From(source interface{}) Query { src := reflect.ValueOf(source) switch src.Kind() { case reflect.Slice, reflect.Array: len := src.Len() return Query{ Iterate: func() Iterator { index := 0 return func() (item interface{}, ok bool) { ok = index < len if ok { item = src.Index(index).Interface() index++ } return } }, } case reflect.Map: len := src.Len() return Query{ Iterate: func() Iterator { index := 0 keys := src.MapKeys() return func() (item interface{}, ok bool) { ok = index < len if ok { key := keys[index] item = KeyValue{ Key: key.Interface(), Value: src.MapIndex(key).Interface(), } index++ } return } }, } case reflect.String: return FromString(source.(string)) case reflect.Chan: return FromChannel(source.(chan interface{})) default: return FromIterable(source.(Iterable)) } }
go
func From(source interface{}) Query { src := reflect.ValueOf(source) switch src.Kind() { case reflect.Slice, reflect.Array: len := src.Len() return Query{ Iterate: func() Iterator { index := 0 return func() (item interface{}, ok bool) { ok = index < len if ok { item = src.Index(index).Interface() index++ } return } }, } case reflect.Map: len := src.Len() return Query{ Iterate: func() Iterator { index := 0 keys := src.MapKeys() return func() (item interface{}, ok bool) { ok = index < len if ok { key := keys[index] item = KeyValue{ Key: key.Interface(), Value: src.MapIndex(key).Interface(), } index++ } return } }, } case reflect.String: return FromString(source.(string)) case reflect.Chan: return FromChannel(source.(chan interface{})) default: return FromIterable(source.(Iterable)) } }
[ "func", "From", "(", "source", "interface", "{", "}", ")", "Query", "{", "src", ":=", "reflect", ".", "ValueOf", "(", "source", ")", "\n\n", "switch", "src", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Slice", ",", "reflect", ".", "Array", ...
// From initializes a linq query with passed slice, array or map as the source. // String, channel or struct implementing Iterable interface can be used as an // input. In this case From delegates it to FromString, FromChannel and // FromIterable internally.
[ "From", "initializes", "a", "linq", "query", "with", "passed", "slice", "array", "or", "map", "as", "the", "source", ".", "String", "channel", "or", "struct", "implementing", "Iterable", "interface", "can", "be", "used", "as", "an", "input", ".", "In", "th...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/from.go#L32-L85
train
ahmetb/go-linq
from.go
FromChannel
func FromChannel(source <-chan interface{}) Query { return Query{ Iterate: func() Iterator { return func() (item interface{}, ok bool) { item, ok = <-source return } }, } }
go
func FromChannel(source <-chan interface{}) Query { return Query{ Iterate: func() Iterator { return func() (item interface{}, ok bool) { item, ok = <-source return } }, } }
[ "func", "FromChannel", "(", "source", "<-", "chan", "interface", "{", "}", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "return", "func", "(", ")", "(", "item", "interface", "{", "}", ",", "ok", "bool"...
// FromChannel initializes a linq query with passed channel, linq iterates over // channel until it is closed.
[ "FromChannel", "initializes", "a", "linq", "query", "with", "passed", "channel", "linq", "iterates", "over", "channel", "until", "it", "is", "closed", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/from.go#L89-L98
train
ahmetb/go-linq
from.go
FromString
func FromString(source string) Query { runes := []rune(source) len := len(runes) return Query{ Iterate: func() Iterator { index := 0 return func() (item interface{}, ok bool) { ok = index < len if ok { item = runes[index] index++ } return } }, } }
go
func FromString(source string) Query { runes := []rune(source) len := len(runes) return Query{ Iterate: func() Iterator { index := 0 return func() (item interface{}, ok bool) { ok = index < len if ok { item = runes[index] index++ } return } }, } }
[ "func", "FromString", "(", "source", "string", ")", "Query", "{", "runes", ":=", "[", "]", "rune", "(", "source", ")", "\n", "len", ":=", "len", "(", "runes", ")", "\n\n", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "...
// FromString initializes a linq query with passed string, linq iterates over // runes of string.
[ "FromString", "initializes", "a", "linq", "query", "with", "passed", "string", "linq", "iterates", "over", "runes", "of", "string", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/from.go#L102-L121
train
ahmetb/go-linq
from.go
Range
func Range(start, count int) Query { return Query{ Iterate: func() Iterator { index := 0 current := start return func() (item interface{}, ok bool) { if index >= count { return nil, false } item, ok = current, true index++ current++ return } }, } }
go
func Range(start, count int) Query { return Query{ Iterate: func() Iterator { index := 0 current := start return func() (item interface{}, ok bool) { if index >= count { return nil, false } item, ok = current, true index++ current++ return } }, } }
[ "func", "Range", "(", "start", ",", "count", "int", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "index", ":=", "0", "\n", "current", ":=", "start", "\n\n", "return", "func", "(", ")", "(", "item", "...
// Range generates a sequence of integral numbers within a specified range.
[ "Range", "generates", "a", "sequence", "of", "integral", "numbers", "within", "a", "specified", "range", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/from.go#L133-L152
train
ahmetb/go-linq
from.go
Repeat
func Repeat(value interface{}, count int) Query { return Query{ Iterate: func() Iterator { index := 0 return func() (item interface{}, ok bool) { if index >= count { return nil, false } item, ok = value, true index++ return } }, } }
go
func Repeat(value interface{}, count int) Query { return Query{ Iterate: func() Iterator { index := 0 return func() (item interface{}, ok bool) { if index >= count { return nil, false } item, ok = value, true index++ return } }, } }
[ "func", "Repeat", "(", "value", "interface", "{", "}", ",", "count", "int", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "index", ":=", "0", "\n\n", "return", "func", "(", ")", "(", "item", "interface"...
// Repeat generates a sequence that contains one repeated value.
[ "Repeat", "generates", "a", "sequence", "that", "contains", "one", "repeated", "value", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/from.go#L155-L172
train
ahmetb/go-linq
genericfunc.go
Call
func (g *genericFunc) Call(params ...interface{}) interface{} { paramsIn := make([]reflect.Value, len(params)) for i, param := range params { paramsIn[i] = reflect.ValueOf(param) } paramsOut := g.Cache.FnValue.Call(paramsIn) if len(paramsOut) >= 1 { return paramsOut[0].Interface() } return nil }
go
func (g *genericFunc) Call(params ...interface{}) interface{} { paramsIn := make([]reflect.Value, len(params)) for i, param := range params { paramsIn[i] = reflect.ValueOf(param) } paramsOut := g.Cache.FnValue.Call(paramsIn) if len(paramsOut) >= 1 { return paramsOut[0].Interface() } return nil }
[ "func", "(", "g", "*", "genericFunc", ")", "Call", "(", "params", "...", "interface", "{", "}", ")", "interface", "{", "}", "{", "paramsIn", ":=", "make", "(", "[", "]", "reflect", ".", "Value", ",", "len", "(", "params", ")", ")", "\n", "for", "...
// Call calls a dynamic function.
[ "Call", "calls", "a", "dynamic", "function", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/genericfunc.go#L30-L40
train
ahmetb/go-linq
genericfunc.go
newGenericFunc
func newGenericFunc(methodName, paramName string, fn interface{}, validateFunc func(*functionCache) error) (*genericFunc, error) { cache := &functionCache{} cache.FnValue = reflect.ValueOf(fn) if cache.FnValue.Kind() != reflect.Func { return nil, fmt.Errorf("%s: parameter [%s] is not a function type. It is a '%s'", methodName, paramName, cache.FnValue.Type()) } cache.MethodName = methodName cache.ParamName = paramName cache.FnType = cache.FnValue.Type() numTypesIn := cache.FnType.NumIn() cache.TypesIn = make([]reflect.Type, numTypesIn) for i := 0; i < numTypesIn; i++ { cache.TypesIn[i] = cache.FnType.In(i) } numTypesOut := cache.FnType.NumOut() cache.TypesOut = make([]reflect.Type, numTypesOut) for i := 0; i < numTypesOut; i++ { cache.TypesOut[i] = cache.FnType.Out(i) } if err := validateFunc(cache); err != nil { return nil, err } return &genericFunc{Cache: cache}, nil }
go
func newGenericFunc(methodName, paramName string, fn interface{}, validateFunc func(*functionCache) error) (*genericFunc, error) { cache := &functionCache{} cache.FnValue = reflect.ValueOf(fn) if cache.FnValue.Kind() != reflect.Func { return nil, fmt.Errorf("%s: parameter [%s] is not a function type. It is a '%s'", methodName, paramName, cache.FnValue.Type()) } cache.MethodName = methodName cache.ParamName = paramName cache.FnType = cache.FnValue.Type() numTypesIn := cache.FnType.NumIn() cache.TypesIn = make([]reflect.Type, numTypesIn) for i := 0; i < numTypesIn; i++ { cache.TypesIn[i] = cache.FnType.In(i) } numTypesOut := cache.FnType.NumOut() cache.TypesOut = make([]reflect.Type, numTypesOut) for i := 0; i < numTypesOut; i++ { cache.TypesOut[i] = cache.FnType.Out(i) } if err := validateFunc(cache); err != nil { return nil, err } return &genericFunc{Cache: cache}, nil }
[ "func", "newGenericFunc", "(", "methodName", ",", "paramName", "string", ",", "fn", "interface", "{", "}", ",", "validateFunc", "func", "(", "*", "functionCache", ")", "error", ")", "(", "*", "genericFunc", ",", "error", ")", "{", "cache", ":=", "&", "fu...
// newGenericFunc instantiates a new genericFunc pointer
[ "newGenericFunc", "instantiates", "a", "new", "genericFunc", "pointer" ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/genericfunc.go#L43-L69
train
ahmetb/go-linq
genericfunc.go
simpleParamValidator
func simpleParamValidator(In []reflect.Type, Out []reflect.Type) func(cache *functionCache) error { return func(cache *functionCache) error { var isValid = func() bool { if In != nil { if len(In) != len(cache.TypesIn) { return false } for i, paramIn := range In { if paramIn != genericTp && paramIn != cache.TypesIn[i] { return false } } } if Out != nil { if len(Out) != len(cache.TypesOut) { return false } for i, paramOut := range Out { if paramOut != genericTp && paramOut != cache.TypesOut[i] { return false } } } return true } if !isValid() { return fmt.Errorf("%s: parameter [%s] has a invalid function signature. Expected: '%s', actual: '%s'", cache.MethodName, cache.ParamName, formatFnSignature(In, Out), formatFnSignature(cache.TypesIn, cache.TypesOut)) } return nil } }
go
func simpleParamValidator(In []reflect.Type, Out []reflect.Type) func(cache *functionCache) error { return func(cache *functionCache) error { var isValid = func() bool { if In != nil { if len(In) != len(cache.TypesIn) { return false } for i, paramIn := range In { if paramIn != genericTp && paramIn != cache.TypesIn[i] { return false } } } if Out != nil { if len(Out) != len(cache.TypesOut) { return false } for i, paramOut := range Out { if paramOut != genericTp && paramOut != cache.TypesOut[i] { return false } } } return true } if !isValid() { return fmt.Errorf("%s: parameter [%s] has a invalid function signature. Expected: '%s', actual: '%s'", cache.MethodName, cache.ParamName, formatFnSignature(In, Out), formatFnSignature(cache.TypesIn, cache.TypesOut)) } return nil } }
[ "func", "simpleParamValidator", "(", "In", "[", "]", "reflect", ".", "Type", ",", "Out", "[", "]", "reflect", ".", "Type", ")", "func", "(", "cache", "*", "functionCache", ")", "error", "{", "return", "func", "(", "cache", "*", "functionCache", ")", "e...
// simpleParamValidator creates a function to validate genericFunc based in the // In and Out function parameters.
[ "simpleParamValidator", "creates", "a", "function", "to", "validate", "genericFunc", "based", "in", "the", "In", "and", "Out", "function", "parameters", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/genericfunc.go#L73-L104
train
ahmetb/go-linq
genericfunc.go
newElemTypeSlice
func newElemTypeSlice(items ...interface{}) []reflect.Type { typeList := make([]reflect.Type, len(items)) for i, item := range items { typeItem := reflect.TypeOf(item) if typeItem.Kind() == reflect.Ptr { typeList[i] = typeItem.Elem() } } return typeList }
go
func newElemTypeSlice(items ...interface{}) []reflect.Type { typeList := make([]reflect.Type, len(items)) for i, item := range items { typeItem := reflect.TypeOf(item) if typeItem.Kind() == reflect.Ptr { typeList[i] = typeItem.Elem() } } return typeList }
[ "func", "newElemTypeSlice", "(", "items", "...", "interface", "{", "}", ")", "[", "]", "reflect", ".", "Type", "{", "typeList", ":=", "make", "(", "[", "]", "reflect", ".", "Type", ",", "len", "(", "items", ")", ")", "\n", "for", "i", ",", "item", ...
// newElemTypeSlice creates a slice of items elem types.
[ "newElemTypeSlice", "creates", "a", "slice", "of", "items", "elem", "types", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/genericfunc.go#L107-L116
train
ahmetb/go-linq
genericfunc.go
formatFnSignature
func formatFnSignature(In []reflect.Type, Out []reflect.Type) string { paramInNames := make([]string, len(In)) for i, typeIn := range In { if typeIn == genericTp { paramInNames[i] = "T" } else { paramInNames[i] = typeIn.String() } } paramOutNames := make([]string, len(Out)) for i, typeOut := range Out { if typeOut == genericTp { paramOutNames[i] = "T" } else { paramOutNames[i] = typeOut.String() } } return fmt.Sprintf("func(%s)%s", strings.Join(paramInNames, ","), strings.Join(paramOutNames, ",")) }
go
func formatFnSignature(In []reflect.Type, Out []reflect.Type) string { paramInNames := make([]string, len(In)) for i, typeIn := range In { if typeIn == genericTp { paramInNames[i] = "T" } else { paramInNames[i] = typeIn.String() } } paramOutNames := make([]string, len(Out)) for i, typeOut := range Out { if typeOut == genericTp { paramOutNames[i] = "T" } else { paramOutNames[i] = typeOut.String() } } return fmt.Sprintf("func(%s)%s", strings.Join(paramInNames, ","), strings.Join(paramOutNames, ",")) }
[ "func", "formatFnSignature", "(", "In", "[", "]", "reflect", ".", "Type", ",", "Out", "[", "]", "reflect", ".", "Type", ")", "string", "{", "paramInNames", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "In", ")", ")", "\n", "for", "i", ...
// formatFnSignature formats the func signature based in the parameters types.
[ "formatFnSignature", "formats", "the", "func", "signature", "based", "in", "the", "parameters", "types", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/genericfunc.go#L119-L138
train
ahmetb/go-linq
concat.go
Append
func (q Query) Append(item interface{}) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() appended := false return func() (interface{}, bool) { i, ok := next() if ok { return i, ok } if !appended { appended = true return item, true } return nil, false } }, } }
go
func (q Query) Append(item interface{}) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() appended := false return func() (interface{}, bool) { i, ok := next() if ok { return i, ok } if !appended { appended = true return item, true } return nil, false } }, } }
[ "func", "(", "q", "Query", ")", "Append", "(", "item", "interface", "{", "}", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n", "appended", ":=", "false"...
// Append inserts an item to the end of a collection, so it becomes the last // item.
[ "Append", "inserts", "an", "item", "to", "the", "end", "of", "a", "collection", "so", "it", "becomes", "the", "last", "item", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/concat.go#L5-L26
train
ahmetb/go-linq
concat.go
Concat
func (q Query) Concat(q2 Query) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() next2 := q2.Iterate() use1 := true return func() (item interface{}, ok bool) { if use1 { item, ok = next() if ok { return } use1 = false } return next2() } }, } }
go
func (q Query) Concat(q2 Query) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() next2 := q2.Iterate() use1 := true return func() (item interface{}, ok bool) { if use1 { item, ok = next() if ok { return } use1 = false } return next2() } }, } }
[ "func", "(", "q", "Query", ")", "Concat", "(", "q2", "Query", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n", "next2", ":=", "q2", ".", "Iterate", "(...
// Concat concatenates two collections. // // The Concat method differs from the Union method because the Concat method // returns all the original elements in the input sequences. The Union method // returns only unique elements.
[ "Concat", "concatenates", "two", "collections", ".", "The", "Concat", "method", "differs", "from", "the", "Union", "method", "because", "the", "Concat", "method", "returns", "all", "the", "original", "elements", "in", "the", "input", "sequences", ".", "The", "...
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/concat.go#L33-L54
train
ahmetb/go-linq
concat.go
Prepend
func (q Query) Prepend(item interface{}) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() prepended := false return func() (interface{}, bool) { if prepended { return next() } prepended = true return item, true } }, } }
go
func (q Query) Prepend(item interface{}) Query { return Query{ Iterate: func() Iterator { next := q.Iterate() prepended := false return func() (interface{}, bool) { if prepended { return next() } prepended = true return item, true } }, } }
[ "func", "(", "q", "Query", ")", "Prepend", "(", "item", "interface", "{", "}", ")", "Query", "{", "return", "Query", "{", "Iterate", ":", "func", "(", ")", "Iterator", "{", "next", ":=", "q", ".", "Iterate", "(", ")", "\n", "prepended", ":=", "fals...
// Prepend inserts an item to the beginning of a collection, so it becomes the // first item.
[ "Prepend", "inserts", "an", "item", "to", "the", "beginning", "of", "a", "collection", "so", "it", "becomes", "the", "first", "item", "." ]
9f6960b5d2e017ec4b7820f045fbd7db66dd53b6
https://github.com/ahmetb/go-linq/blob/9f6960b5d2e017ec4b7820f045fbd7db66dd53b6/concat.go#L58-L74
train
sfreiberg/gotwilio
proxy_participant.go
AddParticipant
func (session *ProxySession) AddParticipant(req ParticipantRequest) (response Participant, exception *Exception, err error) { twilioUrl := fmt.Sprintf("%s/%s/%s/%s/%s/%s", ProxyBaseUrl, "Services", session.ServiceSid, "Sessions", session.Sid, "Participants") res, err := session.twilio.post(participantFormValues(req), twilioUrl) if err != nil { return response, exception, err } defer res.Body.Close() responseBody, err := ioutil.ReadAll(res.Body) if err != nil { return response, exception, err } if res.StatusCode != http.StatusCreated { exception = new(Exception) err = json.Unmarshal(responseBody, exception) // We aren't checking the error because we don't actually care. // It's going to be passed to the client either way. return response, exception, err } err = json.Unmarshal(responseBody, &response) return response, exception, err }
go
func (session *ProxySession) AddParticipant(req ParticipantRequest) (response Participant, exception *Exception, err error) { twilioUrl := fmt.Sprintf("%s/%s/%s/%s/%s/%s", ProxyBaseUrl, "Services", session.ServiceSid, "Sessions", session.Sid, "Participants") res, err := session.twilio.post(participantFormValues(req), twilioUrl) if err != nil { return response, exception, err } defer res.Body.Close() responseBody, err := ioutil.ReadAll(res.Body) if err != nil { return response, exception, err } if res.StatusCode != http.StatusCreated { exception = new(Exception) err = json.Unmarshal(responseBody, exception) // We aren't checking the error because we don't actually care. // It's going to be passed to the client either way. return response, exception, err } err = json.Unmarshal(responseBody, &response) return response, exception, err }
[ "func", "(", "session", "*", "ProxySession", ")", "AddParticipant", "(", "req", "ParticipantRequest", ")", "(", "response", "Participant", ",", "exception", "*", "Exception", ",", "err", "error", ")", "{", "twilioUrl", ":=", "fmt", ".", "Sprintf", "(", "\"",...
// AddParticipant adds Participant to Session
[ "AddParticipant", "adds", "Participant", "to", "Session" ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/proxy_participant.go#L89-L116
train
sfreiberg/gotwilio
proxy_participant.go
DeleteParticipant
func (session *ProxySession) DeleteParticipant(participantID string) (exception *Exception, err error) { twilioUrl := fmt.Sprintf("%s/%s/%s/%s/%s/%s/%s", ProxyBaseUrl, "Services", session.ServiceSid, "Sessions", session.Sid, "Participants", participantID) res, err := session.twilio.delete(twilioUrl) if err != nil { return exception, err } respBody, err := ioutil.ReadAll(res.Body) if err != nil { return nil, err } if res.StatusCode != http.StatusNoContent { exc := new(Exception) err = json.Unmarshal(respBody, exc) return exc, err } return nil, nil }
go
func (session *ProxySession) DeleteParticipant(participantID string) (exception *Exception, err error) { twilioUrl := fmt.Sprintf("%s/%s/%s/%s/%s/%s/%s", ProxyBaseUrl, "Services", session.ServiceSid, "Sessions", session.Sid, "Participants", participantID) res, err := session.twilio.delete(twilioUrl) if err != nil { return exception, err } respBody, err := ioutil.ReadAll(res.Body) if err != nil { return nil, err } if res.StatusCode != http.StatusNoContent { exc := new(Exception) err = json.Unmarshal(respBody, exc) return exc, err } return nil, nil }
[ "func", "(", "session", "*", "ProxySession", ")", "DeleteParticipant", "(", "participantID", "string", ")", "(", "exception", "*", "Exception", ",", "err", "error", ")", "{", "twilioUrl", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "ProxyBaseUrl", "...
// Participants cannot be changed once added. To add a new Participant, delete a Participant and add a new one.
[ "Participants", "cannot", "be", "changed", "once", "added", ".", "To", "add", "a", "new", "Participant", "delete", "a", "Participant", "and", "add", "a", "new", "one", "." ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/proxy_participant.go#L179-L199
train
sfreiberg/gotwilio
gotwilio.go
NewTwilioClientCustomHTTP
func NewTwilioClientCustomHTTP(accountSid, authToken string, HTTPClient *http.Client) *Twilio { if HTTPClient == nil { HTTPClient = defaultClient } return &Twilio{ AccountSid: accountSid, AuthToken: authToken, BaseUrl: baseURL, VideoUrl: videoURL, HTTPClient: HTTPClient, } }
go
func NewTwilioClientCustomHTTP(accountSid, authToken string, HTTPClient *http.Client) *Twilio { if HTTPClient == nil { HTTPClient = defaultClient } return &Twilio{ AccountSid: accountSid, AuthToken: authToken, BaseUrl: baseURL, VideoUrl: videoURL, HTTPClient: HTTPClient, } }
[ "func", "NewTwilioClientCustomHTTP", "(", "accountSid", ",", "authToken", "string", ",", "HTTPClient", "*", "http", ".", "Client", ")", "*", "Twilio", "{", "if", "HTTPClient", "==", "nil", "{", "HTTPClient", "=", "defaultClient", "\n", "}", "\n\n", "return", ...
// Create a new Twilio client, optionally using a custom http.Client
[ "Create", "a", "new", "Twilio", "client", "optionally", "using", "a", "custom", "http", ".", "Client" ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/gotwilio.go#L49-L61
train
sfreiberg/gotwilio
fax.go
DateCreatedAsTime
func (d *FaxBase) DateCreatedAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, d.DateCreated) }
go
func (d *FaxBase) DateCreatedAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, d.DateCreated) }
[ "func", "(", "d", "*", "FaxBase", ")", "DateCreatedAsTime", "(", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "return", "time", ".", "Parse", "(", "time", ".", "RFC1123Z", ",", "d", ".", "DateCreated", ")", "\n", "}" ]
// DateCreatedAsTime returns FaxBase.DateCreated as a time.Time object // instead of a string.
[ "DateCreatedAsTime", "returns", "FaxBase", ".", "DateCreated", "as", "a", "time", ".", "Time", "object", "instead", "of", "a", "string", "." ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/fax.go#L20-L22
train
sfreiberg/gotwilio
fax.go
DateUpdatesAsTime
func (d *FaxBase) DateUpdatesAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, d.DateUpdated) }
go
func (d *FaxBase) DateUpdatesAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, d.DateUpdated) }
[ "func", "(", "d", "*", "FaxBase", ")", "DateUpdatesAsTime", "(", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "return", "time", ".", "Parse", "(", "time", ".", "RFC1123Z", ",", "d", ".", "DateUpdated", ")", "\n", "}" ]
// DateUpdatesAsTime returns FaxBase.DateUpdated as a time.Time object // instead of a string.
[ "DateUpdatesAsTime", "returns", "FaxBase", ".", "DateUpdated", "as", "a", "time", ".", "Time", "object", "instead", "of", "a", "string", "." ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/fax.go#L26-L28
train
sfreiberg/gotwilio
sms.go
DateCreatedAsTime
func (sms *SmsResponse) DateCreatedAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, sms.DateCreated) }
go
func (sms *SmsResponse) DateCreatedAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, sms.DateCreated) }
[ "func", "(", "sms", "*", "SmsResponse", ")", "DateCreatedAsTime", "(", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "return", "time", ".", "Parse", "(", "time", ".", "RFC1123Z", ",", "sms", ".", "DateCreated", ")", "\n", "}" ]
// DateCreatedAsTime returns SmsResponse.DateCreated as a time.Time object // instead of a string.
[ "DateCreatedAsTime", "returns", "SmsResponse", ".", "DateCreated", "as", "a", "time", ".", "Time", "object", "instead", "of", "a", "string", "." ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/sms.go#L31-L33
train
sfreiberg/gotwilio
sms.go
DateUpdateAsTime
func (sms *SmsResponse) DateUpdateAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, sms.DateUpdate) }
go
func (sms *SmsResponse) DateUpdateAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, sms.DateUpdate) }
[ "func", "(", "sms", "*", "SmsResponse", ")", "DateUpdateAsTime", "(", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "return", "time", ".", "Parse", "(", "time", ".", "RFC1123Z", ",", "sms", ".", "DateUpdate", ")", "\n", "}" ]
// DateUpdateAsTime returns SmsResponse.DateUpdate as a time.Time object // instead of a string.
[ "DateUpdateAsTime", "returns", "SmsResponse", ".", "DateUpdate", "as", "a", "time", ".", "Time", "object", "instead", "of", "a", "string", "." ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/sms.go#L37-L39
train
sfreiberg/gotwilio
sms.go
DateSentAsTime
func (sms *SmsResponse) DateSentAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, sms.DateSent) }
go
func (sms *SmsResponse) DateSentAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, sms.DateSent) }
[ "func", "(", "sms", "*", "SmsResponse", ")", "DateSentAsTime", "(", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "return", "time", ".", "Parse", "(", "time", ".", "RFC1123Z", ",", "sms", ".", "DateSent", ")", "\n", "}" ]
// DateSentAsTime returns SmsResponse.DateSent as a time.Time object // instead of a string.
[ "DateSentAsTime", "returns", "SmsResponse", ".", "DateSent", "as", "a", "time", ".", "Time", "object", "instead", "of", "a", "string", "." ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/sms.go#L43-L45
train
sfreiberg/gotwilio
sms.go
sendMessage
func (twilio *Twilio) sendMessage(formValues url.Values) (smsResponse *SmsResponse, exception *Exception, err error) { twilioUrl := twilio.BaseUrl + "/Accounts/" + twilio.AccountSid + "/Messages.json" res, err := twilio.post(formValues, twilioUrl) if err != nil { return smsResponse, exception, err } defer res.Body.Close() responseBody, err := ioutil.ReadAll(res.Body) if err != nil { return smsResponse, exception, err } if res.StatusCode != http.StatusCreated { exception = new(Exception) err = json.Unmarshal(responseBody, exception) // We aren't checking the error because we don't actually care. // It's going to be passed to the client either way. return smsResponse, exception, err } smsResponse = new(SmsResponse) err = json.Unmarshal(responseBody, smsResponse) return smsResponse, exception, err }
go
func (twilio *Twilio) sendMessage(formValues url.Values) (smsResponse *SmsResponse, exception *Exception, err error) { twilioUrl := twilio.BaseUrl + "/Accounts/" + twilio.AccountSid + "/Messages.json" res, err := twilio.post(formValues, twilioUrl) if err != nil { return smsResponse, exception, err } defer res.Body.Close() responseBody, err := ioutil.ReadAll(res.Body) if err != nil { return smsResponse, exception, err } if res.StatusCode != http.StatusCreated { exception = new(Exception) err = json.Unmarshal(responseBody, exception) // We aren't checking the error because we don't actually care. // It's going to be passed to the client either way. return smsResponse, exception, err } smsResponse = new(SmsResponse) err = json.Unmarshal(responseBody, smsResponse) return smsResponse, exception, err }
[ "func", "(", "twilio", "*", "Twilio", ")", "sendMessage", "(", "formValues", "url", ".", "Values", ")", "(", "smsResponse", "*", "SmsResponse", ",", "exception", "*", "Exception", ",", "err", "error", ")", "{", "twilioUrl", ":=", "twilio", ".", "BaseUrl", ...
// Core method to send message
[ "Core", "method", "to", "send", "message" ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/sms.go#L107-L133
train
sfreiberg/gotwilio
voice.go
DateCreatedAsTime
func (vr *VoiceResponse) DateCreatedAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, vr.DateCreated) }
go
func (vr *VoiceResponse) DateCreatedAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, vr.DateCreated) }
[ "func", "(", "vr", "*", "VoiceResponse", ")", "DateCreatedAsTime", "(", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "return", "time", ".", "Parse", "(", "time", ".", "RFC1123Z", ",", "vr", ".", "DateCreated", ")", "\n", "}" ]
// DateCreatedAsTime returns VoiceResponse.DateCreated as a time.Time object // instead of a string.
[ "DateCreatedAsTime", "returns", "VoiceResponse", ".", "DateCreated", "as", "a", "time", ".", "Time", "object", "instead", "of", "a", "string", "." ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/voice.go#L65-L67
train
sfreiberg/gotwilio
voice.go
DateUpdatedAsTime
func (vr *VoiceResponse) DateUpdatedAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, vr.DateUpdated) }
go
func (vr *VoiceResponse) DateUpdatedAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, vr.DateUpdated) }
[ "func", "(", "vr", "*", "VoiceResponse", ")", "DateUpdatedAsTime", "(", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "return", "time", ".", "Parse", "(", "time", ".", "RFC1123Z", ",", "vr", ".", "DateUpdated", ")", "\n", "}" ]
// DateUpdatedAsTime returns VoiceResponse.DateUpdated as a time.Time object // instead of a string.
[ "DateUpdatedAsTime", "returns", "VoiceResponse", ".", "DateUpdated", "as", "a", "time", ".", "Time", "object", "instead", "of", "a", "string", "." ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/voice.go#L71-L73
train
sfreiberg/gotwilio
voice.go
StartTimeAsTime
func (vr *VoiceResponse) StartTimeAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, vr.StartTime) }
go
func (vr *VoiceResponse) StartTimeAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, vr.StartTime) }
[ "func", "(", "vr", "*", "VoiceResponse", ")", "StartTimeAsTime", "(", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "return", "time", ".", "Parse", "(", "time", ".", "RFC1123Z", ",", "vr", ".", "StartTime", ")", "\n", "}" ]
// StartTimeAsTime returns VoiceResponse.StartTime as a time.Time object // instead of a string.
[ "StartTimeAsTime", "returns", "VoiceResponse", ".", "StartTime", "as", "a", "time", ".", "Time", "object", "instead", "of", "a", "string", "." ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/voice.go#L77-L79
train
sfreiberg/gotwilio
voice.go
EndTimeAsTime
func (vr *VoiceResponse) EndTimeAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, vr.EndTime) }
go
func (vr *VoiceResponse) EndTimeAsTime() (time.Time, error) { return time.Parse(time.RFC1123Z, vr.EndTime) }
[ "func", "(", "vr", "*", "VoiceResponse", ")", "EndTimeAsTime", "(", ")", "(", "time", ".", "Time", ",", "error", ")", "{", "return", "time", ".", "Parse", "(", "time", ".", "RFC1123Z", ",", "vr", ".", "EndTime", ")", "\n", "}" ]
// EndTimeAsTime returns VoiceResponse.EndTime as a time.Time object // instead of a string.
[ "EndTimeAsTime", "returns", "VoiceResponse", ".", "EndTime", "as", "a", "time", ".", "Time", "object", "instead", "of", "a", "string", "." ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/voice.go#L83-L85
train
sfreiberg/gotwilio
voice.go
CallWithUrlCallbacks
func (twilio *Twilio) CallWithUrlCallbacks(from, to string, callbackParameters *CallbackParameters) (*VoiceResponse, *Exception, error) { formValues := url.Values{} formValues.Set("From", from) formValues.Set("To", to) formValues.Set("Url", callbackParameters.Url) // Optional values if callbackParameters.Method != "" { formValues.Set("Method", callbackParameters.Method) } if callbackParameters.FallbackUrl != "" { formValues.Set("FallbackUrl", callbackParameters.FallbackUrl) } if callbackParameters.FallbackMethod != "" { formValues.Set("FallbackMethod", callbackParameters.FallbackMethod) } if callbackParameters.StatusCallback != "" { formValues.Set("StatusCallback", callbackParameters.StatusCallback) } if callbackParameters.StatusCallbackMethod != "" { formValues.Set("StatusCallbackMethod", callbackParameters.StatusCallbackMethod) } for _, event := range callbackParameters.StatusCallbackEvent { formValues.Add("StatusCallbackEvent", event) } if callbackParameters.SendDigits != "" { formValues.Set("SendDigits", callbackParameters.SendDigits) } if callbackParameters.IfMachine != "" { formValues.Set("IfMachine", callbackParameters.IfMachine) } if callbackParameters.Timeout != 0 { formValues.Set("Timeout", strconv.Itoa(callbackParameters.Timeout)) } if callbackParameters.MachineDetection != "" { formValues.Set("MachineDetection", callbackParameters.MachineDetection) } if callbackParameters.MachineDetectionTimeout != 0 { formValues.Set( "MachineDetectionTimeout", strconv.Itoa(callbackParameters.MachineDetectionTimeout), ) } if callbackParameters.Record { formValues.Set("Record", "true") if callbackParameters.RecordingChannels != "" { formValues.Set("RecordingChannels", callbackParameters.RecordingChannels) } if callbackParameters.RecordingStatusCallback != "" { formValues.Set("RecordingStatusCallback", callbackParameters.RecordingStatusCallback) } if callbackParameters.RecordingStatusCallbackMethod != "" { formValues.Set("RecordingStatusCallbackMethod", callbackParameters.RecordingStatusCallbackMethod) } } else { formValues.Set("Record", "false") } return twilio.voicePost(formValues) }
go
func (twilio *Twilio) CallWithUrlCallbacks(from, to string, callbackParameters *CallbackParameters) (*VoiceResponse, *Exception, error) { formValues := url.Values{} formValues.Set("From", from) formValues.Set("To", to) formValues.Set("Url", callbackParameters.Url) // Optional values if callbackParameters.Method != "" { formValues.Set("Method", callbackParameters.Method) } if callbackParameters.FallbackUrl != "" { formValues.Set("FallbackUrl", callbackParameters.FallbackUrl) } if callbackParameters.FallbackMethod != "" { formValues.Set("FallbackMethod", callbackParameters.FallbackMethod) } if callbackParameters.StatusCallback != "" { formValues.Set("StatusCallback", callbackParameters.StatusCallback) } if callbackParameters.StatusCallbackMethod != "" { formValues.Set("StatusCallbackMethod", callbackParameters.StatusCallbackMethod) } for _, event := range callbackParameters.StatusCallbackEvent { formValues.Add("StatusCallbackEvent", event) } if callbackParameters.SendDigits != "" { formValues.Set("SendDigits", callbackParameters.SendDigits) } if callbackParameters.IfMachine != "" { formValues.Set("IfMachine", callbackParameters.IfMachine) } if callbackParameters.Timeout != 0 { formValues.Set("Timeout", strconv.Itoa(callbackParameters.Timeout)) } if callbackParameters.MachineDetection != "" { formValues.Set("MachineDetection", callbackParameters.MachineDetection) } if callbackParameters.MachineDetectionTimeout != 0 { formValues.Set( "MachineDetectionTimeout", strconv.Itoa(callbackParameters.MachineDetectionTimeout), ) } if callbackParameters.Record { formValues.Set("Record", "true") if callbackParameters.RecordingChannels != "" { formValues.Set("RecordingChannels", callbackParameters.RecordingChannels) } if callbackParameters.RecordingStatusCallback != "" { formValues.Set("RecordingStatusCallback", callbackParameters.RecordingStatusCallback) } if callbackParameters.RecordingStatusCallbackMethod != "" { formValues.Set("RecordingStatusCallbackMethod", callbackParameters.RecordingStatusCallbackMethod) } } else { formValues.Set("Record", "false") } return twilio.voicePost(formValues) }
[ "func", "(", "twilio", "*", "Twilio", ")", "CallWithUrlCallbacks", "(", "from", ",", "to", "string", ",", "callbackParameters", "*", "CallbackParameters", ")", "(", "*", "VoiceResponse", ",", "*", "Exception", ",", "error", ")", "{", "formValues", ":=", "url...
// Place a voice call with a list of callbacks specified.
[ "Place", "a", "voice", "call", "with", "a", "list", "of", "callbacks", "specified", "." ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/voice.go#L122-L183
train
sfreiberg/gotwilio
voice.go
CallWithApplicationCallbacks
func (twilio *Twilio) CallWithApplicationCallbacks(from, to, applicationSid string) (*VoiceResponse, *Exception, error) { formValues := url.Values{} formValues.Set("From", from) formValues.Set("To", to) formValues.Set("ApplicationSid", applicationSid) return twilio.voicePost(formValues) }
go
func (twilio *Twilio) CallWithApplicationCallbacks(from, to, applicationSid string) (*VoiceResponse, *Exception, error) { formValues := url.Values{} formValues.Set("From", from) formValues.Set("To", to) formValues.Set("ApplicationSid", applicationSid) return twilio.voicePost(formValues) }
[ "func", "(", "twilio", "*", "Twilio", ")", "CallWithApplicationCallbacks", "(", "from", ",", "to", ",", "applicationSid", "string", ")", "(", "*", "VoiceResponse", ",", "*", "Exception", ",", "error", ")", "{", "formValues", ":=", "url", ".", "Values", "{"...
// Place a voice call with an ApplicationSid specified.
[ "Place", "a", "voice", "call", "with", "an", "ApplicationSid", "specified", "." ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/voice.go#L186-L193
train
sfreiberg/gotwilio
voice.go
voicePost
func (twilio *Twilio) voicePost(formValues url.Values) (*VoiceResponse, *Exception, error) { var voiceResponse *VoiceResponse var exception *Exception twilioUrl := twilio.BaseUrl + "/Accounts/" + twilio.AccountSid + "/Calls.json" res, err := twilio.post(formValues, twilioUrl) if err != nil { return voiceResponse, exception, err } defer res.Body.Close() decoder := json.NewDecoder(res.Body) if res.StatusCode != http.StatusCreated { exception = new(Exception) err = decoder.Decode(exception) // We aren't checking the error because we don't actually care. // It's going to be passed to the client either way. return voiceResponse, exception, err } voiceResponse = new(VoiceResponse) err = decoder.Decode(voiceResponse) return voiceResponse, exception, err }
go
func (twilio *Twilio) voicePost(formValues url.Values) (*VoiceResponse, *Exception, error) { var voiceResponse *VoiceResponse var exception *Exception twilioUrl := twilio.BaseUrl + "/Accounts/" + twilio.AccountSid + "/Calls.json" res, err := twilio.post(formValues, twilioUrl) if err != nil { return voiceResponse, exception, err } defer res.Body.Close() decoder := json.NewDecoder(res.Body) if res.StatusCode != http.StatusCreated { exception = new(Exception) err = decoder.Decode(exception) // We aren't checking the error because we don't actually care. // It's going to be passed to the client either way. return voiceResponse, exception, err } voiceResponse = new(VoiceResponse) err = decoder.Decode(voiceResponse) return voiceResponse, exception, err }
[ "func", "(", "twilio", "*", "Twilio", ")", "voicePost", "(", "formValues", "url", ".", "Values", ")", "(", "*", "VoiceResponse", ",", "*", "Exception", ",", "error", ")", "{", "var", "voiceResponse", "*", "VoiceResponse", "\n", "var", "exception", "*", "...
// This is a private method that has the common bits for making a voice call.
[ "This", "is", "a", "private", "method", "that", "has", "the", "common", "bits", "for", "making", "a", "voice", "call", "." ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/voice.go#L196-L221
train
sfreiberg/gotwilio
util.go
CheckRequestSignature
func (twilio *Twilio) CheckRequestSignature(r *http.Request, baseURL string) (bool, error) { if r.Method != "POST" { return false, errors.New("Checking signatures on non-POST requests is not implemented") } if err := r.ParseForm(); err != nil { return false, err } url := baseURL + r.URL.String() expected, err := twilio.GenerateSignature(url, r.PostForm) if err != nil { return false, err } actual := r.Header.Get("X-Twilio-Signature") if actual == "" { return false, errors.New("Request does not have a twilio signature header") } return hmac.Equal(expected, []byte(actual)), nil }
go
func (twilio *Twilio) CheckRequestSignature(r *http.Request, baseURL string) (bool, error) { if r.Method != "POST" { return false, errors.New("Checking signatures on non-POST requests is not implemented") } if err := r.ParseForm(); err != nil { return false, err } url := baseURL + r.URL.String() expected, err := twilio.GenerateSignature(url, r.PostForm) if err != nil { return false, err } actual := r.Header.Get("X-Twilio-Signature") if actual == "" { return false, errors.New("Request does not have a twilio signature header") } return hmac.Equal(expected, []byte(actual)), nil }
[ "func", "(", "twilio", "*", "Twilio", ")", "CheckRequestSignature", "(", "r", "*", "http", ".", "Request", ",", "baseURL", "string", ")", "(", "bool", ",", "error", ")", "{", "if", "r", ".", "Method", "!=", "\"", "\"", "{", "return", "false", ",", ...
// CheckRequestSignature checks that the X-Twilio-Signature header on a request // matches the expected signature defined by the GenerateSignature function. // // The baseUrl parameter will be prepended to the request URL. It is useful for // specifying the protocol and host parts of the server URL hosting your endpoint. // // Passing a non-POST request or a request without the X-Twilio-Signature // header is an error.
[ "CheckRequestSignature", "checks", "that", "the", "X", "-", "Twilio", "-", "Signature", "header", "on", "a", "request", "matches", "the", "expected", "signature", "defined", "by", "the", "GenerateSignature", "function", ".", "The", "baseUrl", "parameter", "will", ...
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/util.go#L62-L84
train
sfreiberg/gotwilio
access_token.go
NewAccessToken
func (twilio *Twilio) NewAccessToken() *AccessToken { return &AccessToken{ AccountSid: twilio.AccountSid, APIKeySid: twilio.APIKeySid, APIKeySecret: twilio.APIKeySecret, } }
go
func (twilio *Twilio) NewAccessToken() *AccessToken { return &AccessToken{ AccountSid: twilio.AccountSid, APIKeySid: twilio.APIKeySid, APIKeySecret: twilio.APIKeySecret, } }
[ "func", "(", "twilio", "*", "Twilio", ")", "NewAccessToken", "(", ")", "*", "AccessToken", "{", "return", "&", "AccessToken", "{", "AccountSid", ":", "twilio", ".", "AccountSid", ",", "APIKeySid", ":", "twilio", ".", "APIKeySid", ",", "APIKeySecret", ":", ...
// NewAccessToken creates a new Access Token which // can be used to authenticate Twilio Client SDKs // for a short period of time.
[ "NewAccessToken", "creates", "a", "new", "Access", "Token", "which", "can", "be", "used", "to", "authenticate", "Twilio", "Client", "SDKs", "for", "a", "short", "period", "of", "time", "." ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/access_token.go#L45-L51
train
sfreiberg/gotwilio
access_token.go
AddGrant
func (a *AccessToken) AddGrant(grant Grant) *AccessToken { a.Grants = append(a.Grants, grant) return a }
go
func (a *AccessToken) AddGrant(grant Grant) *AccessToken { a.Grants = append(a.Grants, grant) return a }
[ "func", "(", "a", "*", "AccessToken", ")", "AddGrant", "(", "grant", "Grant", ")", "*", "AccessToken", "{", "a", ".", "Grants", "=", "append", "(", "a", ".", "Grants", ",", "grant", ")", "\n", "return", "a", "\n", "}" ]
// AddGrant adds a given Grant to the Access Token.
[ "AddGrant", "adds", "a", "given", "Grant", "to", "the", "Access", "Token", "." ]
4c78e78c98b65cf3b9ab4edbe635d4080c6db6da
https://github.com/sfreiberg/gotwilio/blob/4c78e78c98b65cf3b9ab4edbe635d4080c6db6da/access_token.go#L54-L57
train
kr/pty
run.go
Start
func Start(c *exec.Cmd) (pty *os.File, err error) { return StartWithSize(c, nil) }
go
func Start(c *exec.Cmd) (pty *os.File, err error) { return StartWithSize(c, nil) }
[ "func", "Start", "(", "c", "*", "exec", ".", "Cmd", ")", "(", "pty", "*", "os", ".", "File", ",", "err", "error", ")", "{", "return", "StartWithSize", "(", "c", ",", "nil", ")", "\n", "}" ]
// Start assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout, // and c.Stderr, calls c.Start, and returns the File of the tty's // corresponding pty.
[ "Start", "assigns", "a", "pseudo", "-", "terminal", "tty", "os", ".", "File", "to", "c", ".", "Stdin", "c", ".", "Stdout", "and", "c", ".", "Stderr", "calls", "c", ".", "Start", "and", "returns", "the", "File", "of", "the", "tty", "s", "corresponding...
b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17
https://github.com/kr/pty/blob/b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17/run.go#L14-L16
train
kr/pty
run.go
StartWithSize
func StartWithSize(c *exec.Cmd, sz *Winsize) (pty *os.File, err error) { pty, tty, err := Open() if err != nil { return nil, err } defer tty.Close() if sz != nil { err = Setsize(pty, sz) if err != nil { pty.Close() return nil, err } } if c.Stdout == nil { c.Stdout = tty } if c.Stderr == nil { c.Stderr = tty } if c.Stdin == nil { c.Stdin = tty } if c.SysProcAttr == nil { c.SysProcAttr = &syscall.SysProcAttr{} } c.SysProcAttr.Setctty = true c.SysProcAttr.Setsid = true c.SysProcAttr.Ctty = int(tty.Fd()) err = c.Start() if err != nil { pty.Close() return nil, err } return pty, err }
go
func StartWithSize(c *exec.Cmd, sz *Winsize) (pty *os.File, err error) { pty, tty, err := Open() if err != nil { return nil, err } defer tty.Close() if sz != nil { err = Setsize(pty, sz) if err != nil { pty.Close() return nil, err } } if c.Stdout == nil { c.Stdout = tty } if c.Stderr == nil { c.Stderr = tty } if c.Stdin == nil { c.Stdin = tty } if c.SysProcAttr == nil { c.SysProcAttr = &syscall.SysProcAttr{} } c.SysProcAttr.Setctty = true c.SysProcAttr.Setsid = true c.SysProcAttr.Ctty = int(tty.Fd()) err = c.Start() if err != nil { pty.Close() return nil, err } return pty, err }
[ "func", "StartWithSize", "(", "c", "*", "exec", ".", "Cmd", ",", "sz", "*", "Winsize", ")", "(", "pty", "*", "os", ".", "File", ",", "err", "error", ")", "{", "pty", ",", "tty", ",", "err", ":=", "Open", "(", ")", "\n", "if", "err", "!=", "ni...
// StartWithSize assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout, // and c.Stderr, calls c.Start, and returns the File of the tty's // corresponding pty. // // This will resize the pty to the specified size before starting the command
[ "StartWithSize", "assigns", "a", "pseudo", "-", "terminal", "tty", "os", ".", "File", "to", "c", ".", "Stdin", "c", ".", "Stdout", "and", "c", ".", "Stderr", "calls", "c", ".", "Start", "and", "returns", "the", "File", "of", "the", "tty", "s", "corre...
b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17
https://github.com/kr/pty/blob/b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17/run.go#L23-L57
train
kr/pty
pty_dragonfly.go
open
func open() (pty, tty *os.File, err error) { p, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0) if err != nil { return nil, nil, err } // In case of error after this point, make sure we close the ptmx fd. defer func() { if err != nil { _ = p.Close() // Best effort. } }() sname, err := ptsname(p) if err != nil { return nil, nil, err } if err := grantpt(p); err != nil { return nil, nil, err } if err := unlockpt(p); err != nil { return nil, nil, err } t, err := os.OpenFile(sname, os.O_RDWR, 0) if err != nil { return nil, nil, err } return p, t, nil }
go
func open() (pty, tty *os.File, err error) { p, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0) if err != nil { return nil, nil, err } // In case of error after this point, make sure we close the ptmx fd. defer func() { if err != nil { _ = p.Close() // Best effort. } }() sname, err := ptsname(p) if err != nil { return nil, nil, err } if err := grantpt(p); err != nil { return nil, nil, err } if err := unlockpt(p); err != nil { return nil, nil, err } t, err := os.OpenFile(sname, os.O_RDWR, 0) if err != nil { return nil, nil, err } return p, t, nil }
[ "func", "open", "(", ")", "(", "pty", ",", "tty", "*", "os", ".", "File", ",", "err", "error", ")", "{", "p", ",", "err", ":=", "os", ".", "OpenFile", "(", "\"", "\"", ",", "os", ".", "O_RDWR", ",", "0", ")", "\n", "if", "err", "!=", "nil",...
// same code as pty_darwin.go
[ "same", "code", "as", "pty_darwin", ".", "go" ]
b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17
https://github.com/kr/pty/blob/b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17/pty_dragonfly.go#L12-L42
train
kr/pty
util.go
InheritSize
func InheritSize(pty, tty *os.File) error { size, err := GetsizeFull(pty) if err != nil { return err } err = Setsize(tty, size) if err != nil { return err } return nil }
go
func InheritSize(pty, tty *os.File) error { size, err := GetsizeFull(pty) if err != nil { return err } err = Setsize(tty, size) if err != nil { return err } return nil }
[ "func", "InheritSize", "(", "pty", ",", "tty", "*", "os", ".", "File", ")", "error", "{", "size", ",", "err", ":=", "GetsizeFull", "(", "pty", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "Setsize", "(",...
// InheritSize applies the terminal size of pty to tty. This should be run // in a signal handler for syscall.SIGWINCH to automatically resize the tty when // the pty receives a window size change notification.
[ "InheritSize", "applies", "the", "terminal", "size", "of", "pty", "to", "tty", ".", "This", "should", "be", "run", "in", "a", "signal", "handler", "for", "syscall", ".", "SIGWINCH", "to", "automatically", "resize", "the", "tty", "when", "the", "pty", "rece...
b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17
https://github.com/kr/pty/blob/b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17/util.go#L14-L24
train
kr/pty
util.go
Setsize
func Setsize(t *os.File, ws *Winsize) error { return windowRectCall(ws, t.Fd(), syscall.TIOCSWINSZ) }
go
func Setsize(t *os.File, ws *Winsize) error { return windowRectCall(ws, t.Fd(), syscall.TIOCSWINSZ) }
[ "func", "Setsize", "(", "t", "*", "os", ".", "File", ",", "ws", "*", "Winsize", ")", "error", "{", "return", "windowRectCall", "(", "ws", ",", "t", ".", "Fd", "(", ")", ",", "syscall", ".", "TIOCSWINSZ", ")", "\n", "}" ]
// Setsize resizes t to s.
[ "Setsize", "resizes", "t", "to", "s", "." ]
b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17
https://github.com/kr/pty/blob/b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17/util.go#L27-L29
train
kr/pty
util.go
GetsizeFull
func GetsizeFull(t *os.File) (size *Winsize, err error) { var ws Winsize err = windowRectCall(&ws, t.Fd(), syscall.TIOCGWINSZ) return &ws, err }
go
func GetsizeFull(t *os.File) (size *Winsize, err error) { var ws Winsize err = windowRectCall(&ws, t.Fd(), syscall.TIOCGWINSZ) return &ws, err }
[ "func", "GetsizeFull", "(", "t", "*", "os", ".", "File", ")", "(", "size", "*", "Winsize", ",", "err", "error", ")", "{", "var", "ws", "Winsize", "\n", "err", "=", "windowRectCall", "(", "&", "ws", ",", "t", ".", "Fd", "(", ")", ",", "syscall", ...
// GetsizeFull returns the full terminal size description.
[ "GetsizeFull", "returns", "the", "full", "terminal", "size", "description", "." ]
b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17
https://github.com/kr/pty/blob/b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17/util.go#L32-L36
train