BaşlayınÜcretsiz Başlayın

Anonymous functions

Anonymous functions are those that do not have a name assigned to them. These functions can be useful to quickly evaluate an expression without having to create a standard function, which is significantly more verbose. To define and evaluate an anonymous function in one line, we use parenthesis, as shown below.

(x -> x^2 + 5)(5)  # 30

Another use for anonymous functions is passing them to functions that take other functions as arguments. This is useful with functions such as map and filter, where an anonymous function can be passed as an argument.

map(x -> x^2 + 5, [5, 10])  # 30, 105

Bu egzersiz

Intermediate Julia

kursunun bir parçasıdır
Kursu Görüntüle

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Create an anonymous function and evaluate it at x=6
____
Kodu Düzenle ve Çalıştır