cheekyfinder
ExSift 0.2.0 - Filter any Elixir type with MongoDB-style queries
ExSift 0.2.0 is out. The big headline: you can now filter anything not just plain maps. Keyword lists, MapSets, structs, and any custom type all work out of the box.
What’s new
Filter keyword lists
data = [[name: "Alice", age: 30], [name: "Bob", age: 25]]
ExSift.filter(data, %{"age" => %{"$gt" => 28}})
# => [[name: "Alice", age: 30]]
Filter structs directly
Shape matching, dot notation, and all operators work on any struct - no boilerplate needed:
defmodule User, do: defstruct [:name, :age, :role]
data = [
%User{name: "Alice", age: 30, role: "admin"},
%User{name: "Bob", age: 25, role: "user"},
%User{name: "Charlie", age: 35, role: "admin"}
]
ExSift.filter(data, %{role: "admin", age: %{"$gte" => 30}})
# => [%User{name: "Alice", ...}, %User{name: "Charlie", ...}]
# Dot notation through nested structs
ExSift.filter(records, %{"address.city" => "NYC"})
MapSet fields - $size, $all, $in, $elemMatch
data = [
%{user: "alice", perms: MapSet.new([:read, :write, :delete])},
%{user: "bob", perms: MapSet.new([:read])}
]
# Who has both :read and :write?
ExSift.filter(data, %{perms: %{"$all" => [:read, :write]}})
# => [%{user: "alice", ...}]
# Who has exactly 1 permission?
ExSift.filter(data, %{perms: %{"$size" => 1}})
# => [%{user: "bob", ...}]
# Who has :write in their perms?
ExSift.filter(data, %{perms: %{"$in" => [:write]}})
# => [%{user: "alice", ...}]
Custom types via the Collection protocol
Implement ExSift.Collection for any type and it will work with all operators:
defimpl ExSift.Collection, for: MyQueue do
def fetch(q, key), do: Map.get(q, key)
def to_pairs(q), do: [size: q.size, name: q.name]
def member?(q, value), do: value in q.items
def size(q), do: length(q.items)
end
# Now ExSift works on MyQueue natively
ExSift.filter(queues, %{name: "priority", "$size" => 5})
Compiled filters work across all types
compile/1 returns a plain function. Reuse it across any collection type:
is_senior = ExSift.compile(%{age: %{"$gte" => 30}})
Enum.filter(maps, is_senior)
Enum.filter(structs, is_senior)
Enum.filter(keyword_lists, is_senior)
Enum.count(all_users, is_senior)
Upgrading
No breaking changes. Drop in the new version:
{:ex_sift, "~> 0.2.0"}
Links
- Hex: ex_sift | Hex
- Docs: ex_sift v0.2.0 — Documentation
- GitHub: GitHub - sahilpohare/ex_sift: MongoDB-style query filtering for Elixir collections. · GitHub
- Changelog: ex_sift/CHANGELOG.md at main · sahilpohare/ex_sift · GitHub
As always, feedback and PRs welcome!
Trending in News & Updates
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
I’ll be using this thread to share Hologram patch release announcements. Minor releases will continue to get dedicated threads with blog ...
New
This release unifies configuration for queues, repos, and services, swaps opaque timing integers for readable durations, and backports pe...
New
:heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::heart::hea...
New
Bond brings Design by Contract to Elixir: preconditions, postconditions and invariants as executable specifications, checked at runtime a...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
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
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
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
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
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming









