MavuUtils (MavuUtils v1.0.3) View Source
An opinionated set of utility functions used by other (upcoming) packages under mavuio/*
Link to this section Summary
Functions
applies a function to a pipe based on a condition
applies a function to a pipe based on a condition tested with present?/1
applies a function to a pipe based on a condition tested with true?/1
tests if value is "blank"
tests if value is one of several falsy values.
applies a value when piped value is_empty ( as defined by present?/1 )
applies a value when piped value is nil
simple pipeable logger.
macro to only apply a function within a pipe if a condition equals to true.
tests if value is "non-blank"
tries to convert any value to integer
tests if value is one of several truthy values and not false?/1
updates query (given as string) with new parameters (given as keyword-list) parameters which values are nil will be removed from the query
updates url (given as string) with new parameters (given as keyword-list) parameters which values are nil will be removed from the query
Link to this section Functions
applies a function to a pipe based on a condition
##Example:
get_name() |> do_if(opts[:uppercase], &String.upcase/1) |> Jason.encode!()
applies a function to a pipe based on a condition tested with present?/1
##Example:
get_record() |> if_true(opts[:key], &Map.get(&1, opts[:key])) |> Jason.encode!()
applies a function to a pipe based on a condition tested with true?/1
##Example:
get_record() |> if_true(opts[:uppercase], &String.upcase/1) |> Jason.encode!()
tests if value is "blank"
tests if value is one of several falsy values.
applies a value when piped value is_empty ( as defined by present?/1 )
##Example:
taxrate_item =
taxrates[taxkey]
|> if_empty(%{tax: "0", net: "0", gross: "0"})
|> taxrate_item_append(create_taxrate_stats_entry_for_item(item))
applies a value when piped value is nil
##Example:
get_max_order_id() |> if_nil(1000)
simple pipeable logger.
setting a loglevel is mandatory
order |> MavuUtils.log("trying to finish order #{order.id}", :info) |> finish_order()
macro to only apply a function within a pipe if a condition equals to true.
the conditional gets passed to true?/1 first
##Example:
|> pipe_when(
item[:taxrate],
update_in([:taxrates], &update_taxrate_stats(&1, item))
)
tests if value is "non-blank"
tries to convert any value to integer
returns integer on success, nil on failure
tests if value is one of several truthy values and not false?/1
updates query (given as string) with new parameters (given as keyword-list) parameters which values are nil will be removed from the query
updates url (given as string) with new parameters (given as keyword-list) parameters which values are nil will be removed from the query