Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rupurt/juice
Reduce in memory data structures using a lightweight query language
https://github.com/rupurt/juice
elixir query
Last synced: 3 months ago
JSON representation
Reduce in memory data structures using a lightweight query language
- Host: GitHub
- URL: https://github.com/rupurt/juice
- Owner: rupurt
- License: mit
- Created: 2018-05-06T06:01:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-22T03:52:04.000Z (over 4 years ago)
- Last Synced: 2024-10-30T07:08:56.122Z (3 months ago)
- Topics: elixir, query
- Language: Elixir
- Size: 28.3 KB
- Stars: 26
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Juice
[![Build Status](https://github.com/rupurt/juice/workflows/test/badge.svg?branch=master)](https://github.com/rupurt/juice/actions?query=workflow%3Atest)
[![hex.pm version](https://img.shields.io/hexpm/v/juice.svg?style=flat)](https://hex.pm/packages/juice)Reduce in memory data structures using a lightweight query language
## Installation
Add `juice` to your list of dependencies in `mix.exs`
```elixir
def deps do
[{:juice, "~> 0.0.3"}]
end
```## Usage
Juice can collect and reject string or atom keys from an Elixir [Map](https://hexdocs.pm/elixir/Map.html) or [List](https://hexdocs.pm/elixir/List.html).
Given the map
```elixir
iex> fruit_basket = %{
apples: {
granny_smith: 10,
golden_delicious: 3
},
"oranges" => 5,
plums: 6,
"mangos" => 2,
recipients: [:steph, "michael", :lebron, "charles"]
}
```Return everything with a wildcard `*`
```elixir
iex> Juice.squeeze(fruit_basket, "*") == %{
apples: {
granny_smith: 10,
golden_delicious: 3
},
"oranges" => 5,
plums: 6,
"mangos" => 2,
recipients: [:steph, "michael", :lebron, "charles"]
}
```Remove `plums` and `mangos`
```elixir
iex> Juice.squeeze(fruit_basket, "* -plums -mangos") == %{
apples: {
granny_smith: 10,
golden_delicious: 3
},
"oranges" => 5,
recipients: [:steph, "michael", :lebron, "charles"]
}
```Only collect `granny_smith` `apples` and `oranges` with nested `.` notation
```elixir
iex> Juice.squeeze(fruit_basket, "apples.granny_smith oranges") == %{
apples: {
granny_smith: 10,
},
"oranges" => 5
}
```Collect `plums` and `mangos` for `charles`
```elixir
iex> Juice.squeeze(fruit_basket, "plums mangos recipients.charles") == %{
plums: 6,
"mangos" => 2,
recipients: ["charles"]
}
```