MavuUtils (MavuUtils v0.1.13) View Source

An opinionated set of utility functions used by other (upcoming) packages under mavuio/*

Link to this section Summary

Functions

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

tests if value is "blank"

tests if value is one of several falsy values.

Link to this function

if_empty(val, default_val)

View Source

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))
Link to this function

if_nil(val, default_val)

View Source

applies a value when piped value is nil

##Example:

get_max_order_id() |> if_nil(1000)

Link to this function

log(data, msg \\ "", level)

View Source

simple pipeable logger.

setting a loglevel is mandatory

order |> MavuUtils.log("trying to finish order #{order.id}", :info) |> finish_order()

Link to this macro

pipe_when(left, condition, fun)

View Source (macro)

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

Link to this function

update_params_in_path(url, params)

View Source
Link to this function

update_params_in_query(query, params)

View Source

updates query (given as string) with new parameters (given as keyword-list) parameters which values are nil will be removed from the query

Link to this function

update_params_in_url(url, params)

View Source

updates url (given as string) with new parameters (given as keyword-list) parameters which values are nil will be removed from the query