Skip to content
/ juice Public

Reduce in memory data structures using a lightweight query language

License

Notifications You must be signed in to change notification settings

rupurt/juice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Juice

Build Status hex.pm version

Reduce in memory data structures using a lightweight query language

Installation

Add juice to your list of dependencies in mix.exs

def deps do
  [{:juice, "~> 0.0.3"}]
end

Usage

Juice can collect and reject string or atom keys from an Elixir Map or List.

Given the map

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 *

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

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

iex> Juice.squeeze(fruit_basket, "apples.granny_smith oranges") == %{
	apples: {
		granny_smith: 10,
	},
	"oranges" => 5
}

Collect plums and mangos for charles

iex> Juice.squeeze(fruit_basket, "plums mangos recipients.charles") == %{
	plums: 6,
	"mangos" => 2,
	recipients: ["charles"]
}

About

Reduce in memory data structures using a lightweight query language

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages