4 ms·
Exactly! In Elixir, structs are just a special case of a map with a little bit of compile-time field checking magic. At runtime it's all the same. It's so easy
by ashton314 5y ago
Exactly! In Elixir, structs are just a special case of a map with a little bit of compile-time field checking magic. At runtime it's all the same. It's so easy to see the shape of things and figure out where stuff came from. Also, `|> IO.inspect(label: "...")` is one of my favorite things ever in getting my head wrapped around a new struct I haven't encountered before.
- dnautics 5y agoif you use vscode, you might like this: https://slickb.it/bits/70 https://slickb.it/bits/70
- bostonvaulter2 5y agoNice snippet! I think that snippets are often underrated by programmers, especially debugging related snippets (the code is temporary so "duplication" doesn't really matter).
- dnautics 5y agoThis snippet is my #1 productivity enhancer for elixir. It goes extremely well with multiline cursor. Especially since line numbers are typically the same length so ninjaing out the inspects in a pipeline is usually fast
- ashton314 5y agoOh that's lovely! I'm an Emacs user, and I've got two yasnippets that do roughly the same thing: https://gist.github.com/ashton314/f0a90a46e39b103635f2be8d8e6aeefd https://gist.github.com/ashton314/f0a90a46e39b103635f2be8d8e... The second one adds a pipe in front, which is super handy. Yours gives me some ideas though…
- bostonvaulter2 5y agoDo you know if you can insert the current line number with yasnippet? I have two snippets that look almost identical to yours, although my non-pipe version leaves the cursor at the beginning of the label since I've found that I often want to customize the label because I may be inspecting similar variables at different points in the code. Ah, figured it out. It's very powerful to be able to call elisp inside snippets. Here's my new Labeled Inspect snippet: # -*- mode: snippet -*- # name: Labeled Inspect # key: lin # -- IO.inspect($1, label: "$2$1 (`(buffer-name)`:`(line-number-at-pos))`") and a piped version: # -*- mode: snippet -*- # name: Piped Inspect # key: pin # -- |> IO.inspect(label: "$2$1 (`(buffer-name)`:`(line-number-at-pos))`")
- ashton314 5y agoExcellent! I'm going to have to extend mine. Emacs ftw
- pablodavila 5y agoAlso, if you have piped functions you can now use `|> tap(&IO.inspect(&1.a))`at any point (requires 1.12).