Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow var in functions accepting lambdas #4280

Closed
kofifus opened this issue Dec 27, 2020 · 1 comment
Closed

Allow var in functions accepting lambdas #4280

kofifus opened this issue Dec 27, 2020 · 1 comment

Comments

@kofifus
Copy link

kofifus commented Dec 27, 2020

A simplified version of restricted state access with side effects (locking):

public delegate void ActionRef<T>(ref T r1);
public delegate RES FuncRef<T, RES>(ref T r1);

public class LockedState<T>  {
  T Value;
  readonly object theLock = new object();

  public void Ref(ActionRef<T> f) { lock(theLock) f(ref Value);  }
  public TRES Ref<TRES>(FuncRef<T, TRES> f) { lock(theLock) return f(ref Value); }
}

public static void Main() {
  LockedState<SomeComplexType<DateTime, OtherComplexType<List<int>>>> State = new();

  // this is what I have to do ATM:	
  State.Ref((ref SomeComplexType<DateTime, OtherComplexType<List<int>>> v) => {  v = v.next();  }); 

  // but I would like to do this:
  State.Ref((ref var v) => { v = v.next();  }); // The contextual keyword 'var' may only appear within a local variable declaration or in script code	

  // or even better this:
  State.Ref(ref var v => { v = v.next();  });

  // or even better this:
  State.Ref((ref v) => {  v = v.next(); });

  // or best this:
  State.Ref(ref v => {  v = v.next(); });
}

I propose for some of the shorter forms I show above to be allowed Thanks!

@333fred
Copy link
Member

333fred commented Dec 27, 2020

Duplicate of #338.

@333fred 333fred closed this as completed Dec 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants