🤖Dart 3 の switch expressions で factorial を elixir っぽく2023/05/12に公開1ElixirFlutterDartfactorialDart 3tech Elixir バージョン defmodule Factorial do def f(0), do: 1 def f(i) when i > 0 do n * f(i-1) end end Dart 3 バージョン int f(int n) => switch (n) { > 0 => n * f(n - 1), _ => 1, }; > 0 は Swift っぽいですが、_ when n > 0 と同等です。 https://dart.dev/language/branches#switch-expressions 1DiscussionログインするとコメントできますLogin
Discussion