sodapopcan
I go through bouts of playing around with re-writing source-code using Sourceror. It generally goes: I learn a whole bunch, start getting comfortable with it, stop doing it for many months and forget everything ![]()
I’m back at it and just finished creating a function that will inline single pipes. IE:
socket
|> assign(:foo, "foo")
becomes:
assign(socket, :foo, "foo")
I was looking to get some feedback on my solution.
I initially thought I could get away with simply pre- or postwalking with some clever pattern-matching, but that proved to be difficult for me. I ended up using a zipper which made life a LOT easier getting me to a solution quite quickly. There are still a few issues with line-length but I’m otherwise quite happy with the clarity of it.
Still, I’m wondering:
- Is this possible using walking with an accumulator?
- Do you have a solution that’s different/better than mine?
- Do you have any other feedback?
TIA
def unpipe(ast) do
Sourceror.Zipper.zip(ast)
|> Sourceror.Zipper.traverse(fn
%{node: {:|>, _, _} = node} = zipper ->
prev = Sourceror.Zipper.prev(zipper)
next = Sourceror.Zipper.next(zipper)
with false <- match?(%{node: {:|>, _, _}}, prev),
false <- match?(%{node: {:|>, _, _}}, next),
{:|>, _, [var, {func, meta, args}]} <- node do
Sourceror.Zipper.replace(zipper, {func, meta, [var | args]})
else
_ ->
zipper
end
zipper ->
zipper
end)
|> Sourceror.Zipper.topmost_root()
end
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 15 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sodapopcan
That’s good to know! I’ve been thinking of polishing and focusing up that package for a while now, even just for learnings, but have been spending my time on other ventures. I made it at a time where I was prototyping a new Phoenix app weekly and I don’t do that anymore. I will certainly look to igniter for inspiration, though. I remember a convo where you and Ben were talking about using closures in module attributes which was the big piece of refactoring I wanted to do, even just to see it work. I’m currently using a GenServer to get around not being able to figure that out for myself but anyway, that is a bit off topic
zachdaniel
I’ve talked about the idea itself many times in the past, but it was pretty nebulous. I don’t think that igniter is really what you’re looking for, just perhaps good for some inspiration potentially
sodapopcan
I am aware of Styler but it’s too stringent for our tastes We’re small team and not looking for enforcement, just to fix a whole bunch of stuff that we considered poor/inconsistent style.
sodapopcan
I’ve looked quickly at igniter but haven’t tried it out yet. Over a year ago now I started a very similar project called vials, though once it got to where I was happy with it. I went from the perspective of “wrapping” mix tasks though really it’s just for editing generators and really it was just about editing the output of
mix phx.new. Overall, it felt a bit unfocused so I’ll check it out. I do remember hearing about a similar project also about a year ago… was that you? Were you talking about the beginnings of igniter back then?slouchpie
You can also use styler | Hex to fix single pipes.
zachdaniel
Based on your proclivity for source code rewriting, you may also be interested in the igniter project
It’s similar to recode in some ways, but designed for building generators, installers, and upgraders. GitHub - ash-project/igniter: A code generation and project patching framework. · GitHub
sodapopcan
Turns out the real answer is “just use recode” which I totally forgot about. Was a good learning experience regardless
sodapopcan
I’ll keep an eye out for this, thanks!!
sodapopcan
Ok, I may be celebrating early but simply setting empty
metasolved it.zachdaniel
Ah, right. I think what you can do is check if the node previous to the top node is
{:__block__, meta, [just_one_thing]}and if so, replace that node instead? Might mess w/ your traversal though.