Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

What does => mean?

Discussion in 'Scripting' started by renman3000, Apr 8, 2014.

  1. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    Hi sorry for psoting here, but a quick google search yielded no results.

    What does this mean...
    Code (csharp):
    1.  
    2. =>
    3.  

    Source:
    Code (csharp):
    1.  
    2. Social.localUser.Authenticate (success => {
    3.         if (success) {
    4.             Debug.Log ("Authentication successful");
    5.             string userInfo = "Username: " + Social.localUser.userName +
    6.                 "\nUser ID: " + Social.localUser.id +
    7.                 "\nIsUnderage: " + Social.localUser.underage;
    8.             Debug.Log (userInfo);
    9.         }
    10.         else
    11.             Debug.Log ("Authentication failed");
    12.     });
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,381
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    I don't recall the technical term for it, but in that context it's essentially an inline function call, usually (including this instance) used for callbacks. In other words, you COULD do this:

    Code (csharp):
    1.  
    2. Social.localUser.Authenticate(SomeCallbackFunction);
    3.  
    4. . . .
    5.  
    6. void SomeCallbackFunction(bool success) {
    7. if (success) {
    8. . . .
    9.  
    However, the person who wrote this decided that that would junk up their class too much, and therefore they preferred to just write the function in-place there.

    I don't like using these myself, so I have only a passing familiarity with them (encountering them in much the same way you have - sample code from other programmers). I think they make the code look disorganized and crappy, while simultaneously making it unintuitive what code is getting executed at what time.
     
  4. Findo

    Findo

    Joined:
    Mar 11, 2014
    Posts:
    368
    I believe it is >=, not =>
     
  5. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    While >= is an operator, it is not what renman3000 did mean => and his question has already been answered.