Lambda property value selector as parameter

private string MyMethod(int testParameter, Func<MyObject, string> selector) { return selector(_myObject); } When using Func delegates, the last parameter is the return type and the first N-1 are the argument types. In this case, there is a single MyObject argument to selector and it returns a string. You can invoke it like: string name = _myClassInstance.MyMethod(1, … Read more

How to apply transform to an STL map in C++

You are missing the const in the first type of the pair. [](std::pair<const std::string, std::string>& p) { However this is not your problem: You cannot use a map as the OutputIterator, as they do not support assignment. You can, however mutate the second argument using std::for_each. Good old map_to_foobar: std::for_each(data.begin(), data.end(), [](std::pair<const std::string, std::string>& p) … Read more

lambda functions in bash

I don’t know of a way to do this, however you may be able to accomplish what you’re trying to do using: somecommand | while read -r; do echo “Something with $REPLY”; done This will also be faster, as you won’t be creating a new process for each line of text. [EDIT 2009-07-09] I’ve made … Read more

Generate a list with lambdas in kotlin

It’s way better to use kotlin.collections function to do this: List(100) { Random.nextInt() } According to Collections.kt inline fun <T> List(size: Int, init: (index: Int) -> T): List<T> = MutableList(size, init) It’s also possible to generate using range like in your case: (1..100).map { Random.nextInt() } The reason you can’t use forEach is that it … Read more

Sort a string in lexicographic order python

Do not use lambda functions when there’s builtin ones for the job. Also never use the cmp argument of sorted because it’s deprecated: sorted(s, key=str.lower) or sorted(s, key=str.upper) But that may not keep ‘A’ and ‘a’ in order, so: sorted(sorted(s), key=str.upper) that will and, by the nature of sorted the operation will be very fast … Read more

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