Crate lowdash

Source

Modules§

common

Structs§

Entry
Represents a key-value pair entry in a map.

Enums§

DurationUnit
Time units for calculating duration.

Functions§

assign
Merges multiple maps into a single map. If the same key exists in multiple maps, the value from the last map is used.
associate
Creates a HashMap by transforming each element in a collection into a key-value pair using a provided function.
camel_case
Converts a string to camelCase.
capitalize
Capitalizes the first letter of the input string and converts the rest to lowercase.
char_length
Returns the length of a string in Unicode characters.
chunk
Divide a collection into smaller chunks of a specified size, preserving the order of elements.
chunk_string
Splits a string into chunks of specified size.
clamp
Clamps a value between a minimum and maximum value. If the value is less than the minimum, returns the minimum. If the value is greater than the maximum, returns the maximum. Otherwise, returns the value unchanged.
combination
Finds all combinations of k elements from a collection.
compact
Removes all zero-valued elements from a collection, preserving the order of non-zero elements.
count
Counts the number of occurrences of a specific value in a collection.
count_by
Counts the number of elements in a collection that satisfy a given predicate.
count_values
Counts the number of occurrences of each value in a collection.
count_values_by
Counts the number of occurrences of each value in a collection after applying a mapper function.
drop
Removes the first n elements from a collection and returns the remaining elements. If n is greater than or equal to the length of the collection, returns an empty Vec.
drop_by_index
Removes elements from a collection at the specified indices. Supports negative indices which count from the end of the collection. Indices that are out of bounds are ignored.
drop_right
Removes the last n elements from a collection and returns the remaining elements. If n is greater than or equal to the length of the collection, returns an empty Vec.
drop_right_while
Removes elements from the end of a collection as long as a predicate returns true, and returns the remaining elements. As soon as the predicate returns false, the function stops dropping elements.
drop_while
Removes elements from the beginning of a collection as long as a predicate returns true, and returns the remaining elements. As soon as the predicate returns false, the function stops dropping elements.
duration_between
Returns the absolute difference between two dates in the specified unit.
earliest
Find the earliest time in a collection. If the collection is empty, returns None.
earliest_by
Find the earliest item in a collection based on a custom iteratee function. If the collection is empty, returns None.
ellipsis
Truncates a string and appends an ellipsis ("...") if it exceeds the specified length.
entries
Collects all entries from a map into a vector of Entry structs.
fill
Fill a collection with a specified value, returning a new vector with all elements set to the initial value.
filter
Filter items from a collection that satisfy a predicate.
filter_map
Apply a function to each item in a collection, filtering and transforming items based on a callback.
filter_reject
Filters a collection into two separate vectors based on a predicate function.
find
Find the first item in a collection that satisfies a predicate. If no item satisfies the predicate, return None.
find_duplicates
Find all duplicate elements in a collection (elements that appear more than once). Each duplicate element appears exactly once in the result.
find_duplicates_by
Find all duplicate elements in a collection based on a key generated by the iteratee function. Each duplicate element (beyond the first occurrence) appears in the result.
find_index_of
Find the first item in a collection that satisfies a predicate and return its index. If no item satisfies the predicate, return None.
find_key
Find the key in a map that corresponds to a given value. If no key corresponds to the value, return None.
find_key_by
Find the key in a map that satisfies a predicate based on both key and value. If no key satisfies the predicate, return None.
find_last_index_of
Find the last item in a collection that satisfies a predicate and return its index. If no item satisfies the predicate, return None.
find_or_else
Find the first item in a collection that satisfies a predicate. If no item satisfies the predicate, return the fallback value.
find_uniques
Find all unique elements in a collection (elements that appear exactly once).
find_uniques_by
Find all unique elements in a collection based on a key generated by the iteratee function. Returns elements whose generated keys appear exactly once.
first
Returns the first item from the collection. If the collection is empty, returns the default value of T and false.
first_or
Returns the first item from the collection. If the collection is empty, returns the provided fallback value.
first_or_empty
Returns the first item from the collection. If the collection is empty, returns the default value of T.
flat_map
Apply a function to each item in a collection, flattening the results based on a callback.
flatten
Flatten a collection of slices into a single vector, preserving the order of elements.
foreach
Execute a function on each item in a collection.
foreach_while
Execute a function on each item in a collection until the iteratee returns false.
from_entries
Constructs a HashMap from a slice of Entry structs.
from_pairs
Constructs a HashMap from a slice of Entry structs.
group_by
Group elements of a collection based on a key extracted by a provided function, preserving the order of their first occurrence.
has_key
Checks if a map contains a specific key.
index_of
Finds the position of the first occurrence of an element in a collection. Returns -1 if the element is not found.
interleave
Interleave multiple collections into a single vector, preserving the order of elements.
interpolate
Performs linear interpolation between two values.
invert
Constructs a HashMap by inverting the keys and values of the input map.
is_sorted
Determines if a collection is sorted in ascending order.
is_sorted_by_key
Determines if a collection is sorted in ascending order based on a specified key.
kebab_case
Converts a string to kebab-case.
key_by
Creates a HashMap by mapping each element in a collection to a key using an iteratee function. If multiple elements map to the same key, the last occurrence will overwrite previous ones.
keys
Collects all keys from one or more maps into a single vector.
last
Returns the last item from the collection. If the collection is empty, returns the default value of T and false.
last_index_of
Finds the position of the last occurrence of an element in a collection. Returns -1 if the element is not found.
last_or
Returns the last item from the collection. If the collection is empty, returns the provided fallback value.
last_or_empty
Returns the last item from the collection. If the collection is empty, returns the default value of T.
latest
Returns the latest SystemTime from the provided arguments. If no arguments are provided, returns SystemTime::UNIX_EPOCH.
latest_by
Returns the item from the collection for which the iteratee returns the latest SystemTime. If the collection is empty, returns the default value of T.
map
Apply a function to each item in a collection, producing a new collection of results.
map_entries
Transforms the entries of a map using a provided function.
map_keys
Transforms the keys of a map using a provided function.
map_to_slice
Transforms the entries of a map into a slice using a provided function.
map_values
Transforms the values of a map using a provided function.
max
Find the maximum element in a collection. If the collection is empty, returns None.
max_by
Find the maximum element in a collection based on a custom comparison function. If the collection is empty, returns None.
mean
Calculates the arithmetic mean of a collection of numbers. If the collection is empty, returns zero.
mean_by
Calculates the mean value of a collection after applying a transformation function to each element.
median
Calculate the median value of a collection. The median is the 50th percentile of a collection. For collections with an even number of elements, the median is the average of the two middle values. The collection will be sorted before calculation.
min
Find the minimum element in a collection. If the collection is empty, returns None.
min_by
Find the minimum element in a collection based on a custom comparison function. If the collection is empty, returns None.
nearest_power_of_two
Calculates the smallest power of two greater than or equal to the given capacity.
nth
Returns the nth element from the collection. Supports both positive and negative indices. Negative indices count from the end of the collection.
omit_by
Filters a map by omitting key-value pairs that satisfy a predicate.
omit_by_keys
Filters a map by omitting specified keys.
omit_by_values
partition_by
Divide a collection into partitions based on a key extracted by a provided function, preserving the order of elements and the order of partitions as they first appear.
pascal_case
Converts a string to PascalCase.
percentile
Calculates the specified percentile of a collection. The percentile should be a value between 0 and 100. The collection will be sorted before calculation. Uses linear interpolation between closest ranks for non-integer results.
permutation
Finds all permutations of k elements from a collection.
pick_by
Filters a map by applying a predicate to its key-value pairs.
pick_by_keys
Filters a map by selecting only the specified keys.
pick_by_values
Filters a map by selecting only the specified values.
product
Calculate the product of all elements in a collection. If the collection is empty, returns 1 (multiplicative identity). Works with any numeric type that implements std::ops::Mul and can be copied.
product_by
Calculate the product of values obtained by applying a function to each element in a collection. If the collection is empty, returns 1 (multiplicative identity). Works with any numeric type that implements std::ops::Mul and can be copied.
random_string
Generates a random string of a specified size using the provided charset.
range
Generate a range of integers from 0 to element_num (exclusive). If element_num is negative, generate a range from 0 to -element_num (exclusive) with a step of -1.
range_from
Generate a range of numbers starting from a given value. If element_num is negative, generate a range with a step of -1.
range_with_steps
Generate a range of numbers from start to end (exclusive) with a specified step.
reduce
Apply a function to each item in a collection, accumulating a single result.
reduce_right
Apply a function to each item in a collection, accumulating a single result from right to left.
reject
Reject items from a collection that satisfy a predicate.
reject_map
Applies a callback function to each item in a collection along with its index and collects the results where the callback returns false.
repeat
Fill a collection with a specified value, returning a new vector with all elements set to the initial value.
repeat_by
Repeat a specified value count times by applying a predicate function to each index, returning a new vector with the generated elements.
replace
Replaces occurrences of a specified value in a collection with a new value, up to a maximum number of replacements.
replace_all
Replaces all occurrences of a specified value in a collection with a new value.
reverse
Reverse a collection, returning a new vector with the elements in reverse order.
sample
Returns a pseudo-random element from the collection. If the collection is empty, returns the default value of T.
samples
Returns a slice of pseudo-randomly selected elements from the collection. The elements are selected without replacement (no duplicates).
shuffle
Shuffle a collection, returning a new vector with the elements in random order.
slice
Returns a subset of the collection based on the provided start and end indices.
slice_to_map
Transforms a slice of items into a HashMap by applying a provided function to each item.
snake_case
Converts a string to snake_case.
splice
Inserts elements into a collection at a specified index, handling negative indices and overflow. Returns a new Vec<T> with the elements inserted.
subset
Returns a subset of the collection based on the provided offset and length.
substring
Extracts a substring from the given string based on the specified offset and length.
sum
Calculates the sum of all elements in a collection. Works with any numeric type that implements std::ops::Add and can be copied.
sum_by
Calculates the sum of values obtained by applying a function to each element in a collection.
times
Generates a collection by invoking the provided function iteratee a specified number of times.
to_pairs
Collects all entries from a map into a vector of Entry structs.
uniq
Remove duplicate elements from a collection, preserving the order of their first occurrence.
uniq_by
Remove duplicate elements from a collection based on a key extracted by a provided function, preserving the order of their first occurrence.
uniq_keys
Collects all unique keys from one or more maps into a single vector.
uniq_values
Collects all unique values from one or more maps into a single vector.
value_or
Returns a value from a map for a given key, or a fallback value if the key doesn’t exist.
values
Collects all values from one or more maps into a single vector.
words
Splits a string into words based on casing, digits, and separators.