Learning Elixir: My side-project
adrian-philipp.com
Learning Elixir: My side-project
1–10 of 38 posts
Re: Learning Elixir: My side-project
#2EDIT: Looks like the repo is pretty abandoned actually, scratch that!
Re: Learning Elixir: My side-project
#3I have to say things like this tickle my funny bone though:
> def backlog(board_id) when is_integer(board_id) do
What happened to good old fashioned function foo (int bar) :)
Is there an equivalent to typescript for elixir?
Re: Learning Elixir: My side-project
#4Picking up new languages is fun. I have to say things like this tickle my funny bone though: > def backlog(board_id) when is_integer(board_id) do What happened to good old fashioned function foo (int bar) :) Is there an equivalent to typescript for elixir?
def backlog(board_id) when is_integer(board_id), do: something
and
def backlog(board_id) when is_list(board_id), do: some_list_thing
Re: Learning Elixir: My side-project
#5I had a brief stint of working with Elixir a while ago, and got side-tracked and spent that time going down the GraphQL/Relay rabbit hole instead. During that time I was ramping up to help out on the GraphQL Elixir project [1]. I don't know its current state, but it might be worth looking into vs Absinthe (which I'm pretty sure was branched off that project originally). EDIT: Looks like the repo is pretty abandoned a…
[1]: https://pragprog.com/book/wwgraphql/craft-graphql-apis-in-el...
Re: Learning Elixir: My side-project
#6Picking up new languages is fun. I have to say things like this tickle my funny bone though: > def backlog(board_id) when is_integer(board_id) do What happened to good old fashioned function foo (int bar) :) Is there an equivalent to typescript for elixir?
right_age(X) when X >= 16, X =
true;
right_age(_) ->
false.
http://learnyousomeerlang.com/syntax-in-functions#guards-gua...Re: Learning Elixir: My side-project
#7Picking up new languages is fun. I have to say things like this tickle my funny bone though: > def backlog(board_id) when is_integer(board_id) do What happened to good old fashioned function foo (int bar) :) Is there an equivalent to typescript for elixir?
E.g
############
# no args
def my_func() do: (something) end
# an array arg, assigning the first to "head and the rest to "tail"
def my_func([ head | tail ]) do: (something) end
# two args, so you'd call this my_func/2 instead of my_func/1.
def my_func([], %{key: val}) do: (something) end
# definition with a guard clause, so it checks the value of the arg when determining whether it matches
def my_func(val) when (val > 10) do: (something) end
# wildcard matcher for any single arg passed
def my_func(_) do: (something) end
############
Pattern matching was my gateway drug for getting into Elixir, and it's just the tip of the iceberg when it comes to what makes the language great to work with. It's particularly elegant when pattern matching responses from HTTP requests, using switch statements. No need to put try catch blocks around everything, just pattern match against a tuple with :ok and a tuple with :error
Re: Learning Elixir: My side-project
#8Picking up new languages is fun. I have to say things like this tickle my funny bone though: > def backlog(board_id) when is_integer(board_id) do What happened to good old fashioned function foo (int bar) :) Is there an equivalent to typescript for elixir?
I've been reading about Erlang recently, and guards (the when clause) seem much more expressive than something like type annotations for function parameters. For example, TypeScript's annotations can't express something like this (which also shows Erlang's pattern matching): right_age(X) when X >= 16, X = true; right_age(_) -> false. http://learnyousomeerlang.com/syntax-in-functions#guards-gua...
Re: Learning Elixir: My side-project
#9Earlier quoted context omitted.
I've been reading about Erlang recently, and guards (the when clause) seem much more expressive than something like type annotations for function parameters. For example, TypeScript's annotations can't express something like this (which also shows Erlang's pattern matching): right_age(X) when X >= 16, X = true; right_age(_) -> false. http://learnyousomeerlang.com/syntax-in-functions#guards-gua...
Can't?
Re: Learning Elixir: My side-project
#10Picking up new languages is fun. I have to say things like this tickle my funny bone though: > def backlog(board_id) when is_integer(board_id) do What happened to good old fashioned function foo (int bar) :) Is there an equivalent to typescript for elixir?
But if you don't mind me nerd-sniping you ... someone's done something a bit crazier recently.
It's called Elmchemy[1], which lets you write Elm that compiles to elixir. Recent blog post[2].
---
[1] https://github.com/wende/elmchemy
[2] https://hackernoon.com/elmchemy-write-type-safe-elixir-code-...