MapSchema.ExuString (map_schema v0.2.7) View Source
Elixir UnOfficial Extension of String module
Link to this section Summary
Functions
Check if a string is float
Check if a string is integer
Parse string to Float
Parse string to Integer
Link to this section Functions
Specs
Check if a string is float
Why is interesting
This method let you check a String is float.
Target of proposal
Keep simple code
Examples
iex> MapSchema.ExuString.is_float?("1")
false
iex> MapSchema.ExuString.is_float?("-0.10")
true
iex> MapSchema.ExuString.is_float?("10.0000000")
true
iex> MapSchema.ExuString.is_float?("10.1")
true
iex> MapSchema.ExuString.is_float?("invalid_float")
false
iex> MapSchema.ExuString.is_float?(:invalid_string)
false
iex> ["1.2","3.1","invalid"] |> Enum.all?(&MapSchema.ExuString.is_float?(&1))
false
Specs
Check if a string is integer
Why is interesting
This method let you check a String is integer.
Target of proposal
Keep simple code
Examples
iex> MapSchema.ExuString.is_integer?("1")
true
iex> MapSchema.ExuString.is_integer?("-1")
true
iex> MapSchema.ExuString.is_integer?("10.0")
false
iex> MapSchema.ExuString.is_integer?("10.1")
false
iex> MapSchema.ExuString.is_integer?("invalid_integer")
false
iex> MapSchema.ExuString.is_integer?(:invalid_string)
false
iex> ["1","3","invalid"] |> Enum.all?(&MapSchema.ExuString.is_integer?(&1))
false
Specs
Parse string to Float
Why is interesting
This method let you cast fast a String to float without require use a official Float.parse/2 that return a tuple. This method return an float number or :error
Target of proposal
Keep simple code
Examples
iex> MapSchema.ExuString.to_float!(1.0)
1.0
iex> MapSchema.ExuString.to_float!("1")
:error
iex> MapSchema.ExuString.to_float!("-0.10")
-0.10
iex> MapSchema.ExuString.to_float!("10.0000000")
10.0
iex> MapSchema.ExuString.to_float!("10.1")
10.1
iex> MapSchema.ExuString.to_float!("invalid_float")
:error
iex> MapSchema.ExuString.to_float!(:invalid_string)
:error
iex> ["1.1","3.3","invalid"] |> Enum.map(&MapSchema.ExuString.to_float!(&1))
[1.1,3.3,:error]
Specs
Parse string to Integer
Why is interesting
This method let you cast fast a String to integer without require use a official Integer.parse/2 that return a tuple. This method return an integer number or :error.
Target of proposal
Keep simple code
Examples
iex> MapSchema.ExuString.to_integer!(1)
1
iex> MapSchema.ExuString.to_integer!("1")
1
iex> MapSchema.ExuString.to_integer!("-1")
-1
iex> MapSchema.ExuString.to_integer!("10.0")
:error
iex> MapSchema.ExuString.to_integer!("10.1")
:error
iex> MapSchema.ExuString.to_integer!("invalid_integer")
:error
iex> MapSchema.ExuString.to_integer!(:invalid_string)
:error
iex> ["1","3","invalid"] |> Enum.map(&MapSchema.ExuString.to_integer!(&1))
[1,3,:error]