potion v1.3.1 Potion

Summary

Functions

debug

check empty

Gets the value for a specific key

Puts the given value

Puts the given value

Converts atom

Converts float

Converts integer

Converts string

Collection trim

Deletes the given value from key

Deletes the given value from value

Functions

debug(data)

debug

Examples

Potion.debug([1,2,3])
【Potion Debug】
(List)
   [0] => Integer: 1
   [1] => Integer: 2
   [2] => Integer: 3

Potion.debug(%{a: "some content", b: "some content"})
【Potion Debug】
(Map)
   %{:a} => BitString: some content
   %{:b} => BitString: some content

 Potion.debug(__struct__)
 【Potion Debug】
 (Struct)
    %{:age} => Integer: 14
    %{:name} => BitString: potion
empty?(data)
empty?(any) :: boolean

check empty

Examples

Potion.empty?([])
true
Potion.empty?(%{})
true
Potion.empty?({})
true
Potion.empty?("")
true
Potion.empty?(nil)
true
Potion.empty?(false)
true

Potion.empty?([1,2])
false
Potion.empty?(%{map: "some content"})
false
Potion.empty?({1, 2})
false
Potion.empty?("some content")
false
Potion.empty?(1)
false
Potion.empty?(true)
false
get(data, key, default \\ nil)
get(Map.t | List.t | Tuple.t, String.t | Integer.t | Atom.t, any) :: any

Gets the value for a specific key

Examples

Potion.get([1,2,3], 0)
1
Potion.get([1,2,3], 4)
nil
Potion.get({1,2,3}, 0)
1
Potion.get([index: 1, index2: 2], :index2)
2
Potion.get({:ok, "some content"}, :ok)
"some content"
Potion.get(%{map: "some content"}, :map)
"some content"
Potion.get([1,2,3], 4, 0)
0
put(data, item)
put(Map.t | List.t | Tuple.t, any) ::
  Map.t |
  List.t |
  Tuple.t

Puts the given value

Examples

Potion.put([1], 2)
[1,2]
Potion.put([1], [2])
[1,2]
Potion.put(%{map: "some content"}, add: "some content")
%{map: "some content", add: "some content"}
Potion.put(%{map: "some content"}, [add: "some content"])
%{map: "some content", add: "some content"}
Potion.put(%{map: "some content"}, %{add: "some content"})
%{map: "some content", add: "some content"}
Potion.put(%{map: "some content"}, %{map: "some content!"})
%{map: "some content!"}
Potion.put({1,2,3}, 4)
{1,2,3,4}
put_first(data, item)
put_first(Map.t | List.t | Tuple.t, any) ::
  Map.t |
  List.t |
  Tuple.t

Puts the given value

Examples

Potion.put_first([1], 2)
[2,1]
Potion.put_first([1], [2])
[2,1]
Potion.put_first(%{map: "some content"}, add: "some content")
%{add: "some content", map: "some content"}
Potion.put_first(%{map: "some content"}, [add: "some content"])
%{add: "some content", map: "some content"}
Potion.put_first(%{map: "some content"}, %{add: "some content"})
%{add: "some content", map: "some content"}
Potion.put_first(%{map: "some content"}, %{map: "some content!"})
%{map: "some content"}
Potion.put_first({1,2,3}, 4)
{4,1,2,3}
to_atom(item)
to_atom(BitString.t | List.t | Atom.t) :: Atom.t

Converts atom

Examples

Potion.to_atom("atom")
:atom
Potion.to_atom('atom')
:atom
Potion.to_atom(:atom)
:atom
to_float(item)
to_float(BitString.t | List.t | Float.t | Integer.t) :: Float.t

Converts float

Examples

Potion.to_float("1.0")
1.0
Potion.to_float('1.0')
1.0
Potion.to_float(1)
1.0
Potion.to_float(1.0)
1.0
to_integer(item)
to_integer(BitString.t | List.t | Float.t | Integer.t) :: Integer.t

Converts integer

Examples

Potion.to_integer("1")
1
Potion.to_integer('1')
1
Potion.to_integer(1)
1
Potion.to_integer(1.0)
1
Potion.to_integer(1.5)
1
to_string(item)
to_string(BitString.t | List.t | Atom.t | Float.t | Integer.t) :: BitString.t

Converts string

Examples

Potion.to_string("string")
"string"
Potion.to_string('string')
"string"
Potion.to_string(:string)
"string"
Potion.to_string(1)
"1"
Potion.to_string(1.0)
"1.0"
trim(data)
trim(Map.t | List.t | Tuple.t) :: Map.t | List.t | Tuple.t

Collection trim

Examples

Potion.trim([1,"",3])
[1,3]
Potion.trim(%{map: "some content", map2: ""})
%{map: "some content"}
Potion.trim({1, ""})
{1}
unset(data, key)
unset(Map.t | List.t | Tuple.t, String.t | Integer.t | Atom.t | List.t) :: any

Deletes the given value from key

Examples

Potion.unset([1,2], 0)
[2]
Potion.unset(%{a: 1, b: 2}, :a)
%{b: 2}
Potion.unset({1,2}, 0)
{2}
Potion.unset([1,2], [0,1])
[]
Potion.unset(%{a: 1, b: 2}, [:a, :b])
%{}
Potion.unset({1,2}, [1,2])
{1}
unset_value(data, value)
unset_value(Map.t | List.t | Tuple.t, String.t | Integer.t | Atom.t | List.t) :: any

Deletes the given value from value

Examples

Potion.unset_value([1,2], 2)
[1]
Potion.unset_value([1,2], [0,1])
[2]
Potion.unset_value(%{a: 1, b: 2}, 1)
%{b: 2}
Potion.unset_value(%{a: 1, b: 2}, [1, 2])
%{}
Potion.unset_value({1,2}, 2)
{1}
Potion.unset_value({1,2}, [1,2])
{}