repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
boombuler/barcode
ean/encoder.go
Encode
func Encode(code string) (barcode.BarcodeIntCS, error) { var checkSum int if len(code) == 7 || len(code) == 12 { code += string(calcCheckNum(code)) checkSum = utils.RuneToInt(calcCheckNum(code)) } else if len(code) == 8 || len(code) == 13 { check := code[0 : len(code)-1] check += string(calcCheckNum(check)) if check != code { return nil, errors.New("checksum missmatch") } checkSum = utils.RuneToInt(rune(code[len(code)-1])) } if len(code) == 8 { result := encodeEAN8(code) if result != nil { return utils.New1DCodeIntCheckSum(barcode.TypeEAN8, code, result, checkSum), nil } } else if len(code) == 13 { result := encodeEAN13(code) if result != nil { return utils.New1DCodeIntCheckSum(barcode.TypeEAN13, code, result, checkSum), nil } } return nil, errors.New("invalid ean code data") }
go
func Encode(code string) (barcode.BarcodeIntCS, error) { var checkSum int if len(code) == 7 || len(code) == 12 { code += string(calcCheckNum(code)) checkSum = utils.RuneToInt(calcCheckNum(code)) } else if len(code) == 8 || len(code) == 13 { check := code[0 : len(code)-1] check += string(calcCheckNum(check)) if check != code { return nil, errors.New("checksum missmatch") } checkSum = utils.RuneToInt(rune(code[len(code)-1])) } if len(code) == 8 { result := encodeEAN8(code) if result != nil { return utils.New1DCodeIntCheckSum(barcode.TypeEAN8, code, result, checkSum), nil } } else if len(code) == 13 { result := encodeEAN13(code) if result != nil { return utils.New1DCodeIntCheckSum(barcode.TypeEAN13, code, result, checkSum), nil } } return nil, errors.New("invalid ean code data") }
[ "func", "Encode", "(", "code", "string", ")", "(", "barcode", ".", "BarcodeIntCS", ",", "error", ")", "{", "var", "checkSum", "int", "\n", "if", "len", "(", "code", ")", "==", "7", "||", "len", "(", "code", ")", "==", "12", "{", "code", "+=", "st...
// Encode returns a EAN 8 or EAN 13 barcode for the given code
[ "Encode", "returns", "a", "EAN", "8", "or", "EAN", "13", "barcode", "for", "the", "given", "code" ]
6c824513baccd76c674ce72112c29ef550187b08
https://github.com/boombuler/barcode/blob/6c824513baccd76c674ce72112c29ef550187b08/ean/encoder.go#L161-L187
train
boombuler/barcode
aztec/state.go
shiftAndAppend
func (s *state) shiftAndAppend(mode encodingMode, value int) *state { tokens := s.tokens // Shifts exist only to UPPER and PUNCT, both with tokens size 5. tokens = newSimpleToken(tokens, shiftTable[s.mode][mode], s.mode.BitCount()) tokens = newSimpleToken(tokens, value, 5) return &state{ mode: s.mode, tokens: tokens, bShiftByteCount: 0, bitCount: s.bitCount + int(s.mode.BitCount()) + 5, } }
go
func (s *state) shiftAndAppend(mode encodingMode, value int) *state { tokens := s.tokens // Shifts exist only to UPPER and PUNCT, both with tokens size 5. tokens = newSimpleToken(tokens, shiftTable[s.mode][mode], s.mode.BitCount()) tokens = newSimpleToken(tokens, value, 5) return &state{ mode: s.mode, tokens: tokens, bShiftByteCount: 0, bitCount: s.bitCount + int(s.mode.BitCount()) + 5, } }
[ "func", "(", "s", "*", "state", ")", "shiftAndAppend", "(", "mode", "encodingMode", ",", "value", "int", ")", "*", "state", "{", "tokens", ":=", "s", ".", "tokens", "\n", "tokens", "=", "newSimpleToken", "(", "tokens", ",", "shiftTable", "[", "s", ".",...
// Create a new state representing this state, with a temporary shift // to a different mode to output a single value.
[ "Create", "a", "new", "state", "representing", "this", "state", "with", "a", "temporary", "shift", "to", "a", "different", "mode", "to", "output", "a", "single", "value", "." ]
6c824513baccd76c674ce72112c29ef550187b08
https://github.com/boombuler/barcode/blob/6c824513baccd76c674ce72112c29ef550187b08/aztec/state.go#L171-L184
train
boombuler/barcode
aztec/state.go
addBinaryShiftChar
func (s *state) addBinaryShiftChar(index int) *state { tokens := s.tokens mode := s.mode bitCnt := s.bitCount if s.mode == mode_punct || s.mode == mode_digit { latch := latchTable[s.mode][mode_upper] tokens = newSimpleToken(tokens, latch&0xFFFF, byte(latch>>16)) bitCnt += latch >> 16 mode = mode_upper } deltaBitCount := 8 if s.bShiftByteCount == 0 || s.bShiftByteCount == 31 { deltaBitCount = 18 } else if s.bShiftByteCount == 62 { deltaBitCount = 9 } result := &state{ mode: mode, tokens: tokens, bShiftByteCount: s.bShiftByteCount + 1, bitCount: bitCnt + deltaBitCount, } if result.bShiftByteCount == 2047+31 { // The string is as long as it's allowed to be. We should end it. result = result.endBinaryShift(index + 1) } return result }
go
func (s *state) addBinaryShiftChar(index int) *state { tokens := s.tokens mode := s.mode bitCnt := s.bitCount if s.mode == mode_punct || s.mode == mode_digit { latch := latchTable[s.mode][mode_upper] tokens = newSimpleToken(tokens, latch&0xFFFF, byte(latch>>16)) bitCnt += latch >> 16 mode = mode_upper } deltaBitCount := 8 if s.bShiftByteCount == 0 || s.bShiftByteCount == 31 { deltaBitCount = 18 } else if s.bShiftByteCount == 62 { deltaBitCount = 9 } result := &state{ mode: mode, tokens: tokens, bShiftByteCount: s.bShiftByteCount + 1, bitCount: bitCnt + deltaBitCount, } if result.bShiftByteCount == 2047+31 { // The string is as long as it's allowed to be. We should end it. result = result.endBinaryShift(index + 1) } return result }
[ "func", "(", "s", "*", "state", ")", "addBinaryShiftChar", "(", "index", "int", ")", "*", "state", "{", "tokens", ":=", "s", ".", "tokens", "\n", "mode", ":=", "s", ".", "mode", "\n", "bitCnt", ":=", "s", ".", "bitCount", "\n", "if", "s", ".", "m...
// Create a new state representing this state, but an additional character // output in Binary Shift mode.
[ "Create", "a", "new", "state", "representing", "this", "state", "but", "an", "additional", "character", "output", "in", "Binary", "Shift", "mode", "." ]
6c824513baccd76c674ce72112c29ef550187b08
https://github.com/boombuler/barcode/blob/6c824513baccd76c674ce72112c29ef550187b08/aztec/state.go#L188-L216
train
boombuler/barcode
aztec/state.go
endBinaryShift
func (s *state) endBinaryShift(index int) *state { if s.bShiftByteCount == 0 { return s } tokens := newShiftToken(s.tokens, index-s.bShiftByteCount, s.bShiftByteCount) return &state{ mode: s.mode, tokens: tokens, bShiftByteCount: 0, bitCount: s.bitCount, } }
go
func (s *state) endBinaryShift(index int) *state { if s.bShiftByteCount == 0 { return s } tokens := newShiftToken(s.tokens, index-s.bShiftByteCount, s.bShiftByteCount) return &state{ mode: s.mode, tokens: tokens, bShiftByteCount: 0, bitCount: s.bitCount, } }
[ "func", "(", "s", "*", "state", ")", "endBinaryShift", "(", "index", "int", ")", "*", "state", "{", "if", "s", ".", "bShiftByteCount", "==", "0", "{", "return", "s", "\n", "}", "\n", "tokens", ":=", "newShiftToken", "(", "s", ".", "tokens", ",", "i...
// Create the state identical to this one, but we are no longer in // Binary Shift mode.
[ "Create", "the", "state", "identical", "to", "this", "one", "but", "we", "are", "no", "longer", "in", "Binary", "Shift", "mode", "." ]
6c824513baccd76c674ce72112c29ef550187b08
https://github.com/boombuler/barcode/blob/6c824513baccd76c674ce72112c29ef550187b08/aztec/state.go#L220-L231
train
boombuler/barcode
datamatrix/encoder.go
Encode
func Encode(content string) (barcode.Barcode, error) { data := encodeText(content) var size *dmCodeSize for _, s := range codeSizes { if s.DataCodewords() >= len(data) { size = s break } } if size == nil { return nil, errors.New("to much data to encode") } data = addPadding(data, size.DataCodewords()) data = ec.calcECC(data, size) code := render(data, size) if code != nil { code.content = content return code, nil } return nil, errors.New("unable to render barcode") }
go
func Encode(content string) (barcode.Barcode, error) { data := encodeText(content) var size *dmCodeSize for _, s := range codeSizes { if s.DataCodewords() >= len(data) { size = s break } } if size == nil { return nil, errors.New("to much data to encode") } data = addPadding(data, size.DataCodewords()) data = ec.calcECC(data, size) code := render(data, size) if code != nil { code.content = content return code, nil } return nil, errors.New("unable to render barcode") }
[ "func", "Encode", "(", "content", "string", ")", "(", "barcode", ".", "Barcode", ",", "error", ")", "{", "data", ":=", "encodeText", "(", "content", ")", "\n", "var", "size", "*", "dmCodeSize", "\n", "for", "_", ",", "s", ":=", "range", "codeSizes", ...
// Encode returns a Datamatrix barcode for the given content
[ "Encode", "returns", "a", "Datamatrix", "barcode", "for", "the", "given", "content" ]
6c824513baccd76c674ce72112c29ef550187b08
https://github.com/boombuler/barcode/blob/6c824513baccd76c674ce72112c29ef550187b08/datamatrix/encoder.go#L11-L32
train
boombuler/barcode
pdf417/encoder.go
Encode
func Encode(data string, securityLevel byte) (barcode.Barcode, error) { if securityLevel >= 9 { return nil, fmt.Errorf("Invalid security level %d", securityLevel) } sl := securitylevel(securityLevel) dataWords, err := highlevelEncode(data) if err != nil { return nil, err } columns, rows := calcDimensions(len(dataWords), sl.ErrorCorrectionWordCount()) if columns < minCols || columns > maxCols || rows < minRows || rows > maxRows { return nil, fmt.Errorf("Unable to fit data in barcode") } barcode := new(pdfBarcode) barcode.data = data codeWords, err := encodeData(dataWords, columns, sl) if err != nil { return nil, err } grid := [][]int{} for i := 0; i < len(codeWords); i += columns { grid = append(grid, codeWords[i:min(i+columns, len(codeWords))]) } codes := [][]int{} for rowNum, row := range grid { table := rowNum % 3 rowCodes := make([]int, 0, columns+4) rowCodes = append(rowCodes, start_word) rowCodes = append(rowCodes, getCodeword(table, getLeftCodeWord(rowNum, rows, columns, securityLevel))) for _, word := range row { rowCodes = append(rowCodes, getCodeword(table, word)) } rowCodes = append(rowCodes, getCodeword(table, getRightCodeWord(rowNum, rows, columns, securityLevel))) rowCodes = append(rowCodes, stop_word) codes = append(codes, rowCodes) } barcode.code = renderBarcode(codes) barcode.width = (columns+4)*17 + 1 return barcode, nil }
go
func Encode(data string, securityLevel byte) (barcode.Barcode, error) { if securityLevel >= 9 { return nil, fmt.Errorf("Invalid security level %d", securityLevel) } sl := securitylevel(securityLevel) dataWords, err := highlevelEncode(data) if err != nil { return nil, err } columns, rows := calcDimensions(len(dataWords), sl.ErrorCorrectionWordCount()) if columns < minCols || columns > maxCols || rows < minRows || rows > maxRows { return nil, fmt.Errorf("Unable to fit data in barcode") } barcode := new(pdfBarcode) barcode.data = data codeWords, err := encodeData(dataWords, columns, sl) if err != nil { return nil, err } grid := [][]int{} for i := 0; i < len(codeWords); i += columns { grid = append(grid, codeWords[i:min(i+columns, len(codeWords))]) } codes := [][]int{} for rowNum, row := range grid { table := rowNum % 3 rowCodes := make([]int, 0, columns+4) rowCodes = append(rowCodes, start_word) rowCodes = append(rowCodes, getCodeword(table, getLeftCodeWord(rowNum, rows, columns, securityLevel))) for _, word := range row { rowCodes = append(rowCodes, getCodeword(table, word)) } rowCodes = append(rowCodes, getCodeword(table, getRightCodeWord(rowNum, rows, columns, securityLevel))) rowCodes = append(rowCodes, stop_word) codes = append(codes, rowCodes) } barcode.code = renderBarcode(codes) barcode.width = (columns+4)*17 + 1 return barcode, nil }
[ "func", "Encode", "(", "data", "string", ",", "securityLevel", "byte", ")", "(", "barcode", ".", "Barcode", ",", "error", ")", "{", "if", "securityLevel", ">=", "9", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Invalid security level %d\"", ","...
// Encodes the given data as PDF417 barcode. // securityLevel should be between 0 and 8. The higher the number, the more // additional error-correction codes are added.
[ "Encodes", "the", "given", "data", "as", "PDF417", "barcode", ".", "securityLevel", "should", "be", "between", "0", "and", "8", ".", "The", "higher", "the", "number", "the", "more", "additional", "error", "-", "correction", "codes", "are", "added", "." ]
6c824513baccd76c674ce72112c29ef550187b08
https://github.com/boombuler/barcode/blob/6c824513baccd76c674ce72112c29ef550187b08/pdf417/encoder.go#L18-L71
train
boombuler/barcode
scaledbarcode.go
Scale
func Scale(bc Barcode, width, height int) (Barcode, error) { switch bc.Metadata().Dimensions { case 1: return scale1DCode(bc, width, height) case 2: return scale2DCode(bc, width, height) } return nil, errors.New("unsupported barcode format") }
go
func Scale(bc Barcode, width, height int) (Barcode, error) { switch bc.Metadata().Dimensions { case 1: return scale1DCode(bc, width, height) case 2: return scale2DCode(bc, width, height) } return nil, errors.New("unsupported barcode format") }
[ "func", "Scale", "(", "bc", "Barcode", ",", "width", ",", "height", "int", ")", "(", "Barcode", ",", "error", ")", "{", "switch", "bc", ".", "Metadata", "(", ")", ".", "Dimensions", "{", "case", "1", ":", "return", "scale1DCode", "(", "bc", ",", "w...
// Scale returns a resized barcode with the given width and height.
[ "Scale", "returns", "a", "resized", "barcode", "with", "the", "given", "width", "and", "height", "." ]
6c824513baccd76c674ce72112c29ef550187b08
https://github.com/boombuler/barcode/blob/6c824513baccd76c674ce72112c29ef550187b08/scaledbarcode.go#L51-L60
train
boombuler/barcode
twooffive/encoder.go
AddCheckSum
func AddCheckSum(content string) (string, error) { if content == "" { return "", errors.New("content is empty") } even := len(content)%2 == 1 sum := 0 for _, r := range content { if _, ok := encodingTable[r]; ok { value := utils.RuneToInt(r) if even { sum += value * 3 } else { sum += value } even = !even } else { return "", fmt.Errorf("can not encode \"%s\"", content) } } return content + string(utils.IntToRune(sum%10)), nil }
go
func AddCheckSum(content string) (string, error) { if content == "" { return "", errors.New("content is empty") } even := len(content)%2 == 1 sum := 0 for _, r := range content { if _, ok := encodingTable[r]; ok { value := utils.RuneToInt(r) if even { sum += value * 3 } else { sum += value } even = !even } else { return "", fmt.Errorf("can not encode \"%s\"", content) } } return content + string(utils.IntToRune(sum%10)), nil }
[ "func", "AddCheckSum", "(", "content", "string", ")", "(", "string", ",", "error", ")", "{", "if", "content", "==", "\"\"", "{", "return", "\"\"", ",", "errors", ".", "New", "(", "\"content is empty\"", ")", "\n", "}", "\n", "even", ":=", "len", "(", ...
// AddCheckSum calculates the correct check-digit and appends it to the given content.
[ "AddCheckSum", "calculates", "the", "correct", "check", "-", "digit", "and", "appends", "it", "to", "the", "given", "content", "." ]
6c824513baccd76c674ce72112c29ef550187b08
https://github.com/boombuler/barcode/blob/6c824513baccd76c674ce72112c29ef550187b08/twooffive/encoder.go#L57-L79
train
thoas/go-funk
zip.go
Zip
func Zip(slice1 interface{}, slice2 interface{}) []Tuple { inValue1 := reflect.ValueOf(slice1) inValue2 := reflect.ValueOf(slice2) kind1 := inValue1.Type().Kind() kind2 := inValue2.Type().Kind() result := []Tuple{} for _, kind := range []reflect.Kind{kind1, kind2} { if kind != reflect.Slice && kind != reflect.Array { return result } } var minLength int length1 := inValue1.Len() length2 := inValue2.Len() if length1 <= length2 { minLength = length1 } else { minLength = length2 } for i := 0; i < minLength; i++ { newTuple := Tuple{ Element1: inValue1.Index(i).Interface(), Element2: inValue2.Index(i).Interface(), } result = append(result, newTuple) } return result }
go
func Zip(slice1 interface{}, slice2 interface{}) []Tuple { inValue1 := reflect.ValueOf(slice1) inValue2 := reflect.ValueOf(slice2) kind1 := inValue1.Type().Kind() kind2 := inValue2.Type().Kind() result := []Tuple{} for _, kind := range []reflect.Kind{kind1, kind2} { if kind != reflect.Slice && kind != reflect.Array { return result } } var minLength int length1 := inValue1.Len() length2 := inValue2.Len() if length1 <= length2 { minLength = length1 } else { minLength = length2 } for i := 0; i < minLength; i++ { newTuple := Tuple{ Element1: inValue1.Index(i).Interface(), Element2: inValue2.Index(i).Interface(), } result = append(result, newTuple) } return result }
[ "func", "Zip", "(", "slice1", "interface", "{", "}", ",", "slice2", "interface", "{", "}", ")", "[", "]", "Tuple", "{", "inValue1", ":=", "reflect", ".", "ValueOf", "(", "slice1", ")", "\n", "inValue2", ":=", "reflect", ".", "ValueOf", "(", "slice2", ...
// Zip returns a list of tuples, where the i-th tuple contains the i-th element // from each of the input iterables. The returned list is truncated in length // to the length of the shortest input iterable.
[ "Zip", "returns", "a", "list", "of", "tuples", "where", "the", "i", "-", "th", "tuple", "contains", "the", "i", "-", "th", "element", "from", "each", "of", "the", "input", "iterables", ".", "The", "returned", "list", "is", "truncated", "in", "length", ...
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/zip.go#L16-L46
train
thoas/go-funk
typesafe.go
FindFloat64
func FindFloat64(s []float64, cb func(s float64) bool) (float64, bool) { for _, i := range s { result := cb(i) if result { return i, true } } return 0.0, false }
go
func FindFloat64(s []float64, cb func(s float64) bool) (float64, bool) { for _, i := range s { result := cb(i) if result { return i, true } } return 0.0, false }
[ "func", "FindFloat64", "(", "s", "[", "]", "float64", ",", "cb", "func", "(", "s", "float64", ")", "bool", ")", "(", "float64", ",", "bool", ")", "{", "for", "_", ",", "i", ":=", "range", "s", "{", "result", ":=", "cb", "(", "i", ")", "\n", "...
// FindFloat64 iterates over a collection of float64, returning an array of // all float64 elements predicate returns truthy for.
[ "FindFloat64", "iterates", "over", "a", "collection", "of", "float64", "returning", "an", "array", "of", "all", "float64", "elements", "predicate", "returns", "truthy", "for", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L39-L49
train
thoas/go-funk
typesafe.go
FindFloat32
func FindFloat32(s []float32, cb func(s float32) bool) (float32, bool) { for _, i := range s { result := cb(i) if result { return i, true } } return 0.0, false }
go
func FindFloat32(s []float32, cb func(s float32) bool) (float32, bool) { for _, i := range s { result := cb(i) if result { return i, true } } return 0.0, false }
[ "func", "FindFloat32", "(", "s", "[", "]", "float32", ",", "cb", "func", "(", "s", "float32", ")", "bool", ")", "(", "float32", ",", "bool", ")", "{", "for", "_", ",", "i", ":=", "range", "s", "{", "result", ":=", "cb", "(", "i", ")", "\n", "...
// FindFloat32 iterates over a collection of float32, returning the first // float32 element predicate returns truthy for.
[ "FindFloat32", "iterates", "over", "a", "collection", "of", "float32", "returning", "the", "first", "float32", "element", "predicate", "returns", "truthy", "for", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L53-L63
train
thoas/go-funk
typesafe.go
FindInt
func FindInt(s []int, cb func(s int) bool) (int, bool) { for _, i := range s { result := cb(i) if result { return i, true } } return 0, false }
go
func FindInt(s []int, cb func(s int) bool) (int, bool) { for _, i := range s { result := cb(i) if result { return i, true } } return 0, false }
[ "func", "FindInt", "(", "s", "[", "]", "int", ",", "cb", "func", "(", "s", "int", ")", "bool", ")", "(", "int", ",", "bool", ")", "{", "for", "_", ",", "i", ":=", "range", "s", "{", "result", ":=", "cb", "(", "i", ")", "\n", "if", "result",...
// FindInt iterates over a collection of int, returning the first // int element predicate returns truthy for.
[ "FindInt", "iterates", "over", "a", "collection", "of", "int", "returning", "the", "first", "int", "element", "predicate", "returns", "truthy", "for", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L67-L77
train
thoas/go-funk
typesafe.go
FindInt32
func FindInt32(s []int32, cb func(s int32) bool) (int32, bool) { for _, i := range s { result := cb(i) if result { return i, true } } return 0, false }
go
func FindInt32(s []int32, cb func(s int32) bool) (int32, bool) { for _, i := range s { result := cb(i) if result { return i, true } } return 0, false }
[ "func", "FindInt32", "(", "s", "[", "]", "int32", ",", "cb", "func", "(", "s", "int32", ")", "bool", ")", "(", "int32", ",", "bool", ")", "{", "for", "_", ",", "i", ":=", "range", "s", "{", "result", ":=", "cb", "(", "i", ")", "\n", "if", "...
// FindInt32 iterates over a collection of int32, returning the first // int32 element predicate returns truthy for.
[ "FindInt32", "iterates", "over", "a", "collection", "of", "int32", "returning", "the", "first", "int32", "element", "predicate", "returns", "truthy", "for", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L81-L91
train
thoas/go-funk
typesafe.go
FindInt64
func FindInt64(s []int64, cb func(s int64) bool) (int64, bool) { for _, i := range s { result := cb(i) if result { return i, true } } return 0, false }
go
func FindInt64(s []int64, cb func(s int64) bool) (int64, bool) { for _, i := range s { result := cb(i) if result { return i, true } } return 0, false }
[ "func", "FindInt64", "(", "s", "[", "]", "int64", ",", "cb", "func", "(", "s", "int64", ")", "bool", ")", "(", "int64", ",", "bool", ")", "{", "for", "_", ",", "i", ":=", "range", "s", "{", "result", ":=", "cb", "(", "i", ")", "\n", "if", "...
// FindInt64 iterates over a collection of int64, returning the first // int64 element predicate returns truthy for.
[ "FindInt64", "iterates", "over", "a", "collection", "of", "int64", "returning", "the", "first", "int64", "element", "predicate", "returns", "truthy", "for", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L95-L105
train
thoas/go-funk
typesafe.go
FindString
func FindString(s []string, cb func(s string) bool) (string, bool) { for _, i := range s { result := cb(i) if result { return i, true } } return "", false }
go
func FindString(s []string, cb func(s string) bool) (string, bool) { for _, i := range s { result := cb(i) if result { return i, true } } return "", false }
[ "func", "FindString", "(", "s", "[", "]", "string", ",", "cb", "func", "(", "s", "string", ")", "bool", ")", "(", "string", ",", "bool", ")", "{", "for", "_", ",", "i", ":=", "range", "s", "{", "result", ":=", "cb", "(", "i", ")", "\n", "if",...
// FindString iterates over a collection of string, returning the first // string element predicate returns truthy for.
[ "FindString", "iterates", "over", "a", "collection", "of", "string", "returning", "the", "first", "string", "element", "predicate", "returns", "truthy", "for", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L109-L119
train
thoas/go-funk
typesafe.go
FilterFloat64
func FilterFloat64(s []float64, cb func(s float64) bool) []float64 { results := []float64{} for _, i := range s { result := cb(i) if result { results = append(results, i) } } return results }
go
func FilterFloat64(s []float64, cb func(s float64) bool) []float64 { results := []float64{} for _, i := range s { result := cb(i) if result { results = append(results, i) } } return results }
[ "func", "FilterFloat64", "(", "s", "[", "]", "float64", ",", "cb", "func", "(", "s", "float64", ")", "bool", ")", "[", "]", "float64", "{", "results", ":=", "[", "]", "float64", "{", "}", "\n", "for", "_", ",", "i", ":=", "range", "s", "{", "re...
// FilterFloat64 iterates over a collection of float64, returning an array of // all float64 elements predicate returns truthy for.
[ "FilterFloat64", "iterates", "over", "a", "collection", "of", "float64", "returning", "an", "array", "of", "all", "float64", "elements", "predicate", "returns", "truthy", "for", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L123-L135
train
thoas/go-funk
typesafe.go
FilterFloat32
func FilterFloat32(s []float32, cb func(s float32) bool) []float32 { results := []float32{} for _, i := range s { result := cb(i) if result { results = append(results, i) } } return results }
go
func FilterFloat32(s []float32, cb func(s float32) bool) []float32 { results := []float32{} for _, i := range s { result := cb(i) if result { results = append(results, i) } } return results }
[ "func", "FilterFloat32", "(", "s", "[", "]", "float32", ",", "cb", "func", "(", "s", "float32", ")", "bool", ")", "[", "]", "float32", "{", "results", ":=", "[", "]", "float32", "{", "}", "\n", "for", "_", ",", "i", ":=", "range", "s", "{", "re...
// FilterFloat32 iterates over a collection of float32, returning an array of // all float32 elements predicate returns truthy for.
[ "FilterFloat32", "iterates", "over", "a", "collection", "of", "float32", "returning", "an", "array", "of", "all", "float32", "elements", "predicate", "returns", "truthy", "for", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L139-L151
train
thoas/go-funk
typesafe.go
FilterInt
func FilterInt(s []int, cb func(s int) bool) []int { results := []int{} for _, i := range s { result := cb(i) if result { results = append(results, i) } } return results }
go
func FilterInt(s []int, cb func(s int) bool) []int { results := []int{} for _, i := range s { result := cb(i) if result { results = append(results, i) } } return results }
[ "func", "FilterInt", "(", "s", "[", "]", "int", ",", "cb", "func", "(", "s", "int", ")", "bool", ")", "[", "]", "int", "{", "results", ":=", "[", "]", "int", "{", "}", "\n", "for", "_", ",", "i", ":=", "range", "s", "{", "result", ":=", "cb...
// FilterInt iterates over a collection of int, returning an array of // all int elements predicate returns truthy for.
[ "FilterInt", "iterates", "over", "a", "collection", "of", "int", "returning", "an", "array", "of", "all", "int", "elements", "predicate", "returns", "truthy", "for", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L155-L167
train
thoas/go-funk
typesafe.go
FilterInt32
func FilterInt32(s []int32, cb func(s int32) bool) []int32 { results := []int32{} for _, i := range s { result := cb(i) if result { results = append(results, i) } } return results }
go
func FilterInt32(s []int32, cb func(s int32) bool) []int32 { results := []int32{} for _, i := range s { result := cb(i) if result { results = append(results, i) } } return results }
[ "func", "FilterInt32", "(", "s", "[", "]", "int32", ",", "cb", "func", "(", "s", "int32", ")", "bool", ")", "[", "]", "int32", "{", "results", ":=", "[", "]", "int32", "{", "}", "\n", "for", "_", ",", "i", ":=", "range", "s", "{", "result", "...
// FilterInt32 iterates over a collection of int32, returning an array of // all int32 elements predicate returns truthy for.
[ "FilterInt32", "iterates", "over", "a", "collection", "of", "int32", "returning", "an", "array", "of", "all", "int32", "elements", "predicate", "returns", "truthy", "for", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L171-L183
train
thoas/go-funk
typesafe.go
FilterInt64
func FilterInt64(s []int64, cb func(s int64) bool) []int64 { results := []int64{} for _, i := range s { result := cb(i) if result { results = append(results, i) } } return results }
go
func FilterInt64(s []int64, cb func(s int64) bool) []int64 { results := []int64{} for _, i := range s { result := cb(i) if result { results = append(results, i) } } return results }
[ "func", "FilterInt64", "(", "s", "[", "]", "int64", ",", "cb", "func", "(", "s", "int64", ")", "bool", ")", "[", "]", "int64", "{", "results", ":=", "[", "]", "int64", "{", "}", "\n", "for", "_", ",", "i", ":=", "range", "s", "{", "result", "...
// FilterInt64 iterates over a collection of int64, returning an array of // all int64 elements predicate returns truthy for.
[ "FilterInt64", "iterates", "over", "a", "collection", "of", "int64", "returning", "an", "array", "of", "all", "int64", "elements", "predicate", "returns", "truthy", "for", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L187-L199
train
thoas/go-funk
typesafe.go
FilterString
func FilterString(s []string, cb func(s string) bool) []string { results := []string{} for _, i := range s { result := cb(i) if result { results = append(results, i) } } return results }
go
func FilterString(s []string, cb func(s string) bool) []string { results := []string{} for _, i := range s { result := cb(i) if result { results = append(results, i) } } return results }
[ "func", "FilterString", "(", "s", "[", "]", "string", ",", "cb", "func", "(", "s", "string", ")", "bool", ")", "[", "]", "string", "{", "results", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "i", ":=", "range", "s", "{", "result"...
// FilterString iterates over a collection of string, returning an array of // all string elements predicate returns truthy for.
[ "FilterString", "iterates", "over", "a", "collection", "of", "string", "returning", "an", "array", "of", "all", "string", "elements", "predicate", "returns", "truthy", "for", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L203-L215
train
thoas/go-funk
typesafe.go
ContainsInt
func ContainsInt(s []int, v int) bool { for _, vv := range s { if vv == v { return true } } return false }
go
func ContainsInt(s []int, v int) bool { for _, vv := range s { if vv == v { return true } } return false }
[ "func", "ContainsInt", "(", "s", "[", "]", "int", ",", "v", "int", ")", "bool", "{", "for", "_", ",", "vv", ":=", "range", "s", "{", "if", "vv", "==", "v", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// ContainsInt returns true if an int is present in a iteratee.
[ "ContainsInt", "returns", "true", "if", "an", "int", "is", "present", "in", "a", "iteratee", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L218-L225
train
thoas/go-funk
typesafe.go
ContainsInt32
func ContainsInt32(s []int32, v int32) bool { for _, vv := range s { if vv == v { return true } } return false }
go
func ContainsInt32(s []int32, v int32) bool { for _, vv := range s { if vv == v { return true } } return false }
[ "func", "ContainsInt32", "(", "s", "[", "]", "int32", ",", "v", "int32", ")", "bool", "{", "for", "_", ",", "vv", ":=", "range", "s", "{", "if", "vv", "==", "v", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// ContainsInt32 returns true if an int32 is present in a iteratee.
[ "ContainsInt32", "returns", "true", "if", "an", "int32", "is", "present", "in", "a", "iteratee", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L228-L235
train
thoas/go-funk
typesafe.go
ContainsInt64
func ContainsInt64(s []int64, v int64) bool { for _, vv := range s { if vv == v { return true } } return false }
go
func ContainsInt64(s []int64, v int64) bool { for _, vv := range s { if vv == v { return true } } return false }
[ "func", "ContainsInt64", "(", "s", "[", "]", "int64", ",", "v", "int64", ")", "bool", "{", "for", "_", ",", "vv", ":=", "range", "s", "{", "if", "vv", "==", "v", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// ContainsInt64 returns true if an int64 is present in a iteratee.
[ "ContainsInt64", "returns", "true", "if", "an", "int64", "is", "present", "in", "a", "iteratee", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L238-L245
train
thoas/go-funk
typesafe.go
ContainsFloat32
func ContainsFloat32(s []float32, v float32) bool { for _, vv := range s { if vv == v { return true } } return false }
go
func ContainsFloat32(s []float32, v float32) bool { for _, vv := range s { if vv == v { return true } } return false }
[ "func", "ContainsFloat32", "(", "s", "[", "]", "float32", ",", "v", "float32", ")", "bool", "{", "for", "_", ",", "vv", ":=", "range", "s", "{", "if", "vv", "==", "v", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", ...
// ContainsFloat32 returns true if a float32 is present in a iteratee.
[ "ContainsFloat32", "returns", "true", "if", "a", "float32", "is", "present", "in", "a", "iteratee", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L258-L265
train
thoas/go-funk
typesafe.go
ContainsFloat64
func ContainsFloat64(s []float64, v float64) bool { for _, vv := range s { if vv == v { return true } } return false }
go
func ContainsFloat64(s []float64, v float64) bool { for _, vv := range s { if vv == v { return true } } return false }
[ "func", "ContainsFloat64", "(", "s", "[", "]", "float64", ",", "v", "float64", ")", "bool", "{", "for", "_", ",", "vv", ":=", "range", "s", "{", "if", "vv", "==", "v", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", ...
// ContainsFloat64 returns true if a float64 is present in a iteratee.
[ "ContainsFloat64", "returns", "true", "if", "a", "float64", "is", "present", "in", "a", "iteratee", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L268-L275
train
thoas/go-funk
typesafe.go
SumInt32
func SumInt32(s []int32) (sum int32) { for _, v := range s { sum += v } return }
go
func SumInt32(s []int32) (sum int32) { for _, v := range s { sum += v } return }
[ "func", "SumInt32", "(", "s", "[", "]", "int32", ")", "(", "sum", "int32", ")", "{", "for", "_", ",", "v", ":=", "range", "s", "{", "sum", "+=", "v", "\n", "}", "\n", "return", "\n", "}" ]
// SumInt32 sums a int32 iteratee and returns the sum of all elements
[ "SumInt32", "sums", "a", "int32", "iteratee", "and", "returns", "the", "sum", "of", "all", "elements" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L278-L283
train
thoas/go-funk
typesafe.go
SumInt64
func SumInt64(s []int64) (sum int64) { for _, v := range s { sum += v } return }
go
func SumInt64(s []int64) (sum int64) { for _, v := range s { sum += v } return }
[ "func", "SumInt64", "(", "s", "[", "]", "int64", ")", "(", "sum", "int64", ")", "{", "for", "_", ",", "v", ":=", "range", "s", "{", "sum", "+=", "v", "\n", "}", "\n", "return", "\n", "}" ]
// SumInt64 sums a int64 iteratee and returns the sum of all elements
[ "SumInt64", "sums", "a", "int64", "iteratee", "and", "returns", "the", "sum", "of", "all", "elements" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L286-L291
train
thoas/go-funk
typesafe.go
SumInt
func SumInt(s []int) (sum int) { for _, v := range s { sum += v } return }
go
func SumInt(s []int) (sum int) { for _, v := range s { sum += v } return }
[ "func", "SumInt", "(", "s", "[", "]", "int", ")", "(", "sum", "int", ")", "{", "for", "_", ",", "v", ":=", "range", "s", "{", "sum", "+=", "v", "\n", "}", "\n", "return", "\n", "}" ]
// SumInt sums a int iteratee and returns the sum of all elements
[ "SumInt", "sums", "a", "int", "iteratee", "and", "returns", "the", "sum", "of", "all", "elements" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L294-L299
train
thoas/go-funk
typesafe.go
SumFloat64
func SumFloat64(s []float64) (sum float64) { for _, v := range s { sum += v } return }
go
func SumFloat64(s []float64) (sum float64) { for _, v := range s { sum += v } return }
[ "func", "SumFloat64", "(", "s", "[", "]", "float64", ")", "(", "sum", "float64", ")", "{", "for", "_", ",", "v", ":=", "range", "s", "{", "sum", "+=", "v", "\n", "}", "\n", "return", "\n", "}" ]
// SumFloat64 sums a float64 iteratee and returns the sum of all elements
[ "SumFloat64", "sums", "a", "float64", "iteratee", "and", "returns", "the", "sum", "of", "all", "elements" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L302-L307
train
thoas/go-funk
typesafe.go
SumFloat32
func SumFloat32(s []float32) (sum float32) { for _, v := range s { sum += v } return }
go
func SumFloat32(s []float32) (sum float32) { for _, v := range s { sum += v } return }
[ "func", "SumFloat32", "(", "s", "[", "]", "float32", ")", "(", "sum", "float32", ")", "{", "for", "_", ",", "v", ":=", "range", "s", "{", "sum", "+=", "v", "\n", "}", "\n", "return", "\n", "}" ]
// SumFloat32 sums a float32 iteratee and returns the sum of all elements
[ "SumFloat32", "sums", "a", "float32", "iteratee", "and", "returns", "the", "sum", "of", "all", "elements" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L310-L315
train
thoas/go-funk
typesafe.go
ReverseStrings
func ReverseStrings(s []string) []string { for i, j := 0, len(s)-1; i < len(s)/2; i, j = i+1, j-1 { s[i], s[j] = s[j], s[i] } return s }
go
func ReverseStrings(s []string) []string { for i, j := 0, len(s)-1; i < len(s)/2; i, j = i+1, j-1 { s[i], s[j] = s[j], s[i] } return s }
[ "func", "ReverseStrings", "(", "s", "[", "]", "string", ")", "[", "]", "string", "{", "for", "i", ",", "j", ":=", "0", ",", "len", "(", "s", ")", "-", "1", ";", "i", "<", "len", "(", "s", ")", "/", "2", ";", "i", ",", "j", "=", "i", "+"...
// ReverseStrings reverses an array of string
[ "ReverseStrings", "reverses", "an", "array", "of", "string" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L318-L323
train
thoas/go-funk
typesafe.go
ReverseInt
func ReverseInt(s []int) []int { for i, j := 0, len(s)-1; i < len(s)/2; i, j = i+1, j-1 { s[i], s[j] = s[j], s[i] } return s }
go
func ReverseInt(s []int) []int { for i, j := 0, len(s)-1; i < len(s)/2; i, j = i+1, j-1 { s[i], s[j] = s[j], s[i] } return s }
[ "func", "ReverseInt", "(", "s", "[", "]", "int", ")", "[", "]", "int", "{", "for", "i", ",", "j", ":=", "0", ",", "len", "(", "s", ")", "-", "1", ";", "i", "<", "len", "(", "s", ")", "/", "2", ";", "i", ",", "j", "=", "i", "+", "1", ...
// ReverseInt reverses an array of int
[ "ReverseInt", "reverses", "an", "array", "of", "int" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L326-L331
train
thoas/go-funk
typesafe.go
ReverseInt32
func ReverseInt32(s []int32) []int32 { for i, j := 0, len(s)-1; i < len(s)/2; i, j = i+1, j-1 { s[i], s[j] = s[j], s[i] } return s }
go
func ReverseInt32(s []int32) []int32 { for i, j := 0, len(s)-1; i < len(s)/2; i, j = i+1, j-1 { s[i], s[j] = s[j], s[i] } return s }
[ "func", "ReverseInt32", "(", "s", "[", "]", "int32", ")", "[", "]", "int32", "{", "for", "i", ",", "j", ":=", "0", ",", "len", "(", "s", ")", "-", "1", ";", "i", "<", "len", "(", "s", ")", "/", "2", ";", "i", ",", "j", "=", "i", "+", ...
// ReverseInt32 reverses an array of int32
[ "ReverseInt32", "reverses", "an", "array", "of", "int32" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L334-L339
train
thoas/go-funk
typesafe.go
ReverseInt64
func ReverseInt64(s []int64) []int64 { for i, j := 0, len(s)-1; i < len(s)/2; i, j = i+1, j-1 { s[i], s[j] = s[j], s[i] } return s }
go
func ReverseInt64(s []int64) []int64 { for i, j := 0, len(s)-1; i < len(s)/2; i, j = i+1, j-1 { s[i], s[j] = s[j], s[i] } return s }
[ "func", "ReverseInt64", "(", "s", "[", "]", "int64", ")", "[", "]", "int64", "{", "for", "i", ",", "j", ":=", "0", ",", "len", "(", "s", ")", "-", "1", ";", "i", "<", "len", "(", "s", ")", "/", "2", ";", "i", ",", "j", "=", "i", "+", ...
// ReverseInt64 reverses an array of int64
[ "ReverseInt64", "reverses", "an", "array", "of", "int64" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L342-L347
train
thoas/go-funk
typesafe.go
ReverseFloat64
func ReverseFloat64(s []float64) []float64 { for i, j := 0, len(s)-1; i < len(s)/2; i, j = i+1, j-1 { s[i], s[j] = s[j], s[i] } return s }
go
func ReverseFloat64(s []float64) []float64 { for i, j := 0, len(s)-1; i < len(s)/2; i, j = i+1, j-1 { s[i], s[j] = s[j], s[i] } return s }
[ "func", "ReverseFloat64", "(", "s", "[", "]", "float64", ")", "[", "]", "float64", "{", "for", "i", ",", "j", ":=", "0", ",", "len", "(", "s", ")", "-", "1", ";", "i", "<", "len", "(", "s", ")", "/", "2", ";", "i", ",", "j", "=", "i", "...
// ReverseFloat64 reverses an array of float64
[ "ReverseFloat64", "reverses", "an", "array", "of", "float64" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L350-L355
train
thoas/go-funk
typesafe.go
ReverseFloat32
func ReverseFloat32(s []float32) []float32 { for i, j := 0, len(s)-1; i < len(s)/2; i, j = i+1, j-1 { s[i], s[j] = s[j], s[i] } return s }
go
func ReverseFloat32(s []float32) []float32 { for i, j := 0, len(s)-1; i < len(s)/2; i, j = i+1, j-1 { s[i], s[j] = s[j], s[i] } return s }
[ "func", "ReverseFloat32", "(", "s", "[", "]", "float32", ")", "[", "]", "float32", "{", "for", "i", ",", "j", ":=", "0", ",", "len", "(", "s", ")", "-", "1", ";", "i", "<", "len", "(", "s", ")", "/", "2", ";", "i", ",", "j", "=", "i", "...
// ReverseFloat32 reverses an array of float32
[ "ReverseFloat32", "reverses", "an", "array", "of", "float32" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L358-L363
train
thoas/go-funk
typesafe.go
ReverseString
func ReverseString(s string) string { r := []rune(s) for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 { r[i], r[j] = r[j], r[i] } return string(r) }
go
func ReverseString(s string) string { r := []rune(s) for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 { r[i], r[j] = r[j], r[i] } return string(r) }
[ "func", "ReverseString", "(", "s", "string", ")", "string", "{", "r", ":=", "[", "]", "rune", "(", "s", ")", "\n", "for", "i", ",", "j", ":=", "0", ",", "len", "(", "r", ")", "-", "1", ";", "i", "<", "len", "(", "r", ")", "/", "2", ";", ...
// ReverseString reverses a string
[ "ReverseString", "reverses", "a", "string" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L366-L372
train
thoas/go-funk
typesafe.go
IndexOfInt
func IndexOfInt(a []int, x int) int { return indexOf(len(a), func(i int) bool { return a[i] == x }) }
go
func IndexOfInt(a []int, x int) int { return indexOf(len(a), func(i int) bool { return a[i] == x }) }
[ "func", "IndexOfInt", "(", "a", "[", "]", "int", ",", "x", "int", ")", "int", "{", "return", "indexOf", "(", "len", "(", "a", ")", ",", "func", "(", "i", "int", ")", "bool", "{", "return", "a", "[", "i", "]", "==", "x", "}", ")", "\n", "}" ...
// IndexOfInt gets the index at which the first occurrence of an int value is found in array or return -1 // if the value cannot be found
[ "IndexOfInt", "gets", "the", "index", "at", "which", "the", "first", "occurrence", "of", "an", "int", "value", "is", "found", "in", "array", "or", "return", "-", "1", "if", "the", "value", "cannot", "be", "found" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L385-L387
train
thoas/go-funk
typesafe.go
IndexOfInt32
func IndexOfInt32(a []int32, x int32) int { return indexOf(len(a), func(i int) bool { return a[i] == x }) }
go
func IndexOfInt32(a []int32, x int32) int { return indexOf(len(a), func(i int) bool { return a[i] == x }) }
[ "func", "IndexOfInt32", "(", "a", "[", "]", "int32", ",", "x", "int32", ")", "int", "{", "return", "indexOf", "(", "len", "(", "a", ")", ",", "func", "(", "i", "int", ")", "bool", "{", "return", "a", "[", "i", "]", "==", "x", "}", ")", "\n", ...
// IndexOfInt32 gets the index at which the first occurrence of an int32 value is found in array or return -1 // if the value cannot be found
[ "IndexOfInt32", "gets", "the", "index", "at", "which", "the", "first", "occurrence", "of", "an", "int32", "value", "is", "found", "in", "array", "or", "return", "-", "1", "if", "the", "value", "cannot", "be", "found" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L391-L393
train
thoas/go-funk
typesafe.go
IndexOfInt64
func IndexOfInt64(a []int64, x int64) int { return indexOf(len(a), func(i int) bool { return a[i] == x }) }
go
func IndexOfInt64(a []int64, x int64) int { return indexOf(len(a), func(i int) bool { return a[i] == x }) }
[ "func", "IndexOfInt64", "(", "a", "[", "]", "int64", ",", "x", "int64", ")", "int", "{", "return", "indexOf", "(", "len", "(", "a", ")", ",", "func", "(", "i", "int", ")", "bool", "{", "return", "a", "[", "i", "]", "==", "x", "}", ")", "\n", ...
// IndexOfInt64 gets the index at which the first occurrence of an int64 value is found in array or return -1 // if the value cannot be found
[ "IndexOfInt64", "gets", "the", "index", "at", "which", "the", "first", "occurrence", "of", "an", "int64", "value", "is", "found", "in", "array", "or", "return", "-", "1", "if", "the", "value", "cannot", "be", "found" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L397-L399
train
thoas/go-funk
typesafe.go
IndexOfFloat64
func IndexOfFloat64(a []float64, x float64) int { return indexOf(len(a), func(i int) bool { return a[i] == x }) }
go
func IndexOfFloat64(a []float64, x float64) int { return indexOf(len(a), func(i int) bool { return a[i] == x }) }
[ "func", "IndexOfFloat64", "(", "a", "[", "]", "float64", ",", "x", "float64", ")", "int", "{", "return", "indexOf", "(", "len", "(", "a", ")", ",", "func", "(", "i", "int", ")", "bool", "{", "return", "a", "[", "i", "]", "==", "x", "}", ")", ...
// IndexOfFloat64 gets the index at which the first occurrence of an float64 value is found in array or return -1 // if the value cannot be found
[ "IndexOfFloat64", "gets", "the", "index", "at", "which", "the", "first", "occurrence", "of", "an", "float64", "value", "is", "found", "in", "array", "or", "return", "-", "1", "if", "the", "value", "cannot", "be", "found" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L403-L405
train
thoas/go-funk
typesafe.go
IndexOfString
func IndexOfString(a []string, x string) int { return indexOf(len(a), func(i int) bool { return a[i] == x }) }
go
func IndexOfString(a []string, x string) int { return indexOf(len(a), func(i int) bool { return a[i] == x }) }
[ "func", "IndexOfString", "(", "a", "[", "]", "string", ",", "x", "string", ")", "int", "{", "return", "indexOf", "(", "len", "(", "a", ")", ",", "func", "(", "i", "int", ")", "bool", "{", "return", "a", "[", "i", "]", "==", "x", "}", ")", "\n...
// IndexOfString gets the index at which the first occurrence of a string value is found in array or return -1 // if the value cannot be found
[ "IndexOfString", "gets", "the", "index", "at", "which", "the", "first", "occurrence", "of", "a", "string", "value", "is", "found", "in", "array", "or", "return", "-", "1", "if", "the", "value", "cannot", "be", "found" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L409-L411
train
thoas/go-funk
typesafe.go
LastIndexOfInt
func LastIndexOfInt(a []int, x int) int { return lastIndexOf(len(a), func(i int) bool { return a[i] == x }) }
go
func LastIndexOfInt(a []int, x int) int { return lastIndexOf(len(a), func(i int) bool { return a[i] == x }) }
[ "func", "LastIndexOfInt", "(", "a", "[", "]", "int", ",", "x", "int", ")", "int", "{", "return", "lastIndexOf", "(", "len", "(", "a", ")", ",", "func", "(", "i", "int", ")", "bool", "{", "return", "a", "[", "i", "]", "==", "x", "}", ")", "\n"...
// LastIndexOfInt gets the index at which the first occurrence of an int value is found in array or return -1 // if the value cannot be found
[ "LastIndexOfInt", "gets", "the", "index", "at", "which", "the", "first", "occurrence", "of", "an", "int", "value", "is", "found", "in", "array", "or", "return", "-", "1", "if", "the", "value", "cannot", "be", "found" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L424-L426
train
thoas/go-funk
typesafe.go
LastIndexOfInt32
func LastIndexOfInt32(a []int32, x int32) int { return lastIndexOf(len(a), func(i int) bool { return a[i] == x }) }
go
func LastIndexOfInt32(a []int32, x int32) int { return lastIndexOf(len(a), func(i int) bool { return a[i] == x }) }
[ "func", "LastIndexOfInt32", "(", "a", "[", "]", "int32", ",", "x", "int32", ")", "int", "{", "return", "lastIndexOf", "(", "len", "(", "a", ")", ",", "func", "(", "i", "int", ")", "bool", "{", "return", "a", "[", "i", "]", "==", "x", "}", ")", ...
// LastIndexOfInt32 gets the index at which the first occurrence of an int32 value is found in array or return -1 // if the value cannot be found
[ "LastIndexOfInt32", "gets", "the", "index", "at", "which", "the", "first", "occurrence", "of", "an", "int32", "value", "is", "found", "in", "array", "or", "return", "-", "1", "if", "the", "value", "cannot", "be", "found" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L430-L432
train
thoas/go-funk
typesafe.go
LastIndexOfInt64
func LastIndexOfInt64(a []int64, x int64) int { return lastIndexOf(len(a), func(i int) bool { return a[i] == x }) }
go
func LastIndexOfInt64(a []int64, x int64) int { return lastIndexOf(len(a), func(i int) bool { return a[i] == x }) }
[ "func", "LastIndexOfInt64", "(", "a", "[", "]", "int64", ",", "x", "int64", ")", "int", "{", "return", "lastIndexOf", "(", "len", "(", "a", ")", ",", "func", "(", "i", "int", ")", "bool", "{", "return", "a", "[", "i", "]", "==", "x", "}", ")", ...
// LastIndexOfInt64 gets the index at which the first occurrence of an int64 value is found in array or return -1 // if the value cannot be found
[ "LastIndexOfInt64", "gets", "the", "index", "at", "which", "the", "first", "occurrence", "of", "an", "int64", "value", "is", "found", "in", "array", "or", "return", "-", "1", "if", "the", "value", "cannot", "be", "found" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L436-L438
train
thoas/go-funk
typesafe.go
LastIndexOfFloat64
func LastIndexOfFloat64(a []float64, x float64) int { return lastIndexOf(len(a), func(i int) bool { return a[i] == x }) }
go
func LastIndexOfFloat64(a []float64, x float64) int { return lastIndexOf(len(a), func(i int) bool { return a[i] == x }) }
[ "func", "LastIndexOfFloat64", "(", "a", "[", "]", "float64", ",", "x", "float64", ")", "int", "{", "return", "lastIndexOf", "(", "len", "(", "a", ")", ",", "func", "(", "i", "int", ")", "bool", "{", "return", "a", "[", "i", "]", "==", "x", "}", ...
// LastIndexOfFloat64 gets the index at which the first occurrence of an float64 value is found in array or return -1 // if the value cannot be found
[ "LastIndexOfFloat64", "gets", "the", "index", "at", "which", "the", "first", "occurrence", "of", "an", "float64", "value", "is", "found", "in", "array", "or", "return", "-", "1", "if", "the", "value", "cannot", "be", "found" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L442-L444
train
thoas/go-funk
typesafe.go
LastIndexOfFloat32
func LastIndexOfFloat32(a []float32, x float32) int { return lastIndexOf(len(a), func(i int) bool { return a[i] == x }) }
go
func LastIndexOfFloat32(a []float32, x float32) int { return lastIndexOf(len(a), func(i int) bool { return a[i] == x }) }
[ "func", "LastIndexOfFloat32", "(", "a", "[", "]", "float32", ",", "x", "float32", ")", "int", "{", "return", "lastIndexOf", "(", "len", "(", "a", ")", ",", "func", "(", "i", "int", ")", "bool", "{", "return", "a", "[", "i", "]", "==", "x", "}", ...
// LastIndexOfFloat32 gets the index at which the first occurrence of an float32 value is found in array or return -1 // if the value cannot be found
[ "LastIndexOfFloat32", "gets", "the", "index", "at", "which", "the", "first", "occurrence", "of", "an", "float32", "value", "is", "found", "in", "array", "or", "return", "-", "1", "if", "the", "value", "cannot", "be", "found" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L448-L450
train
thoas/go-funk
typesafe.go
LastIndexOfString
func LastIndexOfString(a []string, x string) int { return lastIndexOf(len(a), func(i int) bool { return a[i] == x }) }
go
func LastIndexOfString(a []string, x string) int { return lastIndexOf(len(a), func(i int) bool { return a[i] == x }) }
[ "func", "LastIndexOfString", "(", "a", "[", "]", "string", ",", "x", "string", ")", "int", "{", "return", "lastIndexOf", "(", "len", "(", "a", ")", ",", "func", "(", "i", "int", ")", "bool", "{", "return", "a", "[", "i", "]", "==", "x", "}", ")...
// LastIndexOfString gets the index at which the first occurrence of a string value is found in array or return -1 // if the value cannot be found
[ "LastIndexOfString", "gets", "the", "index", "at", "which", "the", "first", "occurrence", "of", "a", "string", "value", "is", "found", "in", "array", "or", "return", "-", "1", "if", "the", "value", "cannot", "be", "found" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L454-L456
train
thoas/go-funk
typesafe.go
UniqInt32
func UniqInt32(a []int32) []int32 { length := len(a) seen := make(map[int32]struct{}, length) j := 0 for i := 0; i < length; i++ { v := a[i] if _, ok := seen[v]; ok { continue } seen[v] = struct{}{} a[j] = v j++ } return a[0:j] }
go
func UniqInt32(a []int32) []int32 { length := len(a) seen := make(map[int32]struct{}, length) j := 0 for i := 0; i < length; i++ { v := a[i] if _, ok := seen[v]; ok { continue } seen[v] = struct{}{} a[j] = v j++ } return a[0:j] }
[ "func", "UniqInt32", "(", "a", "[", "]", "int32", ")", "[", "]", "int32", "{", "length", ":=", "len", "(", "a", ")", "\n", "seen", ":=", "make", "(", "map", "[", "int32", "]", "struct", "{", "}", ",", "length", ")", "\n", "j", ":=", "0", "\n"...
// UniqInt32 creates an array of int32 with unique values.
[ "UniqInt32", "creates", "an", "array", "of", "int32", "with", "unique", "values", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L459-L478
train
thoas/go-funk
typesafe.go
UniqInt64
func UniqInt64(a []int64) []int64 { length := len(a) seen := make(map[int64]struct{}, length) j := 0 for i := 0; i < length; i++ { v := a[i] if _, ok := seen[v]; ok { continue } seen[v] = struct{}{} a[j] = v j++ } return a[0:j] }
go
func UniqInt64(a []int64) []int64 { length := len(a) seen := make(map[int64]struct{}, length) j := 0 for i := 0; i < length; i++ { v := a[i] if _, ok := seen[v]; ok { continue } seen[v] = struct{}{} a[j] = v j++ } return a[0:j] }
[ "func", "UniqInt64", "(", "a", "[", "]", "int64", ")", "[", "]", "int64", "{", "length", ":=", "len", "(", "a", ")", "\n", "seen", ":=", "make", "(", "map", "[", "int64", "]", "struct", "{", "}", ",", "length", ")", "\n", "j", ":=", "0", "\n"...
// UniqInt64 creates an array of int64 with unique values.
[ "UniqInt64", "creates", "an", "array", "of", "int64", "with", "unique", "values", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L481-L500
train
thoas/go-funk
typesafe.go
UniqInt
func UniqInt(a []int) []int { length := len(a) seen := make(map[int]struct{}, length) j := 0 for i := 0; i < length; i++ { v := a[i] if _, ok := seen[v]; ok { continue } seen[v] = struct{}{} a[j] = v j++ } return a[0:j] }
go
func UniqInt(a []int) []int { length := len(a) seen := make(map[int]struct{}, length) j := 0 for i := 0; i < length; i++ { v := a[i] if _, ok := seen[v]; ok { continue } seen[v] = struct{}{} a[j] = v j++ } return a[0:j] }
[ "func", "UniqInt", "(", "a", "[", "]", "int", ")", "[", "]", "int", "{", "length", ":=", "len", "(", "a", ")", "\n", "seen", ":=", "make", "(", "map", "[", "int", "]", "struct", "{", "}", ",", "length", ")", "\n", "j", ":=", "0", "\n", "for...
// UniqInt creates an array of int with unique values.
[ "UniqInt", "creates", "an", "array", "of", "int", "with", "unique", "values", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L503-L522
train
thoas/go-funk
typesafe.go
UniqString
func UniqString(a []string) []string { length := len(a) seen := make(map[string]struct{}, length) j := 0 for i := 0; i < length; i++ { v := a[i] if _, ok := seen[v]; ok { continue } seen[v] = struct{}{} a[j] = v j++ } return a[0:j] }
go
func UniqString(a []string) []string { length := len(a) seen := make(map[string]struct{}, length) j := 0 for i := 0; i < length; i++ { v := a[i] if _, ok := seen[v]; ok { continue } seen[v] = struct{}{} a[j] = v j++ } return a[0:j] }
[ "func", "UniqString", "(", "a", "[", "]", "string", ")", "[", "]", "string", "{", "length", ":=", "len", "(", "a", ")", "\n", "seen", ":=", "make", "(", "map", "[", "string", "]", "struct", "{", "}", ",", "length", ")", "\n", "j", ":=", "0", ...
// UniqString creates an array of string with unique values.
[ "UniqString", "creates", "an", "array", "of", "string", "with", "unique", "values", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L525-L544
train
thoas/go-funk
typesafe.go
UniqFloat64
func UniqFloat64(a []float64) []float64 { length := len(a) seen := make(map[float64]struct{}, length) j := 0 for i := 0; i < length; i++ { v := a[i] if _, ok := seen[v]; ok { continue } seen[v] = struct{}{} a[j] = v j++ } return a[0:j] }
go
func UniqFloat64(a []float64) []float64 { length := len(a) seen := make(map[float64]struct{}, length) j := 0 for i := 0; i < length; i++ { v := a[i] if _, ok := seen[v]; ok { continue } seen[v] = struct{}{} a[j] = v j++ } return a[0:j] }
[ "func", "UniqFloat64", "(", "a", "[", "]", "float64", ")", "[", "]", "float64", "{", "length", ":=", "len", "(", "a", ")", "\n", "seen", ":=", "make", "(", "map", "[", "float64", "]", "struct", "{", "}", ",", "length", ")", "\n", "j", ":=", "0"...
// UniqFloat64 creates an array of float64 with unique values.
[ "UniqFloat64", "creates", "an", "array", "of", "float64", "with", "unique", "values", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L547-L566
train
thoas/go-funk
typesafe.go
UniqFloat32
func UniqFloat32(a []float32) []float32 { length := len(a) seen := make(map[float32]struct{}, length) j := 0 for i := 0; i < length; i++ { v := a[i] if _, ok := seen[v]; ok { continue } seen[v] = struct{}{} a[j] = v j++ } return a[0:j] }
go
func UniqFloat32(a []float32) []float32 { length := len(a) seen := make(map[float32]struct{}, length) j := 0 for i := 0; i < length; i++ { v := a[i] if _, ok := seen[v]; ok { continue } seen[v] = struct{}{} a[j] = v j++ } return a[0:j] }
[ "func", "UniqFloat32", "(", "a", "[", "]", "float32", ")", "[", "]", "float32", "{", "length", ":=", "len", "(", "a", ")", "\n", "seen", ":=", "make", "(", "map", "[", "float32", "]", "struct", "{", "}", ",", "length", ")", "\n", "j", ":=", "0"...
// UniqFloat32 creates an array of float32 with unique values.
[ "UniqFloat32", "creates", "an", "array", "of", "float32", "with", "unique", "values", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/typesafe.go#L569-L588
train
thoas/go-funk
map.go
Keys
func Keys(out interface{}) interface{} { value := redirectValue(reflect.ValueOf(out)) valueType := value.Type() if value.Kind() == reflect.Map { keys := value.MapKeys() length := len(keys) resultSlice := reflect.MakeSlice(reflect.SliceOf(valueType.Key()), length, length) for i, key := range keys { resultSlice.Index(i).Set(key) } return resultSlice.Interface() } if value.Kind() == reflect.Struct { length := value.NumField() resultSlice := make([]string, length) for i := 0; i < length; i++ { resultSlice[i] = valueType.Field(i).Name } return resultSlice } panic(fmt.Sprintf("Type %s is not supported by Keys", valueType.String())) }
go
func Keys(out interface{}) interface{} { value := redirectValue(reflect.ValueOf(out)) valueType := value.Type() if value.Kind() == reflect.Map { keys := value.MapKeys() length := len(keys) resultSlice := reflect.MakeSlice(reflect.SliceOf(valueType.Key()), length, length) for i, key := range keys { resultSlice.Index(i).Set(key) } return resultSlice.Interface() } if value.Kind() == reflect.Struct { length := value.NumField() resultSlice := make([]string, length) for i := 0; i < length; i++ { resultSlice[i] = valueType.Field(i).Name } return resultSlice } panic(fmt.Sprintf("Type %s is not supported by Keys", valueType.String())) }
[ "func", "Keys", "(", "out", "interface", "{", "}", ")", "interface", "{", "}", "{", "value", ":=", "redirectValue", "(", "reflect", ".", "ValueOf", "(", "out", ")", ")", "\n", "valueType", ":=", "value", ".", "Type", "(", ")", "\n", "if", "value", ...
// Keys creates an array of the own enumerable map keys or struct field names.
[ "Keys", "creates", "an", "array", "of", "the", "own", "enumerable", "map", "keys", "or", "struct", "field", "names", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/map.go#L9-L40
train
thoas/go-funk
scan.go
ForEach
func ForEach(arr interface{}, predicate interface{}) { if !IsIteratee(arr) { panic("First parameter must be an iteratee") } var ( funcValue = reflect.ValueOf(predicate) arrValue = reflect.ValueOf(arr) arrType = arrValue.Type() funcType = funcValue.Type() ) if arrType.Kind() == reflect.Slice || arrType.Kind() == reflect.Array { if !IsFunction(predicate, 1, 0) { panic("Second argument must be a function with one parameter") } arrElemType := arrValue.Type().Elem() // Checking whether element type is convertible to function's first argument's type. if !arrElemType.ConvertibleTo(funcType.In(0)) { panic("Map function's argument is not compatible with type of array.") } for i := 0; i < arrValue.Len(); i++ { funcValue.Call([]reflect.Value{arrValue.Index(i)}) } } if arrType.Kind() == reflect.Map { if !IsFunction(predicate, 2, 0) { panic("Second argument must be a function with two parameters") } // Type checking for Map<key, value> = (key, value) keyType := arrType.Key() valueType := arrType.Elem() if !keyType.ConvertibleTo(funcType.In(0)) { panic(fmt.Sprintf("function first argument is not compatible with %s", keyType.String())) } if !valueType.ConvertibleTo(funcType.In(1)) { panic(fmt.Sprintf("function second argument is not compatible with %s", valueType.String())) } for _, key := range arrValue.MapKeys() { funcValue.Call([]reflect.Value{key, arrValue.MapIndex(key)}) } } }
go
func ForEach(arr interface{}, predicate interface{}) { if !IsIteratee(arr) { panic("First parameter must be an iteratee") } var ( funcValue = reflect.ValueOf(predicate) arrValue = reflect.ValueOf(arr) arrType = arrValue.Type() funcType = funcValue.Type() ) if arrType.Kind() == reflect.Slice || arrType.Kind() == reflect.Array { if !IsFunction(predicate, 1, 0) { panic("Second argument must be a function with one parameter") } arrElemType := arrValue.Type().Elem() // Checking whether element type is convertible to function's first argument's type. if !arrElemType.ConvertibleTo(funcType.In(0)) { panic("Map function's argument is not compatible with type of array.") } for i := 0; i < arrValue.Len(); i++ { funcValue.Call([]reflect.Value{arrValue.Index(i)}) } } if arrType.Kind() == reflect.Map { if !IsFunction(predicate, 2, 0) { panic("Second argument must be a function with two parameters") } // Type checking for Map<key, value> = (key, value) keyType := arrType.Key() valueType := arrType.Elem() if !keyType.ConvertibleTo(funcType.In(0)) { panic(fmt.Sprintf("function first argument is not compatible with %s", keyType.String())) } if !valueType.ConvertibleTo(funcType.In(1)) { panic(fmt.Sprintf("function second argument is not compatible with %s", valueType.String())) } for _, key := range arrValue.MapKeys() { funcValue.Call([]reflect.Value{key, arrValue.MapIndex(key)}) } } }
[ "func", "ForEach", "(", "arr", "interface", "{", "}", ",", "predicate", "interface", "{", "}", ")", "{", "if", "!", "IsIteratee", "(", "arr", ")", "{", "panic", "(", "\"First parameter must be an iteratee\"", ")", "\n", "}", "\n", "var", "(", "funcValue", ...
// ForEach iterates over elements of collection and invokes iteratee // for each element.
[ "ForEach", "iterates", "over", "elements", "of", "collection", "and", "invokes", "iteratee", "for", "each", "element", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/scan.go#L10-L60
train
thoas/go-funk
scan.go
Head
func Head(arr interface{}) interface{} { value := redirectValue(reflect.ValueOf(arr)) valueType := value.Type() kind := value.Kind() if kind == reflect.Array || kind == reflect.Slice { if value.Len() == 0 { return nil } return value.Index(0).Interface() } panic(fmt.Sprintf("Type %s is not supported by Head", valueType.String())) }
go
func Head(arr interface{}) interface{} { value := redirectValue(reflect.ValueOf(arr)) valueType := value.Type() kind := value.Kind() if kind == reflect.Array || kind == reflect.Slice { if value.Len() == 0 { return nil } return value.Index(0).Interface() } panic(fmt.Sprintf("Type %s is not supported by Head", valueType.String())) }
[ "func", "Head", "(", "arr", "interface", "{", "}", ")", "interface", "{", "}", "{", "value", ":=", "redirectValue", "(", "reflect", ".", "ValueOf", "(", "arr", ")", ")", "\n", "valueType", ":=", "value", ".", "Type", "(", ")", "\n", "kind", ":=", "...
// Head gets the first element of array.
[ "Head", "gets", "the", "first", "element", "of", "array", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/scan.go#L119-L134
train
thoas/go-funk
scan.go
Tail
func Tail(arr interface{}) interface{} { value := redirectValue(reflect.ValueOf(arr)) valueType := value.Type() kind := value.Kind() if kind == reflect.Array || kind == reflect.Slice { length := value.Len() if length <= 1 { return arr } return value.Slice(1, length).Interface() } panic(fmt.Sprintf("Type %s is not supported by Initial", valueType.String())) }
go
func Tail(arr interface{}) interface{} { value := redirectValue(reflect.ValueOf(arr)) valueType := value.Type() kind := value.Kind() if kind == reflect.Array || kind == reflect.Slice { length := value.Len() if length <= 1 { return arr } return value.Slice(1, length).Interface() } panic(fmt.Sprintf("Type %s is not supported by Initial", valueType.String())) }
[ "func", "Tail", "(", "arr", "interface", "{", "}", ")", "interface", "{", "}", "{", "value", ":=", "redirectValue", "(", "reflect", ".", "ValueOf", "(", "arr", ")", ")", "\n", "valueType", ":=", "value", ".", "Type", "(", ")", "\n", "kind", ":=", "...
// Tail gets all but the first element of array.
[ "Tail", "gets", "all", "but", "the", "first", "element", "of", "array", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/scan.go#L175-L192
train
thoas/go-funk
presence.go
Filter
func Filter(arr interface{}, predicate interface{}) interface{} { if !IsIteratee(arr) { panic("First parameter must be an iteratee") } if !IsFunction(predicate, 1, 1) { panic("Second argument must be function") } funcValue := reflect.ValueOf(predicate) funcType := funcValue.Type() if funcType.Out(0).Kind() != reflect.Bool { panic("Return argument should be a boolean") } arrValue := reflect.ValueOf(arr) arrType := arrValue.Type() // Get slice type corresponding to array type resultSliceType := reflect.SliceOf(arrType.Elem()) // MakeSlice takes a slice kind type, and makes a slice. resultSlice := reflect.MakeSlice(resultSliceType, 0, 0) for i := 0; i < arrValue.Len(); i++ { elem := arrValue.Index(i) result := funcValue.Call([]reflect.Value{elem})[0].Interface().(bool) if result { resultSlice = reflect.Append(resultSlice, elem) } } return resultSlice.Interface() }
go
func Filter(arr interface{}, predicate interface{}) interface{} { if !IsIteratee(arr) { panic("First parameter must be an iteratee") } if !IsFunction(predicate, 1, 1) { panic("Second argument must be function") } funcValue := reflect.ValueOf(predicate) funcType := funcValue.Type() if funcType.Out(0).Kind() != reflect.Bool { panic("Return argument should be a boolean") } arrValue := reflect.ValueOf(arr) arrType := arrValue.Type() // Get slice type corresponding to array type resultSliceType := reflect.SliceOf(arrType.Elem()) // MakeSlice takes a slice kind type, and makes a slice. resultSlice := reflect.MakeSlice(resultSliceType, 0, 0) for i := 0; i < arrValue.Len(); i++ { elem := arrValue.Index(i) result := funcValue.Call([]reflect.Value{elem})[0].Interface().(bool) if result { resultSlice = reflect.Append(resultSlice, elem) } } return resultSlice.Interface() }
[ "func", "Filter", "(", "arr", "interface", "{", "}", ",", "predicate", "interface", "{", "}", ")", "interface", "{", "}", "{", "if", "!", "IsIteratee", "(", "arr", ")", "{", "panic", "(", "\"First parameter must be an iteratee\"", ")", "\n", "}", "\n", "...
// Filter iterates over elements of collection, returning an array of // all elements predicate returns truthy for.
[ "Filter", "iterates", "over", "elements", "of", "collection", "returning", "an", "array", "of", "all", "elements", "predicate", "returns", "truthy", "for", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/presence.go#L11-L49
train
thoas/go-funk
presence.go
Find
func Find(arr interface{}, predicate interface{}) interface{} { if !IsIteratee(arr) { panic("First parameter must be an iteratee") } if !IsFunction(predicate, 1, 1) { panic("Second argument must be function") } funcValue := reflect.ValueOf(predicate) funcType := funcValue.Type() if funcType.Out(0).Kind() != reflect.Bool { panic("Return argument should be a boolean") } arrValue := reflect.ValueOf(arr) for i := 0; i < arrValue.Len(); i++ { elem := arrValue.Index(i) result := funcValue.Call([]reflect.Value{elem})[0].Interface().(bool) if result { return elem.Interface() } } return nil }
go
func Find(arr interface{}, predicate interface{}) interface{} { if !IsIteratee(arr) { panic("First parameter must be an iteratee") } if !IsFunction(predicate, 1, 1) { panic("Second argument must be function") } funcValue := reflect.ValueOf(predicate) funcType := funcValue.Type() if funcType.Out(0).Kind() != reflect.Bool { panic("Return argument should be a boolean") } arrValue := reflect.ValueOf(arr) for i := 0; i < arrValue.Len(); i++ { elem := arrValue.Index(i) result := funcValue.Call([]reflect.Value{elem})[0].Interface().(bool) if result { return elem.Interface() } } return nil }
[ "func", "Find", "(", "arr", "interface", "{", "}", ",", "predicate", "interface", "{", "}", ")", "interface", "{", "}", "{", "if", "!", "IsIteratee", "(", "arr", ")", "{", "panic", "(", "\"First parameter must be an iteratee\"", ")", "\n", "}", "\n", "if...
// Find iterates over elements of collection, returning the first // element predicate returns truthy for.
[ "Find", "iterates", "over", "elements", "of", "collection", "returning", "the", "first", "element", "predicate", "returns", "truthy", "for", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/presence.go#L53-L83
train
thoas/go-funk
presence.go
IndexOf
func IndexOf(in interface{}, elem interface{}) int { inValue := reflect.ValueOf(in) elemValue := reflect.ValueOf(elem) inType := inValue.Type() if inType.Kind() == reflect.String { return strings.Index(inValue.String(), elemValue.String()) } if inType.Kind() == reflect.Slice { for i := 0; i < inValue.Len(); i++ { if equal(inValue.Index(i).Interface(), elem) { return i } } } return -1 }
go
func IndexOf(in interface{}, elem interface{}) int { inValue := reflect.ValueOf(in) elemValue := reflect.ValueOf(elem) inType := inValue.Type() if inType.Kind() == reflect.String { return strings.Index(inValue.String(), elemValue.String()) } if inType.Kind() == reflect.Slice { for i := 0; i < inValue.Len(); i++ { if equal(inValue.Index(i).Interface(), elem) { return i } } } return -1 }
[ "func", "IndexOf", "(", "in", "interface", "{", "}", ",", "elem", "interface", "{", "}", ")", "int", "{", "inValue", ":=", "reflect", ".", "ValueOf", "(", "in", ")", "\n", "elemValue", ":=", "reflect", ".", "ValueOf", "(", "elem", ")", "\n", "inType"...
// IndexOf gets the index at which the first occurrence of value is found in array or return -1 // if the value cannot be found
[ "IndexOf", "gets", "the", "index", "at", "which", "the", "first", "occurrence", "of", "value", "is", "found", "in", "array", "or", "return", "-", "1", "if", "the", "value", "cannot", "be", "found" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/presence.go#L87-L107
train
thoas/go-funk
presence.go
Contains
func Contains(in interface{}, elem interface{}) bool { inValue := reflect.ValueOf(in) elemValue := reflect.ValueOf(elem) inType := inValue.Type() switch inType.Kind() { case reflect.String: return strings.Contains(inValue.String(), elemValue.String()) case reflect.Map: for _, key := range inValue.MapKeys() { if equal(key.Interface(), elem) { return true } } case reflect.Slice, reflect.Array: for i := 0; i < inValue.Len(); i++ { if equal(inValue.Index(i).Interface(), elem) { return true } } default: panic(fmt.Sprintf("Type %s is not supported by Contains, supported types are String, Map, Slice, Array", inType.String())) } return false }
go
func Contains(in interface{}, elem interface{}) bool { inValue := reflect.ValueOf(in) elemValue := reflect.ValueOf(elem) inType := inValue.Type() switch inType.Kind() { case reflect.String: return strings.Contains(inValue.String(), elemValue.String()) case reflect.Map: for _, key := range inValue.MapKeys() { if equal(key.Interface(), elem) { return true } } case reflect.Slice, reflect.Array: for i := 0; i < inValue.Len(); i++ { if equal(inValue.Index(i).Interface(), elem) { return true } } default: panic(fmt.Sprintf("Type %s is not supported by Contains, supported types are String, Map, Slice, Array", inType.String())) } return false }
[ "func", "Contains", "(", "in", "interface", "{", "}", ",", "elem", "interface", "{", "}", ")", "bool", "{", "inValue", ":=", "reflect", ".", "ValueOf", "(", "in", ")", "\n", "elemValue", ":=", "reflect", ".", "ValueOf", "(", "elem", ")", "\n", "inTyp...
// Contains returns true if an element is present in a iteratee.
[ "Contains", "returns", "true", "if", "an", "element", "is", "present", "in", "a", "iteratee", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/presence.go#L136-L161
train
thoas/go-funk
presence.go
Every
func Every(in interface{}, elements ...interface{}) bool { for _, elem := range elements { if !Contains(in, elem) { return false } } return true }
go
func Every(in interface{}, elements ...interface{}) bool { for _, elem := range elements { if !Contains(in, elem) { return false } } return true }
[ "func", "Every", "(", "in", "interface", "{", "}", ",", "elements", "...", "interface", "{", "}", ")", "bool", "{", "for", "_", ",", "elem", ":=", "range", "elements", "{", "if", "!", "Contains", "(", "in", ",", "elem", ")", "{", "return", "false",...
// Every returns true if every element is present in a iteratee.
[ "Every", "returns", "true", "if", "every", "element", "is", "present", "in", "a", "iteratee", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/presence.go#L164-L171
train
thoas/go-funk
builder.go
Chain
func Chain(v interface{}) Builder { isNotNil(v, "Chain") valueType := reflect.TypeOf(v) if isValidBuilderEntry(valueType) || (valueType.Kind() == reflect.Ptr && isValidBuilderEntry(valueType.Elem())) { return &chainBuilder{v} } panic(fmt.Sprintf("Type %s is not supported by Chain", valueType.String())) }
go
func Chain(v interface{}) Builder { isNotNil(v, "Chain") valueType := reflect.TypeOf(v) if isValidBuilderEntry(valueType) || (valueType.Kind() == reflect.Ptr && isValidBuilderEntry(valueType.Elem())) { return &chainBuilder{v} } panic(fmt.Sprintf("Type %s is not supported by Chain", valueType.String())) }
[ "func", "Chain", "(", "v", "interface", "{", "}", ")", "Builder", "{", "isNotNil", "(", "v", ",", "\"Chain\"", ")", "\n", "valueType", ":=", "reflect", ".", "TypeOf", "(", "v", ")", "\n", "if", "isValidBuilderEntry", "(", "valueType", ")", "||", "(", ...
// Chain creates a simple new go-funk.Builder from a collection. Each method // call generate a new builder containing the previous result.
[ "Chain", "creates", "a", "simple", "new", "go", "-", "funk", ".", "Builder", "from", "a", "collection", ".", "Each", "method", "call", "generate", "a", "new", "builder", "containing", "the", "previous", "result", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/builder.go#L47-L57
train
thoas/go-funk
builder.go
LazyChain
func LazyChain(v interface{}) Builder { isNotNil(v, "LazyChain") valueType := reflect.TypeOf(v) if isValidBuilderEntry(valueType) || (valueType.Kind() == reflect.Ptr && isValidBuilderEntry(valueType.Elem())) { return &lazyBuilder{func() interface{} { return v }} } panic(fmt.Sprintf("Type %s is not supported by LazyChain", valueType.String())) }
go
func LazyChain(v interface{}) Builder { isNotNil(v, "LazyChain") valueType := reflect.TypeOf(v) if isValidBuilderEntry(valueType) || (valueType.Kind() == reflect.Ptr && isValidBuilderEntry(valueType.Elem())) { return &lazyBuilder{func() interface{} { return v }} } panic(fmt.Sprintf("Type %s is not supported by LazyChain", valueType.String())) }
[ "func", "LazyChain", "(", "v", "interface", "{", "}", ")", "Builder", "{", "isNotNil", "(", "v", ",", "\"LazyChain\"", ")", "\n", "valueType", ":=", "reflect", ".", "TypeOf", "(", "v", ")", "\n", "if", "isValidBuilderEntry", "(", "valueType", ")", "||", ...
// LazyChain creates a lazy go-funk.Builder from a collection. Each method call // generate a new builder containing a method generating the previous value. // With that, all data are only generated when we call a tailling method like All or Find.
[ "LazyChain", "creates", "a", "lazy", "go", "-", "funk", ".", "Builder", "from", "a", "collection", ".", "Each", "method", "call", "generate", "a", "new", "builder", "containing", "a", "method", "generating", "the", "previous", "value", ".", "With", "that", ...
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/builder.go#L62-L73
train
thoas/go-funk
fill.go
Fill
func Fill(in interface{}, fillValue interface{}) (interface{}, error) { inValue := reflect.ValueOf(in) inKind := inValue.Type().Kind() if inKind != reflect.Slice && inKind != reflect.Array { return nil, errors.New("Can only fill slices and arrays") } inType := reflect.TypeOf(in).Elem() value := reflect.ValueOf(fillValue) if inType != value.Type() { return nil, fmt.Errorf( "Cannot fill '%s' with '%s'", reflect.TypeOf(in), value.Type(), ) } length := inValue.Len() newSlice := reflect.SliceOf(reflect.TypeOf(fillValue)) in = reflect.MakeSlice(newSlice, length, length).Interface() inValue = reflect.ValueOf(in) for i := 0; i < length; i++ { inValue.Index(i).Set(value) } return in, nil }
go
func Fill(in interface{}, fillValue interface{}) (interface{}, error) { inValue := reflect.ValueOf(in) inKind := inValue.Type().Kind() if inKind != reflect.Slice && inKind != reflect.Array { return nil, errors.New("Can only fill slices and arrays") } inType := reflect.TypeOf(in).Elem() value := reflect.ValueOf(fillValue) if inType != value.Type() { return nil, fmt.Errorf( "Cannot fill '%s' with '%s'", reflect.TypeOf(in), value.Type(), ) } length := inValue.Len() newSlice := reflect.SliceOf(reflect.TypeOf(fillValue)) in = reflect.MakeSlice(newSlice, length, length).Interface() inValue = reflect.ValueOf(in) for i := 0; i < length; i++ { inValue.Index(i).Set(value) } return in, nil }
[ "func", "Fill", "(", "in", "interface", "{", "}", ",", "fillValue", "interface", "{", "}", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "inValue", ":=", "reflect", ".", "ValueOf", "(", "in", ")", "\n", "inKind", ":=", "inValue", ".", "T...
// Fill fills elements of array with value
[ "Fill", "fills", "elements", "of", "array", "with", "value" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/fill.go#L10-L34
train
thoas/go-funk
intersection.go
Intersect
func Intersect(x interface{}, y interface{}) interface{} { if !IsCollection(x) { panic("First parameter must be a collection") } if !IsCollection(y) { panic("Second parameter must be a collection") } hash := map[interface{}]struct{}{} xValue := reflect.ValueOf(x) xType := xValue.Type() yValue := reflect.ValueOf(y) yType := yValue.Type() if NotEqual(xType, yType) { panic("Parameters must have the same type") } zType := reflect.SliceOf(xType.Elem()) zSlice := reflect.MakeSlice(zType, 0, 0) for i := 0; i < xValue.Len(); i++ { v := xValue.Index(i).Interface() hash[v] = struct{}{} } for i := 0; i < yValue.Len(); i++ { v := yValue.Index(i).Interface() _, ok := hash[v] if ok { zSlice = reflect.Append(zSlice, yValue.Index(i)) } } return zSlice.Interface() }
go
func Intersect(x interface{}, y interface{}) interface{} { if !IsCollection(x) { panic("First parameter must be a collection") } if !IsCollection(y) { panic("Second parameter must be a collection") } hash := map[interface{}]struct{}{} xValue := reflect.ValueOf(x) xType := xValue.Type() yValue := reflect.ValueOf(y) yType := yValue.Type() if NotEqual(xType, yType) { panic("Parameters must have the same type") } zType := reflect.SliceOf(xType.Elem()) zSlice := reflect.MakeSlice(zType, 0, 0) for i := 0; i < xValue.Len(); i++ { v := xValue.Index(i).Interface() hash[v] = struct{}{} } for i := 0; i < yValue.Len(); i++ { v := yValue.Index(i).Interface() _, ok := hash[v] if ok { zSlice = reflect.Append(zSlice, yValue.Index(i)) } } return zSlice.Interface() }
[ "func", "Intersect", "(", "x", "interface", "{", "}", ",", "y", "interface", "{", "}", ")", "interface", "{", "}", "{", "if", "!", "IsCollection", "(", "x", ")", "{", "panic", "(", "\"First parameter must be a collection\"", ")", "\n", "}", "\n", "if", ...
// Intersect returns the intersection between two collections.
[ "Intersect", "returns", "the", "intersection", "between", "two", "collections", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/intersection.go#L8-L45
train
thoas/go-funk
intersection.go
IntersectString
func IntersectString(x []string, y []string) []string { if len(x) == 0 || len(y) == 0 { return []string{} } set := []string{} hash := map[string]struct{}{} for _, v := range x { hash[v] = struct{}{} } for _, v := range y { _, ok := hash[v] if ok { set = append(set, v) } } return set }
go
func IntersectString(x []string, y []string) []string { if len(x) == 0 || len(y) == 0 { return []string{} } set := []string{} hash := map[string]struct{}{} for _, v := range x { hash[v] = struct{}{} } for _, v := range y { _, ok := hash[v] if ok { set = append(set, v) } } return set }
[ "func", "IntersectString", "(", "x", "[", "]", "string", ",", "y", "[", "]", "string", ")", "[", "]", "string", "{", "if", "len", "(", "x", ")", "==", "0", "||", "len", "(", "y", ")", "==", "0", "{", "return", "[", "]", "string", "{", "}", ...
// IntersectString returns the intersection between two collections of string.
[ "IntersectString", "returns", "the", "intersection", "between", "two", "collections", "of", "string", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/intersection.go#L48-L68
train
thoas/go-funk
helpers.go
ToFloat64
func ToFloat64(x interface{}) (float64, bool) { var xf float64 xok := true switch xn := x.(type) { case uint8: xf = float64(xn) case uint16: xf = float64(xn) case uint32: xf = float64(xn) case uint64: xf = float64(xn) case int: xf = float64(xn) case int8: xf = float64(xn) case int16: xf = float64(xn) case int32: xf = float64(xn) case int64: xf = float64(xn) case float32: xf = float64(xn) case float64: xf = float64(xn) default: xok = false } return xf, xok }
go
func ToFloat64(x interface{}) (float64, bool) { var xf float64 xok := true switch xn := x.(type) { case uint8: xf = float64(xn) case uint16: xf = float64(xn) case uint32: xf = float64(xn) case uint64: xf = float64(xn) case int: xf = float64(xn) case int8: xf = float64(xn) case int16: xf = float64(xn) case int32: xf = float64(xn) case int64: xf = float64(xn) case float32: xf = float64(xn) case float64: xf = float64(xn) default: xok = false } return xf, xok }
[ "func", "ToFloat64", "(", "x", "interface", "{", "}", ")", "(", "float64", ",", "bool", ")", "{", "var", "xf", "float64", "\n", "xok", ":=", "true", "\n", "switch", "xn", ":=", "x", ".", "(", "type", ")", "{", "case", "uint8", ":", "xf", "=", "...
// ToFloat64 converts any numeric value to float64.
[ "ToFloat64", "converts", "any", "numeric", "value", "to", "float64", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/helpers.go#L25-L57
train
thoas/go-funk
helpers.go
PtrOf
func PtrOf(itf interface{}) interface{} { t := reflect.TypeOf(itf) cp := reflect.New(t) cp.Elem().Set(reflect.ValueOf(itf)) // Avoid double pointers if itf is a pointer if t.Kind() == reflect.Ptr { return cp.Elem().Interface() } return cp.Interface() }
go
func PtrOf(itf interface{}) interface{} { t := reflect.TypeOf(itf) cp := reflect.New(t) cp.Elem().Set(reflect.ValueOf(itf)) // Avoid double pointers if itf is a pointer if t.Kind() == reflect.Ptr { return cp.Elem().Interface() } return cp.Interface() }
[ "func", "PtrOf", "(", "itf", "interface", "{", "}", ")", "interface", "{", "}", "{", "t", ":=", "reflect", ".", "TypeOf", "(", "itf", ")", "\n", "cp", ":=", "reflect", ".", "New", "(", "t", ")", "\n", "cp", ".", "Elem", "(", ")", ".", "Set", ...
// PtrOf makes a copy of the given interface and returns a pointer.
[ "PtrOf", "makes", "a", "copy", "of", "the", "given", "interface", "and", "returns", "a", "pointer", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/helpers.go#L60-L72
train
thoas/go-funk
helpers.go
IsFunction
func IsFunction(in interface{}, num ...int) bool { funcType := reflect.TypeOf(in) result := funcType.Kind() == reflect.Func if len(num) >= 1 { result = result && funcType.NumIn() == num[0] } if len(num) == 2 { result = result && funcType.NumOut() == num[1] } return result }
go
func IsFunction(in interface{}, num ...int) bool { funcType := reflect.TypeOf(in) result := funcType.Kind() == reflect.Func if len(num) >= 1 { result = result && funcType.NumIn() == num[0] } if len(num) == 2 { result = result && funcType.NumOut() == num[1] } return result }
[ "func", "IsFunction", "(", "in", "interface", "{", "}", ",", "num", "...", "int", ")", "bool", "{", "funcType", ":=", "reflect", ".", "TypeOf", "(", "in", ")", "\n", "result", ":=", "funcType", ".", "Kind", "(", ")", "==", "reflect", ".", "Func", "...
// IsFunction returns if the argument is a function.
[ "IsFunction", "returns", "if", "the", "argument", "is", "a", "function", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/helpers.go#L75-L89
train
thoas/go-funk
helpers.go
IsType
func IsType(expected interface{}, actual interface{}) bool { return IsEqual(reflect.TypeOf(expected), reflect.TypeOf(actual)) }
go
func IsType(expected interface{}, actual interface{}) bool { return IsEqual(reflect.TypeOf(expected), reflect.TypeOf(actual)) }
[ "func", "IsType", "(", "expected", "interface", "{", "}", ",", "actual", "interface", "{", "}", ")", "bool", "{", "return", "IsEqual", "(", "reflect", ".", "TypeOf", "(", "expected", ")", ",", "reflect", ".", "TypeOf", "(", "actual", ")", ")", "\n", ...
// IsType returns if the two objects are in the same type
[ "IsType", "returns", "if", "the", "two", "objects", "are", "in", "the", "same", "type" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/helpers.go#L115-L117
train
thoas/go-funk
helpers.go
IsIteratee
func IsIteratee(in interface{}) bool { if in == nil { return false } arrType := reflect.TypeOf(in) kind := arrType.Kind() return kind == reflect.Array || kind == reflect.Slice || kind == reflect.Map }
go
func IsIteratee(in interface{}) bool { if in == nil { return false } arrType := reflect.TypeOf(in) kind := arrType.Kind() return kind == reflect.Array || kind == reflect.Slice || kind == reflect.Map }
[ "func", "IsIteratee", "(", "in", "interface", "{", "}", ")", "bool", "{", "if", "in", "==", "nil", "{", "return", "false", "\n", "}", "\n", "arrType", ":=", "reflect", ".", "TypeOf", "(", "in", ")", "\n", "kind", ":=", "arrType", ".", "Kind", "(", ...
// IsIteratee returns if the argument is an iteratee.
[ "IsIteratee", "returns", "if", "the", "argument", "is", "an", "iteratee", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/helpers.go#L130-L139
train
thoas/go-funk
helpers.go
IsCollection
func IsCollection(in interface{}) bool { arrType := reflect.TypeOf(in) kind := arrType.Kind() return kind == reflect.Array || kind == reflect.Slice }
go
func IsCollection(in interface{}) bool { arrType := reflect.TypeOf(in) kind := arrType.Kind() return kind == reflect.Array || kind == reflect.Slice }
[ "func", "IsCollection", "(", "in", "interface", "{", "}", ")", "bool", "{", "arrType", ":=", "reflect", ".", "TypeOf", "(", "in", ")", "\n", "kind", ":=", "arrType", ".", "Kind", "(", ")", "\n", "return", "kind", "==", "reflect", ".", "Array", "||", ...
// IsCollection returns if the argument is a collection.
[ "IsCollection", "returns", "if", "the", "argument", "is", "a", "collection", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/helpers.go#L142-L148
train
thoas/go-funk
helpers.go
SliceOf
func SliceOf(in interface{}) interface{} { value := reflect.ValueOf(in) sliceType := reflect.SliceOf(reflect.TypeOf(in)) slice := reflect.New(sliceType) sliceValue := reflect.MakeSlice(sliceType, 0, 0) sliceValue = reflect.Append(sliceValue, value) slice.Elem().Set(sliceValue) return slice.Elem().Interface() }
go
func SliceOf(in interface{}) interface{} { value := reflect.ValueOf(in) sliceType := reflect.SliceOf(reflect.TypeOf(in)) slice := reflect.New(sliceType) sliceValue := reflect.MakeSlice(sliceType, 0, 0) sliceValue = reflect.Append(sliceValue, value) slice.Elem().Set(sliceValue) return slice.Elem().Interface() }
[ "func", "SliceOf", "(", "in", "interface", "{", "}", ")", "interface", "{", "}", "{", "value", ":=", "reflect", ".", "ValueOf", "(", "in", ")", "\n", "sliceType", ":=", "reflect", ".", "SliceOf", "(", "reflect", ".", "TypeOf", "(", "in", ")", ")", ...
// SliceOf returns a slice which contains the element.
[ "SliceOf", "returns", "a", "slice", "which", "contains", "the", "element", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/helpers.go#L151-L161
train
thoas/go-funk
helpers.go
Any
func Any(objs ...interface{}) bool { if len(objs) == 0 { return false } for _, obj := range objs { if !IsEmpty(obj) { return true } } return false }
go
func Any(objs ...interface{}) bool { if len(objs) == 0 { return false } for _, obj := range objs { if !IsEmpty(obj) { return true } } return false }
[ "func", "Any", "(", "objs", "...", "interface", "{", "}", ")", "bool", "{", "if", "len", "(", "objs", ")", "==", "0", "{", "return", "false", "\n", "}", "\n", "for", "_", ",", "obj", ":=", "range", "objs", "{", "if", "!", "IsEmpty", "(", "obj",...
// Any returns true if any element of the iterable is not empty. If the iterable is empty, return False.
[ "Any", "returns", "true", "if", "any", "element", "of", "the", "iterable", "is", "not", "empty", ".", "If", "the", "iterable", "is", "empty", "return", "False", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/helpers.go#L164-L176
train
thoas/go-funk
helpers.go
IsEmpty
func IsEmpty(obj interface{}) bool { if obj == nil || obj == "" || obj == false { return true } for _, v := range numericZeros { if obj == v { return true } } objValue := reflect.ValueOf(obj) switch objValue.Kind() { case reflect.Map: fallthrough case reflect.Slice, reflect.Chan: return objValue.Len() == 0 case reflect.Struct: return reflect.DeepEqual(obj, ZeroOf(obj)) case reflect.Ptr: if objValue.IsNil() { return true } obj = redirectValue(objValue).Interface() return reflect.DeepEqual(obj, ZeroOf(obj)) } return false }
go
func IsEmpty(obj interface{}) bool { if obj == nil || obj == "" || obj == false { return true } for _, v := range numericZeros { if obj == v { return true } } objValue := reflect.ValueOf(obj) switch objValue.Kind() { case reflect.Map: fallthrough case reflect.Slice, reflect.Chan: return objValue.Len() == 0 case reflect.Struct: return reflect.DeepEqual(obj, ZeroOf(obj)) case reflect.Ptr: if objValue.IsNil() { return true } obj = redirectValue(objValue).Interface() return reflect.DeepEqual(obj, ZeroOf(obj)) } return false }
[ "func", "IsEmpty", "(", "obj", "interface", "{", "}", ")", "bool", "{", "if", "obj", "==", "nil", "||", "obj", "==", "\"\"", "||", "obj", "==", "false", "{", "return", "true", "\n", "}", "\n", "for", "_", ",", "v", ":=", "range", "numericZeros", ...
// IsEmpty returns if the object is considered as empty or not.
[ "IsEmpty", "returns", "if", "the", "object", "is", "considered", "as", "empty", "or", "not", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/helpers.go#L194-L225
train
thoas/go-funk
helpers.go
IsZero
func IsZero(obj interface{}) bool { if obj == nil || obj == "" || obj == false { return true } for _, v := range numericZeros { if obj == v { return true } } return reflect.DeepEqual(obj, ZeroOf(obj)) }
go
func IsZero(obj interface{}) bool { if obj == nil || obj == "" || obj == false { return true } for _, v := range numericZeros { if obj == v { return true } } return reflect.DeepEqual(obj, ZeroOf(obj)) }
[ "func", "IsZero", "(", "obj", "interface", "{", "}", ")", "bool", "{", "if", "obj", "==", "nil", "||", "obj", "==", "\"\"", "||", "obj", "==", "false", "{", "return", "true", "\n", "}", "\n", "for", "_", ",", "v", ":=", "range", "numericZeros", "...
// IsZero returns if the object is considered as zero value
[ "IsZero", "returns", "if", "the", "object", "is", "considered", "as", "zero", "value" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/helpers.go#L228-L240
train
thoas/go-funk
helpers.go
ZeroOf
func ZeroOf(in interface{}) interface{} { if in == nil { return nil } return reflect.Zero(reflect.TypeOf(in)).Interface() }
go
func ZeroOf(in interface{}) interface{} { if in == nil { return nil } return reflect.Zero(reflect.TypeOf(in)).Interface() }
[ "func", "ZeroOf", "(", "in", "interface", "{", "}", ")", "interface", "{", "}", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "reflect", ".", "Zero", "(", "reflect", ".", "TypeOf", "(", "in", ")", ")", ".", "Inter...
// ZeroOf returns a zero value of an element.
[ "ZeroOf", "returns", "a", "zero", "value", "of", "an", "element", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/helpers.go#L248-L254
train
thoas/go-funk
helpers.go
RandomInt
func RandomInt(min, max int) int { return min + rand.Intn(max-min) }
go
func RandomInt(min, max int) int { return min + rand.Intn(max-min) }
[ "func", "RandomInt", "(", "min", ",", "max", "int", ")", "int", "{", "return", "min", "+", "rand", ".", "Intn", "(", "max", "-", "min", ")", "\n", "}" ]
// RandomInt generates a random int, based on a min and max values
[ "RandomInt", "generates", "a", "random", "int", "based", "on", "a", "min", "and", "max", "values" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/helpers.go#L257-L259
train
thoas/go-funk
helpers.go
Shard
func Shard(str string, width int, depth int, restOnly bool) []string { var results []string for i := 0; i < depth; i++ { results = append(results, str[(width*i):(width*(i+1))]) } if restOnly { results = append(results, str[(width*depth):]) } else { results = append(results, str) } return results }
go
func Shard(str string, width int, depth int, restOnly bool) []string { var results []string for i := 0; i < depth; i++ { results = append(results, str[(width*i):(width*(i+1))]) } if restOnly { results = append(results, str[(width*depth):]) } else { results = append(results, str) } return results }
[ "func", "Shard", "(", "str", "string", ",", "width", "int", ",", "depth", "int", ",", "restOnly", "bool", ")", "[", "]", "string", "{", "var", "results", "[", "]", "string", "\n", "for", "i", ":=", "0", ";", "i", "<", "depth", ";", "i", "++", "...
// Shard will shard a string name
[ "Shard", "will", "shard", "a", "string", "name" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/helpers.go#L262-L276
train
thoas/go-funk
helpers.go
RandomString
func RandomString(n int, allowedChars ...[]rune) string { var letters []rune if len(allowedChars) == 0 { letters = defaultLetters } else { letters = allowedChars[0] } b := make([]rune, n) for i := range b { b[i] = letters[rand.Intn(len(letters))] } return string(b) }
go
func RandomString(n int, allowedChars ...[]rune) string { var letters []rune if len(allowedChars) == 0 { letters = defaultLetters } else { letters = allowedChars[0] } b := make([]rune, n) for i := range b { b[i] = letters[rand.Intn(len(letters))] } return string(b) }
[ "func", "RandomString", "(", "n", "int", ",", "allowedChars", "...", "[", "]", "rune", ")", "string", "{", "var", "letters", "[", "]", "rune", "\n", "if", "len", "(", "allowedChars", ")", "==", "0", "{", "letters", "=", "defaultLetters", "\n", "}", "...
// RandomString returns a random string with a fixed length
[ "RandomString", "returns", "a", "random", "string", "with", "a", "fixed", "length" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/helpers.go#L281-L296
train
thoas/go-funk
transform.go
Chunk
func Chunk(arr interface{}, size int) interface{} { if !IsIteratee(arr) { panic("First parameter must be neither array nor slice") } arrValue := reflect.ValueOf(arr) arrType := arrValue.Type() resultSliceType := reflect.SliceOf(arrType) // Initialize final result slice which will contains slice resultSlice := reflect.MakeSlice(resultSliceType, 0, 0) itemType := arrType.Elem() var itemSlice reflect.Value itemSliceType := reflect.SliceOf(itemType) length := arrValue.Len() for i := 0; i < length; i++ { if i%size == 0 || i == 0 { if itemSlice.Kind() != reflect.Invalid { resultSlice = reflect.Append(resultSlice, itemSlice) } itemSlice = reflect.MakeSlice(itemSliceType, 0, 0) } itemSlice = reflect.Append(itemSlice, arrValue.Index(i)) if i == length-1 { resultSlice = reflect.Append(resultSlice, itemSlice) } } return resultSlice.Interface() }
go
func Chunk(arr interface{}, size int) interface{} { if !IsIteratee(arr) { panic("First parameter must be neither array nor slice") } arrValue := reflect.ValueOf(arr) arrType := arrValue.Type() resultSliceType := reflect.SliceOf(arrType) // Initialize final result slice which will contains slice resultSlice := reflect.MakeSlice(resultSliceType, 0, 0) itemType := arrType.Elem() var itemSlice reflect.Value itemSliceType := reflect.SliceOf(itemType) length := arrValue.Len() for i := 0; i < length; i++ { if i%size == 0 || i == 0 { if itemSlice.Kind() != reflect.Invalid { resultSlice = reflect.Append(resultSlice, itemSlice) } itemSlice = reflect.MakeSlice(itemSliceType, 0, 0) } itemSlice = reflect.Append(itemSlice, arrValue.Index(i)) if i == length-1 { resultSlice = reflect.Append(resultSlice, itemSlice) } } return resultSlice.Interface() }
[ "func", "Chunk", "(", "arr", "interface", "{", "}", ",", "size", "int", ")", "interface", "{", "}", "{", "if", "!", "IsIteratee", "(", "arr", ")", "{", "panic", "(", "\"First parameter must be neither array nor slice\"", ")", "\n", "}", "\n", "arrValue", "...
// Chunk creates an array of elements split into groups with the length of size. // If array can't be split evenly, the final chunk will be // the remaining element.
[ "Chunk", "creates", "an", "array", "of", "elements", "split", "into", "groups", "with", "the", "length", "of", "size", ".", "If", "array", "can", "t", "be", "split", "evenly", "the", "final", "chunk", "will", "be", "the", "remaining", "element", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/transform.go#L12-L51
train
thoas/go-funk
transform.go
Map
func Map(arr interface{}, mapFunc interface{}) interface{} { if !IsIteratee(arr) { panic("First parameter must be an iteratee") } if !IsFunction(mapFunc) { panic("Second argument must be function") } var ( funcValue = reflect.ValueOf(mapFunc) arrValue = reflect.ValueOf(arr) arrType = arrValue.Type() ) kind := arrType.Kind() if kind == reflect.Slice || kind == reflect.Array { return mapSlice(arrValue, funcValue) } if kind == reflect.Map { return mapMap(arrValue, funcValue) } panic(fmt.Sprintf("Type %s is not supported by Map", arrType.String())) }
go
func Map(arr interface{}, mapFunc interface{}) interface{} { if !IsIteratee(arr) { panic("First parameter must be an iteratee") } if !IsFunction(mapFunc) { panic("Second argument must be function") } var ( funcValue = reflect.ValueOf(mapFunc) arrValue = reflect.ValueOf(arr) arrType = arrValue.Type() ) kind := arrType.Kind() if kind == reflect.Slice || kind == reflect.Array { return mapSlice(arrValue, funcValue) } if kind == reflect.Map { return mapMap(arrValue, funcValue) } panic(fmt.Sprintf("Type %s is not supported by Map", arrType.String())) }
[ "func", "Map", "(", "arr", "interface", "{", "}", ",", "mapFunc", "interface", "{", "}", ")", "interface", "{", "}", "{", "if", "!", "IsIteratee", "(", "arr", ")", "{", "panic", "(", "\"First parameter must be an iteratee\"", ")", "\n", "}", "\n", "if", ...
// Map manipulates an iteratee and transforms it to another type.
[ "Map", "manipulates", "an", "iteratee", "and", "transforms", "it", "to", "another", "type", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/transform.go#L193-L219
train
thoas/go-funk
transform.go
Shuffle
func Shuffle(in interface{}) interface{} { value := reflect.ValueOf(in) valueType := value.Type() kind := value.Kind() if kind == reflect.Array || kind == reflect.Slice { length := value.Len() resultSlice := makeSlice(value, length) for i, v := range rand.Perm(length) { resultSlice.Index(i).Set(value.Index(v)) } return resultSlice.Interface() } panic(fmt.Sprintf("Type %s is not supported by Shuffle", valueType.String())) }
go
func Shuffle(in interface{}) interface{} { value := reflect.ValueOf(in) valueType := value.Type() kind := value.Kind() if kind == reflect.Array || kind == reflect.Slice { length := value.Len() resultSlice := makeSlice(value, length) for i, v := range rand.Perm(length) { resultSlice.Index(i).Set(value.Index(v)) } return resultSlice.Interface() } panic(fmt.Sprintf("Type %s is not supported by Shuffle", valueType.String())) }
[ "func", "Shuffle", "(", "in", "interface", "{", "}", ")", "interface", "{", "}", "{", "value", ":=", "reflect", ".", "ValueOf", "(", "in", ")", "\n", "valueType", ":=", "value", ".", "Type", "(", ")", "\n", "kind", ":=", "value", ".", "Kind", "(", ...
// Shuffle creates an array of shuffled values
[ "Shuffle", "creates", "an", "array", "of", "shuffled", "values" ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/transform.go#L252-L271
train
thoas/go-funk
transform.go
Reverse
func Reverse(in interface{}) interface{} { value := reflect.ValueOf(in) valueType := value.Type() kind := value.Kind() if kind == reflect.String { return ReverseString(in.(string)) } if kind == reflect.Array || kind == reflect.Slice { length := value.Len() resultSlice := makeSlice(value, length) j := 0 for i := length - 1; i >= 0; i-- { resultSlice.Index(j).Set(value.Index(i)) j++ } return resultSlice.Interface() } panic(fmt.Sprintf("Type %s is not supported by Reverse", valueType.String())) }
go
func Reverse(in interface{}) interface{} { value := reflect.ValueOf(in) valueType := value.Type() kind := value.Kind() if kind == reflect.String { return ReverseString(in.(string)) } if kind == reflect.Array || kind == reflect.Slice { length := value.Len() resultSlice := makeSlice(value, length) j := 0 for i := length - 1; i >= 0; i-- { resultSlice.Index(j).Set(value.Index(i)) j++ } return resultSlice.Interface() } panic(fmt.Sprintf("Type %s is not supported by Reverse", valueType.String())) }
[ "func", "Reverse", "(", "in", "interface", "{", "}", ")", "interface", "{", "}", "{", "value", ":=", "reflect", ".", "ValueOf", "(", "in", ")", "\n", "valueType", ":=", "value", ".", "Type", "(", ")", "\n", "kind", ":=", "value", ".", "Kind", "(", ...
// Reverse transforms an array the first element will become the last, // the second element will become the second to last, etc.
[ "Reverse", "transforms", "an", "array", "the", "first", "element", "will", "become", "the", "last", "the", "second", "element", "will", "become", "the", "second", "to", "last", "etc", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/transform.go#L275-L300
train
thoas/go-funk
transform.go
Uniq
func Uniq(in interface{}) interface{} { value := reflect.ValueOf(in) valueType := value.Type() kind := value.Kind() if kind == reflect.Array || kind == reflect.Slice { length := value.Len() seen := make(map[interface{}]bool, length) j := 0 for i := 0; i < length; i++ { val := value.Index(i) v := val.Interface() if _, ok := seen[v]; ok { continue } seen[v] = true value.Index(j).Set(val) j++ } return value.Slice(0, j).Interface() } panic(fmt.Sprintf("Type %s is not supported by Uniq", valueType.String())) }
go
func Uniq(in interface{}) interface{} { value := reflect.ValueOf(in) valueType := value.Type() kind := value.Kind() if kind == reflect.Array || kind == reflect.Slice { length := value.Len() seen := make(map[interface{}]bool, length) j := 0 for i := 0; i < length; i++ { val := value.Index(i) v := val.Interface() if _, ok := seen[v]; ok { continue } seen[v] = true value.Index(j).Set(val) j++ } return value.Slice(0, j).Interface() } panic(fmt.Sprintf("Type %s is not supported by Uniq", valueType.String())) }
[ "func", "Uniq", "(", "in", "interface", "{", "}", ")", "interface", "{", "}", "{", "value", ":=", "reflect", ".", "ValueOf", "(", "in", ")", "\n", "valueType", ":=", "value", ".", "Type", "(", ")", "\n", "kind", ":=", "value", ".", "Kind", "(", "...
// Uniq creates an array with unique values.
[ "Uniq", "creates", "an", "array", "with", "unique", "values", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/transform.go#L303-L332
train
thoas/go-funk
transform.go
ConvertSlice
func ConvertSlice(in interface{}, out interface{}) { srcValue := reflect.ValueOf(in) dstValue := reflect.ValueOf(out) if dstValue.Kind() != reflect.Ptr { panic("Second argument must be a pointer") } dstValue = dstValue.Elem() if srcValue.Kind() != reflect.Slice && srcValue.Kind() != reflect.Array { panic("First argument must be an array or slice") } if dstValue.Kind() != reflect.Slice && dstValue.Kind() != reflect.Array { panic("Second argument must be an array or slice") } // returns value that points to dstValue direct := reflect.Indirect(dstValue) length := srcValue.Len() for i := 0; i < length; i++ { dstValue = reflect.Append(dstValue, srcValue.Index(i)) } direct.Set(dstValue) }
go
func ConvertSlice(in interface{}, out interface{}) { srcValue := reflect.ValueOf(in) dstValue := reflect.ValueOf(out) if dstValue.Kind() != reflect.Ptr { panic("Second argument must be a pointer") } dstValue = dstValue.Elem() if srcValue.Kind() != reflect.Slice && srcValue.Kind() != reflect.Array { panic("First argument must be an array or slice") } if dstValue.Kind() != reflect.Slice && dstValue.Kind() != reflect.Array { panic("Second argument must be an array or slice") } // returns value that points to dstValue direct := reflect.Indirect(dstValue) length := srcValue.Len() for i := 0; i < length; i++ { dstValue = reflect.Append(dstValue, srcValue.Index(i)) } direct.Set(dstValue) }
[ "func", "ConvertSlice", "(", "in", "interface", "{", "}", ",", "out", "interface", "{", "}", ")", "{", "srcValue", ":=", "reflect", ".", "ValueOf", "(", "in", ")", "\n", "dstValue", ":=", "reflect", ".", "ValueOf", "(", "out", ")", "\n", "if", "dstVa...
// ConvertSlice converts a slice type to another, // a perfect example would be to convert a slice of struct to a slice of interface.
[ "ConvertSlice", "converts", "a", "slice", "type", "to", "another", "a", "perfect", "example", "would", "be", "to", "convert", "a", "slice", "of", "struct", "to", "a", "slice", "of", "interface", "." ]
a0a199e85d6d961670e46df4998f8868a3e3309b
https://github.com/thoas/go-funk/blob/a0a199e85d6d961670e46df4998f8868a3e3309b/transform.go#L336-L365
train
genuinetools/reg
registry/customtransport.go
RoundTrip
func (t *CustomTransport) RoundTrip(request *http.Request) (*http.Response, error) { if len(t.Headers) != 0 { for header, value := range t.Headers { request.Header.Add(header, value) } } resp, err := t.Transport.RoundTrip(request) return resp, err }
go
func (t *CustomTransport) RoundTrip(request *http.Request) (*http.Response, error) { if len(t.Headers) != 0 { for header, value := range t.Headers { request.Header.Add(header, value) } } resp, err := t.Transport.RoundTrip(request) return resp, err }
[ "func", "(", "t", "*", "CustomTransport", ")", "RoundTrip", "(", "request", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "if", "len", "(", "t", ".", "Headers", ")", "!=", "0", "{", "for", "header", ...
// RoundTrip defines the round tripper for the error transport.
[ "RoundTrip", "defines", "the", "round", "tripper", "for", "the", "error", "transport", "." ]
d959057b30da67d5f162790f9d5b5160686901fd
https://github.com/genuinetools/reg/blob/d959057b30da67d5f162790f9d5b5160686901fd/registry/customtransport.go#L14-L24
train
genuinetools/reg
registry/image.go
Reference
func (i Image) Reference() string { if len(i.Digest.String()) > 1 { return i.Digest.String() } return i.Tag }
go
func (i Image) Reference() string { if len(i.Digest.String()) > 1 { return i.Digest.String() } return i.Tag }
[ "func", "(", "i", "Image", ")", "Reference", "(", ")", "string", "{", "if", "len", "(", "i", ".", "Digest", ".", "String", "(", ")", ")", ">", "1", "{", "return", "i", ".", "Digest", ".", "String", "(", ")", "\n", "}", "\n", "return", "i", "....
// Reference returns either the digest if it is non-empty or the tag for the image.
[ "Reference", "returns", "either", "the", "digest", "if", "it", "is", "non", "-", "empty", "or", "the", "tag", "for", "the", "image", "." ]
d959057b30da67d5f162790f9d5b5160686901fd
https://github.com/genuinetools/reg/blob/d959057b30da67d5f162790f9d5b5160686901fd/registry/image.go#L25-L31
train
genuinetools/reg
registry/image.go
WithDigest
func (i *Image) WithDigest(digest digest.Digest) (err error) { i.Digest = digest i.named, err = reference.WithDigest(i.named, digest) return err }
go
func (i *Image) WithDigest(digest digest.Digest) (err error) { i.Digest = digest i.named, err = reference.WithDigest(i.named, digest) return err }
[ "func", "(", "i", "*", "Image", ")", "WithDigest", "(", "digest", "digest", ".", "Digest", ")", "(", "err", "error", ")", "{", "i", ".", "Digest", "=", "digest", "\n", "i", ".", "named", ",", "err", "=", "reference", ".", "WithDigest", "(", "i", ...
// WithDigest sets the digest for an image.
[ "WithDigest", "sets", "the", "digest", "for", "an", "image", "." ]
d959057b30da67d5f162790f9d5b5160686901fd
https://github.com/genuinetools/reg/blob/d959057b30da67d5f162790f9d5b5160686901fd/registry/image.go#L34-L38
train
genuinetools/reg
registry/image.go
ParseImage
func ParseImage(image string) (Image, error) { // Parse the image name and tag. named, err := reference.ParseNormalizedNamed(image) if err != nil { return Image{}, fmt.Errorf("parsing image %q failed: %v", image, err) } // Add the latest lag if they did not provide one. named = reference.TagNameOnly(named) i := Image{ named: named, Domain: reference.Domain(named), Path: reference.Path(named), } // Add the tag if there was one. if tagged, ok := named.(reference.Tagged); ok { i.Tag = tagged.Tag() } // Add the digest if there was one. if canonical, ok := named.(reference.Canonical); ok { i.Digest = canonical.Digest() } return i, nil }
go
func ParseImage(image string) (Image, error) { // Parse the image name and tag. named, err := reference.ParseNormalizedNamed(image) if err != nil { return Image{}, fmt.Errorf("parsing image %q failed: %v", image, err) } // Add the latest lag if they did not provide one. named = reference.TagNameOnly(named) i := Image{ named: named, Domain: reference.Domain(named), Path: reference.Path(named), } // Add the tag if there was one. if tagged, ok := named.(reference.Tagged); ok { i.Tag = tagged.Tag() } // Add the digest if there was one. if canonical, ok := named.(reference.Canonical); ok { i.Digest = canonical.Digest() } return i, nil }
[ "func", "ParseImage", "(", "image", "string", ")", "(", "Image", ",", "error", ")", "{", "named", ",", "err", ":=", "reference", ".", "ParseNormalizedNamed", "(", "image", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Image", "{", "}", ",", "f...
// ParseImage returns an Image struct with all the values filled in for a given image.
[ "ParseImage", "returns", "an", "Image", "struct", "with", "all", "the", "values", "filled", "in", "for", "a", "given", "image", "." ]
d959057b30da67d5f162790f9d5b5160686901fd
https://github.com/genuinetools/reg/blob/d959057b30da67d5f162790f9d5b5160686901fd/registry/image.go#L41-L67
train
genuinetools/reg
registry/tags.go
Tags
func (r *Registry) Tags(ctx context.Context, repository string) ([]string, error) { url := r.url("/v2/%s/tags/list", repository) r.Logf("registry.tags url=%s repository=%s", url, repository) var response tagsResponse if _, err := r.getJSON(ctx, url, &response); err != nil { return nil, err } return response.Tags, nil }
go
func (r *Registry) Tags(ctx context.Context, repository string) ([]string, error) { url := r.url("/v2/%s/tags/list", repository) r.Logf("registry.tags url=%s repository=%s", url, repository) var response tagsResponse if _, err := r.getJSON(ctx, url, &response); err != nil { return nil, err } return response.Tags, nil }
[ "func", "(", "r", "*", "Registry", ")", "Tags", "(", "ctx", "context", ".", "Context", ",", "repository", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "url", ":=", "r", ".", "url", "(", "\"/v2/%s/tags/list\"", ",", "repository", ")...
// Tags returns the tags for a specific repository.
[ "Tags", "returns", "the", "tags", "for", "a", "specific", "repository", "." ]
d959057b30da67d5f162790f9d5b5160686901fd
https://github.com/genuinetools/reg/blob/d959057b30da67d5f162790f9d5b5160686901fd/registry/tags.go#L10-L20
train
genuinetools/reg
registry/ping.go
Ping
func (r *Registry) Ping(ctx context.Context) error { url := r.url("/v2/") r.Logf("registry.ping url=%s", url) req, err := http.NewRequest("GET", url, nil) if err != nil { return err } resp, err := r.Client.Do(req.WithContext(ctx)) if resp != nil { defer resp.Body.Close() } return err }
go
func (r *Registry) Ping(ctx context.Context) error { url := r.url("/v2/") r.Logf("registry.ping url=%s", url) req, err := http.NewRequest("GET", url, nil) if err != nil { return err } resp, err := r.Client.Do(req.WithContext(ctx)) if resp != nil { defer resp.Body.Close() } return err }
[ "func", "(", "r", "*", "Registry", ")", "Ping", "(", "ctx", "context", ".", "Context", ")", "error", "{", "url", ":=", "r", ".", "url", "(", "\"/v2/\"", ")", "\n", "r", ".", "Logf", "(", "\"registry.ping url=%s\"", ",", "url", ")", "\n", "req", ","...
// Ping tries to contact a registry URL to make sure it is up and accessible.
[ "Ping", "tries", "to", "contact", "a", "registry", "URL", "to", "make", "sure", "it", "is", "up", "and", "accessible", "." ]
d959057b30da67d5f162790f9d5b5160686901fd
https://github.com/genuinetools/reg/blob/d959057b30da67d5f162790f9d5b5160686901fd/registry/ping.go#L9-L21
train
genuinetools/reg
clair/vulns.go
Vulnerabilities
func (c *Clair) Vulnerabilities(ctx context.Context, r *registry.Registry, repo, tag string) (VulnerabilityReport, error) { report := VulnerabilityReport{ RegistryURL: r.Domain, Repo: repo, Tag: tag, Date: time.Now().Local().Format(time.RFC1123), VulnsBySeverity: make(map[string][]Vulnerability), } filteredLayers, _, err := c.getLayers(ctx, r, repo, tag, true) if err != nil { return report, fmt.Errorf("getting filtered layers failed: %v", err) } if len(filteredLayers) == 0 { fmt.Printf("No need to analyse image %s:%s as there is no non-emtpy layer", repo, tag) return report, nil } for i := len(filteredLayers) - 1; i >= 0; i-- { // Form the clair layer. l, err := c.NewClairLayer(ctx, r, repo, filteredLayers, i) if err != nil { return report, err } // Post the layer. if _, err := c.PostLayer(ctx, l); err != nil { return report, err } } report.Name = filteredLayers[0].Digest.String() vl, err := c.GetLayer(ctx, filteredLayers[0].Digest.String(), true, true) if err != nil { return report, err } // Get the vulns. for _, f := range vl.Features { report.Vulns = append(report.Vulns, f.Vulnerabilities...) } vulnsBy := func(sev string, store map[string][]Vulnerability) []Vulnerability { items, found := store[sev] if !found { items = make([]Vulnerability, 0) store[sev] = items } return items } // group by severity for _, v := range report.Vulns { sevRow := vulnsBy(v.Severity, report.VulnsBySeverity) report.VulnsBySeverity[v.Severity] = append(sevRow, v) } // calculate number of bad vulns report.BadVulns = len(report.VulnsBySeverity["High"]) + len(report.VulnsBySeverity["Critical"]) + len(report.VulnsBySeverity["Defcon1"]) return report, nil }
go
func (c *Clair) Vulnerabilities(ctx context.Context, r *registry.Registry, repo, tag string) (VulnerabilityReport, error) { report := VulnerabilityReport{ RegistryURL: r.Domain, Repo: repo, Tag: tag, Date: time.Now().Local().Format(time.RFC1123), VulnsBySeverity: make(map[string][]Vulnerability), } filteredLayers, _, err := c.getLayers(ctx, r, repo, tag, true) if err != nil { return report, fmt.Errorf("getting filtered layers failed: %v", err) } if len(filteredLayers) == 0 { fmt.Printf("No need to analyse image %s:%s as there is no non-emtpy layer", repo, tag) return report, nil } for i := len(filteredLayers) - 1; i >= 0; i-- { // Form the clair layer. l, err := c.NewClairLayer(ctx, r, repo, filteredLayers, i) if err != nil { return report, err } // Post the layer. if _, err := c.PostLayer(ctx, l); err != nil { return report, err } } report.Name = filteredLayers[0].Digest.String() vl, err := c.GetLayer(ctx, filteredLayers[0].Digest.String(), true, true) if err != nil { return report, err } // Get the vulns. for _, f := range vl.Features { report.Vulns = append(report.Vulns, f.Vulnerabilities...) } vulnsBy := func(sev string, store map[string][]Vulnerability) []Vulnerability { items, found := store[sev] if !found { items = make([]Vulnerability, 0) store[sev] = items } return items } // group by severity for _, v := range report.Vulns { sevRow := vulnsBy(v.Severity, report.VulnsBySeverity) report.VulnsBySeverity[v.Severity] = append(sevRow, v) } // calculate number of bad vulns report.BadVulns = len(report.VulnsBySeverity["High"]) + len(report.VulnsBySeverity["Critical"]) + len(report.VulnsBySeverity["Defcon1"]) return report, nil }
[ "func", "(", "c", "*", "Clair", ")", "Vulnerabilities", "(", "ctx", "context", ".", "Context", ",", "r", "*", "registry", ".", "Registry", ",", "repo", ",", "tag", "string", ")", "(", "VulnerabilityReport", ",", "error", ")", "{", "report", ":=", "Vuln...
// Vulnerabilities scans the given repo and tag.
[ "Vulnerabilities", "scans", "the", "given", "repo", "and", "tag", "." ]
d959057b30da67d5f162790f9d5b5160686901fd
https://github.com/genuinetools/reg/blob/d959057b30da67d5f162790f9d5b5160686901fd/clair/vulns.go#L14-L77
train
genuinetools/reg
clair/layer.go
GetLayer
func (c *Clair) GetLayer(ctx context.Context, name string, features, vulnerabilities bool) (*Layer, error) { url := c.url("/v1/layers/%s?features=%t&vulnerabilities=%t", name, features, vulnerabilities) c.Logf("clair.layers.get url=%s name=%s", url, name) var respLayer layerEnvelope if _, err := c.getJSON(ctx, url, &respLayer); err != nil { return nil, err } if respLayer.Error != nil { return nil, fmt.Errorf("clair error: %s", respLayer.Error.Message) } return respLayer.Layer, nil }
go
func (c *Clair) GetLayer(ctx context.Context, name string, features, vulnerabilities bool) (*Layer, error) { url := c.url("/v1/layers/%s?features=%t&vulnerabilities=%t", name, features, vulnerabilities) c.Logf("clair.layers.get url=%s name=%s", url, name) var respLayer layerEnvelope if _, err := c.getJSON(ctx, url, &respLayer); err != nil { return nil, err } if respLayer.Error != nil { return nil, fmt.Errorf("clair error: %s", respLayer.Error.Message) } return respLayer.Layer, nil }
[ "func", "(", "c", "*", "Clair", ")", "GetLayer", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "features", ",", "vulnerabilities", "bool", ")", "(", "*", "Layer", ",", "error", ")", "{", "url", ":=", "c", ".", "url", "(", "\"/v...
// GetLayer displays a Layer and optionally all of its features and vulnerabilities.
[ "GetLayer", "displays", "a", "Layer", "and", "optionally", "all", "of", "its", "features", "and", "vulnerabilities", "." ]
d959057b30da67d5f162790f9d5b5160686901fd
https://github.com/genuinetools/reg/blob/d959057b30da67d5f162790f9d5b5160686901fd/clair/layer.go#L12-L26
train
genuinetools/reg
clair/layer.go
PostLayer
func (c *Clair) PostLayer(ctx context.Context, layer *Layer) (*Layer, error) { url := c.url("/v1/layers") c.Logf("clair.layers.post url=%s name=%s", url, layer.Name) b, err := json.Marshal(layerEnvelope{Layer: layer}) if err != nil { return nil, err } c.Logf("clair.layers.post req.Body=%s", string(b)) req, err := http.NewRequest("POST", url, bytes.NewReader(b)) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") resp, err := c.Client.Do(req.WithContext(ctx)) if err != nil { return nil, err } defer resp.Body.Close() c.Logf("clair.layers.post resp.Status=%s", resp.Status) var respLayer layerEnvelope if err := json.NewDecoder(resp.Body).Decode(&respLayer); err != nil { return nil, err } if respLayer.Error != nil { return nil, fmt.Errorf("clair error: %s", respLayer.Error.Message) } return respLayer.Layer, err }
go
func (c *Clair) PostLayer(ctx context.Context, layer *Layer) (*Layer, error) { url := c.url("/v1/layers") c.Logf("clair.layers.post url=%s name=%s", url, layer.Name) b, err := json.Marshal(layerEnvelope{Layer: layer}) if err != nil { return nil, err } c.Logf("clair.layers.post req.Body=%s", string(b)) req, err := http.NewRequest("POST", url, bytes.NewReader(b)) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/json") resp, err := c.Client.Do(req.WithContext(ctx)) if err != nil { return nil, err } defer resp.Body.Close() c.Logf("clair.layers.post resp.Status=%s", resp.Status) var respLayer layerEnvelope if err := json.NewDecoder(resp.Body).Decode(&respLayer); err != nil { return nil, err } if respLayer.Error != nil { return nil, fmt.Errorf("clair error: %s", respLayer.Error.Message) } return respLayer.Layer, err }
[ "func", "(", "c", "*", "Clair", ")", "PostLayer", "(", "ctx", "context", ".", "Context", ",", "layer", "*", "Layer", ")", "(", "*", "Layer", ",", "error", ")", "{", "url", ":=", "c", ".", "url", "(", "\"/v1/layers\"", ")", "\n", "c", ".", "Logf",...
// PostLayer performs the analysis of a Layer from the provided path.
[ "PostLayer", "performs", "the", "analysis", "of", "a", "Layer", "from", "the", "provided", "path", "." ]
d959057b30da67d5f162790f9d5b5160686901fd
https://github.com/genuinetools/reg/blob/d959057b30da67d5f162790f9d5b5160686901fd/clair/layer.go#L29-L65
train
genuinetools/reg
clair/layer.go
DeleteLayer
func (c *Clair) DeleteLayer(ctx context.Context, name string) error { url := c.url("/v1/layers/%s", name) c.Logf("clair.layers.delete url=%s name=%s", url, name) req, err := http.NewRequest("DELETE", url, nil) if err != nil { return err } resp, err := c.Client.Do(req.WithContext(ctx)) if err != nil { return err } defer resp.Body.Close() c.Logf("clair.clair resp.Status=%s", resp.Status) if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusAccepted || resp.StatusCode == http.StatusNotFound { return nil } return fmt.Errorf("got status code: %d", resp.StatusCode) }
go
func (c *Clair) DeleteLayer(ctx context.Context, name string) error { url := c.url("/v1/layers/%s", name) c.Logf("clair.layers.delete url=%s name=%s", url, name) req, err := http.NewRequest("DELETE", url, nil) if err != nil { return err } resp, err := c.Client.Do(req.WithContext(ctx)) if err != nil { return err } defer resp.Body.Close() c.Logf("clair.clair resp.Status=%s", resp.Status) if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusAccepted || resp.StatusCode == http.StatusNotFound { return nil } return fmt.Errorf("got status code: %d", resp.StatusCode) }
[ "func", "(", "c", "*", "Clair", ")", "DeleteLayer", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "error", "{", "url", ":=", "c", ".", "url", "(", "\"/v1/layers/%s\"", ",", "name", ")", "\n", "c", ".", "Logf", "(", "\"clair.layer...
// DeleteLayer removes a layer reference from clair.
[ "DeleteLayer", "removes", "a", "layer", "reference", "from", "clair", "." ]
d959057b30da67d5f162790f9d5b5160686901fd
https://github.com/genuinetools/reg/blob/d959057b30da67d5f162790f9d5b5160686901fd/clair/layer.go#L68-L89
train
genuinetools/reg
registry/catalog.go
Catalog
func (r *Registry) Catalog(ctx context.Context, u string) ([]string, error) { if u == "" { u = "/v2/_catalog" } uri := r.url(u) r.Logf("registry.catalog url=%s", uri) var response catalogResponse h, err := r.getJSON(ctx, uri, &response) if err != nil { return nil, err } for _, l := range link.ParseHeader(h) { if l.Rel == "next" { unescaped, _ := url.QueryUnescape(l.URI) repos, err := r.Catalog(ctx, unescaped) if err != nil { return nil, err } response.Repositories = append(response.Repositories, repos...) } } return response.Repositories, nil }
go
func (r *Registry) Catalog(ctx context.Context, u string) ([]string, error) { if u == "" { u = "/v2/_catalog" } uri := r.url(u) r.Logf("registry.catalog url=%s", uri) var response catalogResponse h, err := r.getJSON(ctx, uri, &response) if err != nil { return nil, err } for _, l := range link.ParseHeader(h) { if l.Rel == "next" { unescaped, _ := url.QueryUnescape(l.URI) repos, err := r.Catalog(ctx, unescaped) if err != nil { return nil, err } response.Repositories = append(response.Repositories, repos...) } } return response.Repositories, nil }
[ "func", "(", "r", "*", "Registry", ")", "Catalog", "(", "ctx", "context", ".", "Context", ",", "u", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "u", "==", "\"\"", "{", "u", "=", "\"/v2/_catalog\"", "\n", "}", "\n", "uri"...
// Catalog returns the repositories in a registry.
[ "Catalog", "returns", "the", "repositories", "in", "a", "registry", "." ]
d959057b30da67d5f162790f9d5b5160686901fd
https://github.com/genuinetools/reg/blob/d959057b30da67d5f162790f9d5b5160686901fd/registry/catalog.go#L15-L40
train