Pass function as a parameter

I’m not sure this is the best, but: function A{ Param([scriptblock]$FunctionToCall) Write-Host “I’m calling $($FunctionToCall.Invoke(4))” } function B($x){ Write-Output “Function B with $x” } Function C{ Param($x) Write-Output “Function C with $x” } PS C:\WINDOWS\system32> A -FunctionToCall $function:B I’m calling Function B with 4 PS C:\WINDOWS\system32> A -FunctionToCall $function:C I’m calling Function C with 4 … Read more

How to pass a type to generic method in Kotlin?

Here’s a complete example: import kotlin.reflect.KClass data class User(val name: String) data class Student(val name: String) fun getUsers(): List<User> = listOf(User(“JB”)) fun getStudents(): List<Student> = listOf(Student(“Claire”)) fun <T: Any> getData(clazz: KClass<T>): List<T>? { return when(clazz) { User::class -> getUsers() as List<T> Student::class -> getStudents() as List<T> else -> null } } fun main(args: Array<String>) { … Read more

Should I add a trailing comma after the last argument in a function call? [closed]

There’s no technical reason to avoid trailing commas in function calls, but some people might find them distracting. Some may wonder: Hmmm, is that comma supposed to be there? One effect of using trailing commas in conjunction with an indented style is to make version control diffs look a little bit cleaner when adding an … Read more

PostgreSQL: ERROR: 42601: a column definition list is required for functions returning “record”

Return selected columns CREATE OR REPLACE FUNCTION get_user_by_username(_username text , _online bool DEFAULT false) RETURNS TABLE ( user_id int , user_name varchar , last_activity timestamptz ) LANGUAGE plpgsql AS $func$ BEGIN IF _online THEN RETURN QUERY UPDATE users u SET last_activity = current_timestamp — ts with time zone WHERE u.user_name = _username RETURNING u.user_id , … Read more

Python, SQLAlchemy pass parameters in connection.execute

The tutorial gives a pretty good example for this: >>> from sqlalchemy.sql import text >>> s = text( … “SELECT users.fullname || ‘, ‘ || addresses.email_address AS title ” … “FROM users, addresses ” … “WHERE users.id = addresses.user_id ” … “AND users.name BETWEEN 😡 AND :y ” … “AND (addresses.email_address LIKE :e1 ” … … Read more

jQuery Passing $(this) to a Function

you can check this link. http://jsfiddle.net/zEXrq/38/ $(“#f”).click(function() { myFunc($(this)); }) function myFunc(thisObj) { thisObj.parent().parent().children().each(function() { alert(“childs”) }); } <div id=”wordlist”> <div id=”a”></div> <div id=”b”> <div id=”e”></div> <div id=”f”>child</div> </div> </div> <script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js”></script>

Passing functions as parameters in Swift

Oneword answer for your question is Closures The Default Syntax for closures is () -> () Instead of Selector you could directly mention the method definition func showConfirmBox(msg:String, title:String, firstBtnStr:String, firstSelector:(sampleParameter: String) -> returntype, secondBtnStr:String, secondSelector:() -> returntype, caller:UIViewController) { //Your Code } But using this will create readability problems so i suggest you to … Read more

Sending data from nested fragments to parent fragment

The best way is use an interface: Declare an interface in the nest fragment // Container Activity or Fragment must implement this interface public interface OnPlayerSelectionSetListener { public void onPlayerSelectionSet(List<Player> players_ist); } Attach the interface to parent fragment // In the child fragment. public void onAttachToParentFragment(Fragment fragment) { try { mOnPlayerSelectionSetListener = (OnPlayerSelectionSetListener)fragment; } catch … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)