shomali11 / util Goto Github PK
View Code? Open in Web Editor NEWA collection of useful utility functions
License: MIT License
A collection of useful utility functions
License: MIT License
Hello @shomali11,
It's very useful util that you have written, but in this case how you are handling errors. For example, if func1 breaks I don't wanna execute the other two func.
func1 := func() {
f(0)
}
func2 = func() {
f(1)
}
func3 = func() {
f(2)
}
Parallelize(func1, func2, func3)
Inspired by a comment on this SO about string-reversal in Python:
For example,
"๐ฌ๐ง"[::-1]
yields "๐ง๐ฌ".
I thought I'd try your Reverse() func:
assert.Equal(t, Reverse("๐ฌ๐ง"), "๐ฌ๐ง")
and I got:
Error Trace: xstrings_test.go:86
Error: Not equal:
expected: "๐ง๐ฌ"
actual : "๐ฌ๐ง"
Test: TestReverse
Flags are special in that they are specific ordering of two letters to designate the ISO-3166 country code, which for some systems and fonts is rendered as that country's flag1:
Regional indicator symbols
These characters can be used in pairs to represent regional
codes. In some emoji implementations, certain pairs may be
recognized and displayed by alternate means; for instance,
an implementation might recognizeF + R
and display this
combination with a symbol representing the flag of France
I only see the IfThenElse
, and this only take 3 arguments.
So I made this:
func ifThenElseIfElse(args ...interface{}) interface{} {
if len(args) < 3 || len(args)%2 == 0 {
panic("Need to pass at least 3 arguments, and argument length must be an odd number")
} else {
for i, value := range args {
if i%2 == 0 && len(args) > 3 { //loop even index only
if reflect.ValueOf(args[i]).Kind() != reflect.Bool {
if i != len(args)-1 {
panic(fmt.Sprintf("Value at param %d need to be a boolean!", i+1))
}
} else {
if value.(bool) {
return args[i+1]
}
}
}
}
}
return args[len(args)-1]
}
With that, we can do a complex one like:
if (1 < 2) ? 1 : (2 > 3) ? 2 : (3 > 3) ? 3 : 4
Test case:
https://go.dev/play/p/nK0p-U3An__2
I'm new to Golang, so that function might look like a mess, but you got the idea.
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.