Forwarded from Dev
All-2024-03-14-130639.tgz
452.1 MB
I Caesar successfully breached Malaysian Sarawak government systems and gained full access
As a demonstration of our capabilities, we are now publishing a dump of the email box belonging to a senior
"Security Is Just An Illusion, Privacy Is Just Another Illusion"
As a demonstration of our capabilities, we are now publishing a dump of the email box belonging to a senior
"Security Is Just An Illusion, Privacy Is Just Another Illusion"
Forwarded from Pishro App
توی گولنگ هم ما توابع ناشناس یا (Anonymous Functions) رو داریم و میتونیم در جاهای که نیاز داریم ازش استفاده کنیم
به کد زیر دقت کنید
// Long form
func add(x, y int) int {
return x + y
}
// Shorthand
add := func(x, y int) int {
return x + y
}
ما در کد بالا یه تابع ناشناس رو تعریف و به متغیر add اختصاص دادیم.
عملیات کوتاهمدت: برای انجام وظایفی که فقط یک بار استفاده میشن، مثل پردازش دادههای موقت.
بازخوردها (Callbacks): در کدهای غیرهمزمان یا تعاملی، مانند پردازش رویدادها در برنامههای UI یا کار با توابع غیرهمزمان.
ورودی به توابع مرتبه بالا (Higher-order functions): توابعی که دیگر توابع را به عنوان ورودی میگیرند یا خروجی میدهند.
مزیت های توابع ناشناس :
کد مختصرتر: نیاز به تعریف جداگانهی تابع را از بین میبرد.
انعطافپذیری: میتوانید به سرعت توابعی ایجاد کنید که فقط در همان لحظه به آنها نیاز دارید.
کاربرد متمرکز: برای وظایف خاصی که به نامگذاری و استفادهی مجدد نیاز ندارند، ایدهآل است.
یه نمونه دیگه از توابع ناشناس:
numbers := []int{1, 2, 3}
result := make([]int, len(numbers))
for i, num := range numbers {
result[i] = func(x int) int { return x * 2 }(num)
}#golang
Please open Telegram to view this post
VIEW IN TELEGRAM
Forwarded from Dev
This media is not supported in your browser
VIEW IN TELEGRAM
Forwarded from Dev
This media is not supported in your browser
VIEW IN TELEGRAM
Forwarded from Dev
This media is not supported in your browser
VIEW IN TELEGRAM