GithubHelp home page GithubHelp logo

ahlib's Introduction

Introduction

Stars Earned Collaborated Stars Followers Repositories GitHub Page

  • ๐Ÿ‘‹ Hi! Here is AoiHosizora (้’ใ„ใปใ—ใžใ‚‰), majors in Intelligent Software and Robotics, Software Engineering.
  • ๐Ÿ“ Speaking languages: Mandarin Chinese (Native), Teo-Swa-uรช (Native), English (CET-6), Japanese (JLPT-N1).
  • ๐Ÿข Some owned GitHub organizations: ah-shellext & ah-forklib, my public email: [email protected].
  • ๐Ÿš€ Interest areas: distributed backend system development, desktop client and android client development.
  • โšก Favorite programming languages: Go, Dart, C#, Kotlin, Rust, Typescript, etc.

Coding status

ahlib's People

Contributors

aoi-hosizora avatar yoruko-km avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

fossabot

ahlib's Issues

Rename xmodule.LogLeftArrow

// LogLeftArrow is the logger function with <-- (used in LogName, LogType, LogImpl).
// You can overwrite this function.
var LogLeftArrow = func(arg1, arg2, arg3 string) {
fmt.Printf("[XMODULE] %-4s %-30s <-- %s\n", arg1, arg2, arg3)
}
// LogRightArrow is the logger function with --> (used in LogInject, LogInjectField).
// You can overwrite this function.
var LogRightArrow = func(arg1, arg2, arg3 string) {
fmt.Printf("[XMODULE] %-4s %-30s --> %s\n", arg1, arg2, arg3)
}

Should be renamed to

var LogLeftArrowFunc func()

func logLeftArrowFunc() {
	if LogLeftArrowFunc != nil {
		LogLeftArrowFunc()
		return
	}

	// ...
}

xmap package record

// SliceToInterfaceMap returns a map[interface{}]interface{} from an interface slice.
func SliceToInterfaceMap(args []interface{}) map[interface{}]interface{} {
	out := make(map[interface{}]interface{})
	l := len(args)
	for i := 0; i < l; i += 2 {
		keyIdx := i
		valueIdx := i + 1
		if i+1 >= l {
			break
		}
		key := args[keyIdx]
		value := args[valueIdx]
		out[key] = value
	}

	return out
}

// SliceToInterfaceMap returns a map[string]interface{} from an interface slice.
func SliceToStringMap(args []interface{}) map[string]interface{} {
	out := make(map[string]interface{})
	l := len(args)
	for i := 0; i < l; i += 2 {
		keyIdx := i
		valueIdx := i + 1
		if i+1 >= l {
			break
		}

		keyItf := args[keyIdx]
		value := args[valueIdx]
		key := ""
		if keyItf == nil {
			continue
		}
		if k, ok := keyItf.(string); ok {
			key = k
		} else {
			key = fmt.Sprintf("%v", keyItf)
		}
		out[key] = value
	}

	return out
}

Update the whole library

  1. Update panic and error values.
  2. Complete comments for all exported functions and values.
  3. Adjust the functions and methods name.
  4. Unfined the Option method.

Refactor progress:

  • xcolor
  • xcondition
  • xdi -> xmodule
  • xentity
  • xmap
  • xnumber
  • xorderedmap
  • xpointer
  • xproperty
  • xreflect
  • xregexp
  • xruntime
  • xslice
  • xstatus
  • xstring
  • xsystem
  • xtesting
  • xtime
  • xzone

Test progress:

  • xcolor
  • xcondition
  • xmodule
  • xnumber
  • xorderedmap
  • xpointer
  • xreflect
  • xruntime
  • xslice
  • xstatus
  • xstring
  • xtesting
  • xtime

Update xtesting

Add msgAndArgs... argument for functions in xtesting, and use testing.TB and not testing.T.

SortSlice, Sti and Its related

type SortSlice struct {
	s    []interface{}
	less func(i, j int) bool
	swap func(i, j int)
}

func (s SortSlice) Len() int {
	return len(s.s)
}

func (s SortSlice) Less(i, j int) bool {
	return s.less(i, j)
}

func (s SortSlice) Swap(i, j int) {
	s.swap(i, j)
}

func NewSortSlice(s []interface{}, less func(i, j int) bool) SortSlice {
	return SortSlice{
		s:    s,
		less: less,
		swap: func(i, j int) { s[i], s[j] = s[j], s[i] },
	}
}

func ReverseSortSlice(s SortSlice) SortSlice {
	return SortSlice{
		s: s.s,
		less: func(i, j int) bool {
			return !s.less(i, j)
		},
		swap: s.swap,
	}
}

func Sort(s []interface{}, less func(i, j int) bool) {
	interfaceSlice := NewSortSlice(s, less)
	sort.Sort(interfaceSlice)
}

func StableSort(s []interface{}, less func(i, j int) bool) {
	interfaceSlice := NewSortSlice(s, less)
	sort.Stable(interfaceSlice)
}
func Sti(slice interface{}) []interface{} {
	if slice == nil {
		return nil
	}

	v := reflect.ValueOf(slice)
	if v.Type().Kind() != reflect.Slice {
		panic("Sti: parameter must be a slice")
	}

	l := v.Len()
	arr := make([]interface{}, l)
	for idx := 0; idx < l; idx++ {
		arr[idx] = v.Index(idx).Interface()
	}
	return arr
}

func Its(slice []interface{}, model interface{}) interface{} {
	if model == nil {
		panic("Its: model must be non-nil")
	}
	if slice == nil {
		return nil
	}

	t := reflect.TypeOf(model)
	l := len(slice)

	out := reflect.MakeSlice(reflect.SliceOf(t), l, l)
	for idx := range slice {
		v := reflect.ValueOf(slice[idx])
		out.Index(idx).Set(v)
	}
	return out.Interface()
}

Add StiOfXXX in xslice

Add StiOfXXX functions in xslice just like ItsOfXXX.

func ItsOfString(slice []interface{}) []string {
out := make([]string, len(slice))
for idx := range slice {
out[idx] = slice[idx].(string)
}
return out
}

func StiOfString(slice []string) []interface{} { }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.