CharlesO
Please is there a way to do the equivalent of the following with ETS.
:ets.fun2ms(fn {_id, m}
when String.starts_with?(m.name, "charles")
or String.starts_with?(m.mobile, "0809133")
or String.starts_with?(m.email, "charles") ->
m end)
I know we cannot have String.starts_with, or similar functions in a when clause, but is there a way to do the equivalent of this?
iex > :ets.fun2ms(fn {_id, m} when m.name == "charles" or m.mobile == "0809133" or m.email == "charles" -> m end)
[{{:"$1", :"$2"}, [{:orelse, {:orelse, {:==, {:map_get, :name, :"$2"}, "charles"}, {:==, {:map_get, :mobile, :"$2"}, "0809133"}}, {:==, {:map_get, :email, :"$2"}, "charles"}}], [:"$2"]}]
The above attempt will only handle exact string matches, and not partial matches like the LIKE clause
Thanks.
Trending in Questions
Hello everyone!
I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++.
Does anyone ...
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #elixirconf-us
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #security
- #elixirconf-eu
- #processes
- #api
- #forms
- #hex











Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
entone
I found this on the mailing list, [erlang-questions] Binary pattern matching on ETS
It doesn’t look like ETS supports binary pattern matching.
It’s a bit dense, but you can also review the match spec, Match Specifications in Erlang — OTP 29.0.2 (erts 17.0.2)
LostKobrakai
Can you split out the part of the value you want to match on insert or is it dynamic?
CharlesO
it’s dynamic. think of a report page where users can select a bunch of filters to apply
al2o3cr
Answering a “starts with” query like that efficiently (ie not with a full table scan) in Postgres requires a B-tree index; with ETS you’ll need to construct something similar yourself.
The Efficiency Guide goes into some more detail about this approach.
mpope
If you are feeling ambitious, you could create a probabilistic datastructure like a Bloom filter or xor_filter for each entry’s possible matches, like adding
['c', 'ch', 'char', 'charl', charle', 'charles'], then iterate over each filter to check if the partial match is in the filter. This would be for very simple matching, but if your use case doesn’t support complex filters or ranking matches based on the ‘best match’ then it could work. There is a small chance of false positives. I’ve used this before for very simple first + last name matches for ~2k static values and it worked well enough.