# Equivalent to arrow functions in Verse?

**URL:** <https://forums.unrealengine.com/t/equivalent-to-arrow-functions-in-verse/828438>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [March 27, 2023, 7:06pm UTC](https://forums.unrealengine.com/t/equivalent-to-arrow-functions-in-verse/828438 "2023-03-27T19:06:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![j\_rapp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@j\_rapp](https://forums.unrealengine.com/u/j_rapp)\
**Post date:** [March 27, 2023, 7:06pm UTC](https://forums.unrealengine.com/t/equivalent-to-arrow-functions-in-verse/828438/1 "2023-03-27T19:06:15Z")

</div>

Im wondering if there is an equivalent to arrow functions in verse. The use case I have is I want to call `SpawnerDevice.SpawnedEvent.Subscribe(OnPlayerSpawned)` but I want to add an additional parameter into the `OnPlayerSpawned` function call. It’d look something like this:

```auto
SpawnerDevice.SpawnedEvent.Subscribe((InAgent: agent) -> OnPlayerSpawned(SpawnerDevice, InAgent));

```

Is this possible? Is there a way to include additional data into these callbacks?

---

<div class="post-metadata">

**Author:** ![DiG3](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dig3/32/1036114_2.png) [@DiG3](https://forums.unrealengine.com/u/DiG3)\
**Post date:** [March 27, 2023, 8:56pm UTC](https://forums.unrealengine.com/t/equivalent-to-arrow-functions-in-verse/828438/2 "2023-03-27T20:56:02Z")

</div>

Hi,  
it seems you’re referring to lambdas, which are currently not available in Verse.

Two common options to solve this are:

# Custom event handler class

- Use a custom event handler class which holds a reference to the sender device and a function with the correct signature for the type of event you’re handling. Then make an instance of that handler class, save the sender and subscribe the event to the custom handler’s function.  
For example, with a `button_device`:

```auto
my_event_handler := class:
    Sender:button_device
    HandleButtonInteractedWith(Agent:agent):void=
        Print("Button Pressed")

# ...inside your creative device...
    OnBegin<override>()<suspends>:void=
        EventHandler:my_event_handler := my_event_handler{Sender := Button}
        Button.InteractedWithEvent.Subscribe(EventHandler.HandleButtonInteractedWith)

```

You can check out an application of this in the [Tagged Lights Puzzle](https://dev.epicgames.com/documentation/en-us/uefn/tagged-lights-4-toggling-lights-with-buttons-in-verse#connectingbuttonpressestotogglinglights) tutorial.

# Await the event

- Create an async function that acts as a handler and uses the `XEvent.Await()` pattern. This is usually better for single-time activations (since you don’t have to unsubscribe the event or maintain state).  
Again, with a `button_device` and support for multiple activations:

```auto
    MyEventHandler(InButton:button_device)<suspends>:void=
        loop:
            Agent := InButton.InteractedWithEvent.Await()
            Print("Button Pressed")
  
    OnBegin<override>()<suspends>:void=
        spawn{MyEventHandler(Button)}

```

---

<div class="post-metadata">

**Author:** ![j\_rapp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@j\_rapp](https://forums.unrealengine.com/u/j_rapp)\
**Post date:** [March 27, 2023, 9:04pm UTC](https://forums.unrealengine.com/t/equivalent-to-arrow-functions-in-verse/828438/3 "2023-03-27T21:04:22Z")

</div>

Oh perfect this works great! Thanks so much for the examples.
