Live data from Hacker News

Learning Elixir: My side-project

adrian-philipp.com

1–10 of 38 posts

Re: Learning Elixir: My side-project

#2
I 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 actually, scratch that!

[1] https://github.com/graphql-elixir/graphql

Re: Learning Elixir: My side-project

#4

Picking 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?

There are typespec annotations. The syntax using guards allows you to have for example:

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

#5

I 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…

Absinthe is completely separate from that project. I think the whole community effort is around Absinthe at the moment and it's shaping into a great library. There's also a PragProg book coming out in Autumn "Craft GraphQL APIs in Elixir with Absinthe" [1].

[1]: https://pragprog.com/book/wwgraphql/craft-graphql-apis-in-el...

Re: Learning Elixir: My side-project

#6

Picking 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

#7

Picking 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?

Elixir uses pattern matching for its functions. You can define multiple functions with the same name, and which function is used depends on which one "matches" first, based on the arguments.

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

#8

Picking 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...

Can't?

Re: Learning Elixir: My side-project

#9
post #8

Earlier 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?

That was awkwardly phrased. I was trying to say "TypeScript's annotations can't express something this Erlang example."

Re: Learning Elixir: My side-project

#10

Picking 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?

There are optional type annotations that are supported by docs and compile-time tools.

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-...

Post reply on HN