Advertisement
lucasteles42

Lambda functions

May 21st, 2022
1,306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // C# JS Dart Scala(1)
  2. x => x + 1
  3.  
  4. // Scala (2)
  5. _ + 1
  6.  
  7. // Java
  8. x -> x + 1
  9.  
  10. // Haskell/Elm
  11. \x -> x + 1
  12.    
  13. // Kotlin (1)
  14. { x -> x + 1 }
  15.  
  16. // Kotlin (2)
  17. { it + 1 }
  18.  
  19. // Swift (1)
  20. { x in x + 1 }
  21.  
  22. // Swift (2)
  23. { $0 + 1 }
  24.  
  25. // F# / OCaml
  26. fun x -> x + 1
  27.  
  28. // SML
  29. fn x => x + 1
  30.    
  31. // Elixir (1)
  32. fn (x) -> x + 1 end
  33.  
  34. // Elixir (2)
  35. &(&1 + 1)
  36.    
  37. // Clojure (1)
  38. (fn [x] (+ x 1))
  39.  
  40. // Clojure (2)
  41. #(+ % 1)
  42.  
  43. // Python
  44. lambda a : a + 10
  45.  
  46. // Scheme
  47. (lambda (x) (+ 1 x))
  48.  
  49. // Lua
  50. function(x) return x + 1 end
  51.  
  52. // Go
  53. func(x int) string { return x + 1 }
  54.  
  55. // R
  56. (function (x) x+1)
  57.  
  58. // Octave / Matlab
  59. @(x) x + 1
  60.  
  61. //Delphi
  62. function(x: Integer): Integer
  63. begin
  64.   Result := x + 1;
  65. end;
  66.  
  67. // Wolfram
  68. // Mathematica
  69. #1+1&
  70.  
  71. // Perl
  72. sub { my $x = shift; $x + 1 }
  73.  
  74. // Visual Prolog
  75. { (X) = X+1 },
  76.  
  77. // Smalltalk
  78. [:x|x+1]
  79.  
  80. // Rust
  81. |x| { x + 1 }
  82.  
  83. // C++
  84. [](int x) { return x + 1; }
  85.  
  86. // PowerShell (1)
  87. { $args[0] + 1 }
  88.  
  89. // PowerShell (2)
  90. { param($x) $x + 1 }
  91.  
  92. // Erlang
  93. fun(X) -> X + 1 end
  94.  
  95. // Ruby
  96. lambda { |x| x + 1 }
  97.  
  98. // PHP
  99. function ($x) { return $x + 1};
  100.  
  101. // VB.NET
  102. Function(x) x + 1  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement