Krug.StructUtil (Krug v0.1.0) View Source
Utilitary secure module to provide mechanisms to handle some complex operations on structs.
Link to this section Summary
Functions
Return a value from a tuple, ignoring the key.
Verify if a value is present on a list or not.
Verify if one value of a list values
is present on a list or not.
Return true when find first match. If none value of values
is present on list,
return false.
Link to this section Functions
Return a value from a tuple, ignoring the key.
If the tuple is nil or value of key is nil/empty return nil.
If tuple contains only the key, return nil.
Examples
iex > tuple = {:ok}
iex > Krug.StructUtil.getValueFromTuple(tuple)
nil
iex > tuple = {:ok,nil}
iex > Krug.StructUtil.getValueFromTuple(tuple)
nil
iex > tuple = {:ok,[1,2,3]}
iex > Krug.StructUtil.getValueFromTuple(tuple)
[1,2,3]
iex > tuple = {:ok,%{a: 1, b: 2, c: 3}}
iex > Krug.StructUtil.getValueFromTuple(tuple)
%{a: 1, b: 2, c: 3}
iex > tuple = {:error,"Operation Error"}
iex > Krug.StructUtil.getValueFromTuple(tuple)
"Operation Error"
Verify if a value is present on a list or not.
If the list is nil/empty return false.
Examples
iex > list = []
iex > Krug.StructUtil.listContains(list,nil)
false
iex > list = nil
iex > Krug.StructUtil.listContains(list,nil)
false
iex > list = [nil]
iex > Krug.StructUtil.listContains(list,nil)
true
iex > list = [1,%{a: 1, b: 2},"",nil,[1,2,3],5]
iex > Krug.StructUtil.listContains(list,"")
true
iex > list = [1,%{a: 1, b: 2},"",nil,[1,2,3],5]
iex > Krug.StructUtil.listContains(list," ")
false
iex > list = [1,%{a: 1, b: 2},"",nil,[1,2,3],5]
iex > Krug.StructUtil.listContains(list,%{a: 1, b: 2})
true
iex > list = [1,%{a: 1, b: 2},"",nil,[1,2,3],5]
iex > Krug.StructUtil.listContains(list,%{a: 1, b: 5})
false
Verify if one value of a list values
is present on a list or not.
Return true when find first match. If none value of values
is present on list,
return false.
If the list is nil/empty return false.
Examples
iex > list = []
iex > values = []
iex > Krug.StructUtil.listContainsOne(list,values)
false
iex > list = [1,2,4,6]
iex > values = [5,7,8]
iex > Krug.StructUtil.listContainsOne(list,values)
false
iex > list = [1,2,4,6]
iex > values = [5,7,8,"A",%{a: 1, b: 3},9,6]
iex > Krug.StructUtil.listContainsOne(list,values)
true
iex > list = [1,2,4,6]
iex > values = [5,7,8,"A",%{a: 1, b: 3},9]
iex > Krug.StructUtil.listContainsOne(list,values)
false
iex > list = [1,2,4,6,%{a: 1, b: 3}]
iex > values = [5,7,8,"A",%{a: 1, b: 3},9]
iex > Krug.StructUtil.listContainsOne(list,values)
true
iex > list = [1,2,4,6,%{a: 1, b: 3}]
iex > values = [5,7,8,"A",%{a: 1, b: 5},9]
iex > Krug.StructUtil.listContainsOne(list,values)
false