Elixir Blog Posts

I know the elixir’s Stream module has a lot of function ref returning, but it is not quite like this. FWIR it does not have any function def chaining.

2 Likes

Till now I never tried them in real world projects. I just encountered that while reading about the anonymous function. If you find one please share that will help us
Anyway thanks for reading… and mentioning…

1 Like

Pretty cool! The whole “char list” thing has been a pain for me… except when it comes in Very Handy, like when applying a Range, which only works with integers. As for the chains, though, don’t give people any ideas; that’s what leads to Callback Hell, so common in JavaScript. :frowning:

3 Likes

Cool, thanks for the tips. There were a few things that I did not know about which will be really helpful in my new project.

3 Likes

Glad that you felt this useful.

1 Like

Thanks for sharing. I have a few remarks though:

The first tip is a bit odd. Multiple or is much more readable and besides your hack behaves differently (it would calculate all conditions, instead of stop on the first true).

I guess the tip #3 could be more useful if you would mention that .iex.exs could be used in a project directory and any Elixir-code could be putted in that project-specified file, it’s very helpful to put some aliases into it.

As to #6, there is also put_in/2 that imho even more helpful than get_in/2.

In #7 could be described a full form with .. do .. else .. end.

Tip #10: IO.inspect/2 inside pipes.

2 Likes

Thanks for tracing out this :bouquet: :bouquet:

1 Like

Glad that you mentioned put_in I am expecting that if we show some thing they can dig more deepper. So I just mentioned only get_in in purpose.

Thanks for the feeds that really helpful for the people.

1 Like

I love to see folks helping teach others in the community, but this post is ripped directly out of my book, in many cases word-for-word and line-for-line code wise. I would appreciate if you reworked your post as original content – which draws inspirations from what you learned in my book, rather than a copy of its contents :slight_smile: If you’re unable to do so, please remove it.

9 Likes

You stood inspiration for writing that.
I am sorry to copy few sentences. I really apologize you for that. I thought that would add some extra attraction for the readers. Anyway I will change every line I used from your book. I will keep it more what I understood after reading the book.

1 Like

As a general rule you need to obtain permission from the authors of copyrighted work. Small snippets can ‘sometimes’ be included depending on their context but always with a credit to the source and even then sparingly (don’t do this for large excerpts or numerous instances, as that can be classed as plagiarism) if in doubt it’s best to avoid reproduction of copyrighted content altogether.

Also I would like to comment that Chris’s response was very gracious, others may not have been quite so diplomatic in their response. Please keep this in mind and if you have done similar previously please amend those instances as well - book authors and content creators spend a lot of time writing and preparing content and it can be very disheartening when others reproduce material without permission (particularly when they pass it off as their own work).

Like Chris said it’s great that people want to help others learn… just please make sure it’s your own content :slight_smile:

4 Likes

I totally changed the entire article giving credits and removing stuff. That is really bad from my side.

I totally changed and removed every thing that is used from the book. and giving credits. Really my bad. Thank you for being so kind. :bouquet: :bouquet:

I haven’t read the book myself yet (it’s on my Kindle ready!) but just to comment on this:

Tribute:
Examples are used from the book. I really recommend this Meta Programming. You can buy here.

Are these copied from the book? If so you should create your own examples to demonstrate the same point.

4 Likes

definitely Thanks for the point…

I’d like to recommend one tip: to update a map with a keyword list safely and exhaustively

2 Likes

Great job, thank you for taking the time to do it. I found guard functions to macros and destructing extremely helpful (life changing?)!

2 Likes

Glad that helped you. Thanks for your time and reading …
Happy Coding …

1 Like

Interesting article!
Here are some important notes that you might want to include to make the different points more complete:

    1. Strings to module names: You use Module.concat in your article, but in 99/100 cases you’ll want to use Module.safe_concat instead: Atoms are not garbage collected, which means that when different atoms are made (that did not exist before), for instance when them somehow depending on user input, you open up your application to an easy DDoS attack.
    1. I would like to add here that it is almost always a bad idea to pipe an anonymous function. It is a clear indication that you have a bit of code that could be split off in its own, named function using def or defp that does what you want.
    1. Note that it only removes the first occurrence of every element in the second list. Note also that it is rather slow to use --. If you frequently need to remove elements from a collection, you properly would want to use either a Set or a Map instead.
2 Likes

You might want to add to 7) that if you want keywords to be able to passed in any order, you should accept any list in your function head, and then use Keyword.get inside the function instead:

defmodule User do
  def user(options) do
    name = Keyword.get(options, :user)
    age = Keyword.get(options, :age)
    "name: #{name}-- age: #{age}"
  end
end

This also allows you to specify useful default values for keywords that are not included when the function is called.

And for 8) Note that there is Map.get/3 as well, which allows you to retrieve a value from a map with a default when it does not exist.

3 Likes