rvirding
Transforming funs to match specifications
How can I get Elixir to help me with generating match specifications from funs. There is an Erlang function :ets.fun2ms/1 which can do this. Sort of anyway, in that the Erlang compiler actually tranforms this to the match specification at compile time. Can I tell the Elixir compiler to do this tranformation?
There are no problems in using match specifications explicitly in Elixr of course as they are just data structures, it doing the transformation I am after.
Most Liked
patrickdm
There is also @ityonemo’s
https://github.com/E-xyza/match_spec
:ets matchspec helper library for elixir. Exposes the fun2ms/1 macro which transforms elixir-style function code into ets matchspecs.
iex> require MatchSpec
iex> MatchSpec.fun2ms(fn {key, value} when key === :foo -> value end)
[{{:"$1", :"$2"}, [{:"=:=", :"$1", {:const, :foo}}], [:"$2"]}]
fun2ms and ms2fun for elixir! Advent of code day 22 (remastered)
hauleth
There is no way to have ets:fun2ms/1 in Elixir, as Elixir disallows parse transforms. However you can use macros to achieve the same thing.
kokolegorille
There is this old post…
Maybe this package can help?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








