|
|
|
|
|
by true_religion
3631 days ago
|
|
This is the starter code: publish :: Bool -> IO ()
publish isDryRun =
if isDryRun
then do
_ <- unsafePreparePackage dryRunOptions
putStrLn "Dry run completed, no errors."
else do
pkg <- unsafePreparePackage defaultPublishOptions
putStrLn (A.encode pkg)
This would be nicer if you could do multiple functions with pattern matching. In Elixir this would be: @spec publish(boolean) :: any
def publish(true = _isDryRun) do
_ = unsafePreparePackage dryRunOptions
IO.puts "Dry run completed, no errors."
end
def publish(false = _isDryRun) do
pkg = unsafePreparePackage defaultPublishOptions
IO.puts (A.encode pkg)
end
Pattern matching is pretty powerful, even going as far to give a dynamic, non-statically types language like Elixir the ability to 'destroy all iffs' too. |
|