### Install Python dependencies Source: https://pydash.readthedocs.io/en/latest/contributing.html Navigate to the pydash directory and install the necessary Python dependencies using pip and a requirements file. ```bash $ cd pydash $ pip install -r requirements.txt ``` -------------------------------- ### Ensure String Starts With Prefix Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/strings.html Prepends a prefix to a string only if it does not already start with that prefix. Ensures consistent string beginnings. ```python >>> ensure_starts_with("foo bar", "Oh my! ") 'Oh my! foo bar' >>> ensure_starts_with("Oh my! foo bar", "Oh my! ") 'Oh my! foo bar' ``` -------------------------------- ### ensure_starts_with Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/strings.html Prepends a prefix to a string if it does not already start with it. ```APIDOC ## ensure_starts_with ### Description Prepend a given prefix to a string, but only if the source string does not start with that prefix. ### Parameters #### Path Parameters - **text** (any) - Required - Source string to prepend `prefix` to. - **prefix** (any) - Required - String to prepend to the source string if the source string does not start with `prefix`. ### Returns - **string** - Source string possibly prefixed by `prefix`. ### Example ```python ensure_starts_with("foo bar", "Oh my! ") # => 'Oh my! foo bar' ensure_starts_with("Oh my! foo bar", "Oh my! ") # => 'Oh my! foo bar' ``` ``` -------------------------------- ### Install pydash using pip Source: https://pydash.readthedocs.io/en/latest/_sources/installation.rst.txt Install pydash from PyPi using pip. This package has no external dependencies and requires Python 3.6 or higher. ```bash pip install pydash ``` -------------------------------- ### Chaining Example Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/chaining/chaining.html Demonstrates how to use method chaining with Pydash functions. ```APIDOC ## Chaining Example ### Description Illustrates the usage of Pydash's method chaining capabilities. ### Usage ```python import pydash as pyd # Example using chain result = pyd.chain([1, 2, 3]) \ .map(lambda x: x * 2) \ .value() # result is [2, 4, 6] # Example using tap to perform a side effect output = [] result_with_tap = pyd.chain([1, 2, 3]) \ .tap(lambda x: output.append(x)) \ .value() # result_with_tap is [1, 2, 3] # output is [[1, 2, 3]] ``` ``` -------------------------------- ### Check if String Starts With - Python Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/strings.html Use `starts_with` to check if a string begins with a specified target. You can also provide a position to start the check from. ```python >>> starts_with("abcdef", "a") True >>> starts_with("abcdef", "b") False >>> starts_with("abcdef", "a", 1) False ``` -------------------------------- ### pydash.strings.start_case Source: https://pydash.readthedocs.io/en/latest/api.html Converts a given string into start case. ```APIDOC ## pydash.strings.start_case ### Description Convert text to start case. ### Parameters #### Path Parameters - **text** (Any) - Required - String to convert. ### Response #### Success Response (str) String converted to start case. ### Request Example ```python >>> start_case("fooBar") 'Foo Bar' ``` ``` -------------------------------- ### starts_with Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/strings.html Checks if a string starts with a given target string at a specified position. ```APIDOC ## starts_with ### Description Checks if `text` starts with a given target string. ### Parameters - **text** (Any) - String to check. - **target** (Any) - String to check for. - **position** (int, optional) - Position to search from. Defaults to beginning of `text`. ### Returns - bool - Whether `text` starts with `target`. ### Example ```python starts_with("abcdef", "a") # => True starts_with("abcdef", "b") # => False starts_with("abcdef", "a", 1) # => False ``` ``` -------------------------------- ### start_case Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/strings.html Converts a given string into start case (e.g., "Foo Bar"). ```APIDOC ## start_case ### Description Convert `text` to start case. ### Parameters - **text** (Any) - String to convert. ### Returns String converted to start case. ### Example ```python start_case("fooBar") # 'Foo Bar' ``` ``` -------------------------------- ### Initialize a pydash chain Source: https://pydash.readthedocs.io/en/latest/_sources/chaining.rst.txt Start a method chain using either the `py_()` wrapper or the `chain()` function. Ensure `pydash` is imported. ```python from pydash import py_ py_([1, 2, 3, 4]) ``` ```python import pydash pydash.chain([1, 2, 3, 4]) ``` -------------------------------- ### Convert to Start Case Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/strings.html Converts a given string into Start Case (e.g., 'Foo Bar'). It capitalizes the first letter of each word identified by `compounder`. ```python >>> start_case("fooBar") 'Foo Bar' ``` -------------------------------- ### replace_start Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/strings.html Replaces text with a replacement only if the pattern matches the start of the string. ```APIDOC ## replace_start ### Description Replaces text with a replacement only if the pattern matches the start of the string. ### Method `replace_start(text, pattern, repl, ignore_case=False, escape=True)` ### Parameters #### Path Parameters - **text** (any) - String to replace. - **pattern** (any) - Pattern to find and replace. - **repl** (str | Callable[[re.Match[str]], str]) - String to substitute `pattern` with. - **ignore_case** (bool) - Whether to ignore case when replacing. Defaults to `False`. - **escape** (bool) - Whether to escape `pattern` when searching. Defaults to `True`. ### Response Replaced string. ### Example >>> replace_start("aabbcc", "b", "X") 'aabbcc' >>> replace_start("aabbcc", "a", "X") 'Xabbcc' ``` -------------------------------- ### Chain Class Initialization Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/chaining/chaining.html Initializes a `Chain` object with an optional starting value. This class enables method chaining for pydash functions. ```python chain = pyd.chain(1) ``` -------------------------------- ### Serve documentation locally Source: https://pydash.readthedocs.io/en/latest/devguide.html Build and serve the project's documentation over HTTP for local preview. Options allow specifying the bind address and port. ```bash inv docs -s|--server [-b|--bind 127.0.0.1] [-p|--port 8000] ``` ```bash inv docs -s ``` ```bash inv docs -s -p 8080 ``` ```bash inv docs -s -b 0.0.0.0 -p 8080 ``` -------------------------------- ### pydash.arrays.index_of Source: https://pydash.readthedocs.io/en/latest/api.html Gets the index at which the first occurrence of a value is found in an array. Searching can start from a specified index. This function was added in version 1.0.0. ```APIDOC ## pydash.arrays.index_of ### Description Gets the index at which the first occurrence of value is found. ### Parameters * **array** (Sequence[T]) - List to search. * **value** (T) - Value to search for. * **from_index** (int) - Index to search from. Defaults to `0`. ### Returns int - Index of found item or `-1` if not found. ### Example ```python >>> index_of([1, 2, 3, 4], 2) 1 >>> index_of([2, 1, 2, 3], 2, from_index=1) 2 ``` ``` -------------------------------- ### Build documentation Source: https://pydash.readthedocs.io/en/latest/devguide.html Generate the project's documentation. The output will be located in the 'docs/_build/' directory. ```bash inv docs ``` -------------------------------- ### Find Index of Value in Array Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/arrays.html Gets the index at which the first occurrence of a specified value is found in an array. Searching can start from a specified index. ```python >>> index_of([1, 2, 3, 4], 2) 1 >>> index_of([2, 1, 2, 3], 2, from_index=1) 2 ``` -------------------------------- ### Importing and Using pydash Functions Source: https://pydash.readthedocs.io/en/latest/_sources/api.rst.txt Demonstrates the recommended ways to import and use functions from the pydash library. ```APIDOC ## Importing pydash ### Description This section shows the recommended import methods for using pydash functions. ### Code Examples **Recommended: Import main module** ```python import pydash pydash.filter_({}) ``` **Recommended: Import specific functions from main module** ```python from pydash import filter_ filter_({}) ``` **Not Recommended: Import from submodule** ```python from pydash.collections import filter_ ``` ``` -------------------------------- ### pydash.predicates.in_range Source: https://pydash.readthedocs.io/en/latest/api.html Checks if value is between start and up to but not including end. If end is not specified it defaults to start with start becoming 0. ```APIDOC ## pydash.predicates.in_range ### Description Checks if value is between start and up to but not including end. If end is not specified it defaults to start with start becoming `0`. ### Parameters #### Path Parameters - **value** (Any_) - Number to check. - **start** (Any_) - Start of range inclusive. Defaults to `0`. - **end** (Any_) - End of range exclusive. Defaults to start. ### Response #### Success Response (bool) Whether value is in range. ### Request Example ```python >>> in_range(2, 4) True >>> in_range(4, 2) False >>> in_range(2, 1, 3) True >>> in_range(3, 1, 2) False >>> in_range(2.5, 3.5) True >>> in_range(3.5, 2.5) False ``` ``` -------------------------------- ### Build package distributions Source: https://pydash.readthedocs.io/en/latest/devguide.html Create source and binary distributions of the package. The output files will be placed in the 'dist/' directory. ```bash inv build ``` -------------------------------- ### in_range(value, start=0, end=None) Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/predicates.html Checks if `value` is between `start` and up to but not including `end`. If `end` is not specified it defaults to `start` with `start` becoming ``0``. ```APIDOC ## in_range(value, start=0, end=None) ### Description Checks if `value` is between `start` and up to but not including `end`. If `end` is not specified it defaults to `start` with `start` becoming ``0``. ### Parameters #### Path Parameters - **value** (any) - Number to check. - **start** (any) - Start of range inclusive. Defaults to ``0``. - **end** (any) - End of range exclusive. Defaults to `start`. ### Request Example ```python in_range(2, 4) in_range(4, 2) in_range(2, 1, 3) in_range(3, 1, 2) in_range(2.5, 3.5) in_range(3.5, 2.5) ``` ### Response #### Success Response (200) - **return** (bool) - Whether `value` is in range. ### Response Example ```json { "example": "True" } ``` ```json { "example": "False" } ``` ```json { "example": "True" } ``` ```json { "example": "False" } ``` ```json { "example": "True" } ``` ```json { "example": "False" } ``` ``` -------------------------------- ### Pydash is_match_with Example Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/predicates.html Checks if an object matches a source object using a customizer function for comparisons. Useful for deep comparisons with specific matching logic. ```python >>> is_greeting = lambda val: val in ("hello", "hi") >>> customizer = lambda ov, sv: is_greeting(ov) and is_greeting(sv) >>> obj = {"greeting": "hello"} >>> src = {"greeting": "hi"} >>> is_match_with(obj, src, customizer) True ``` -------------------------------- ### Slice Array by Start and End Indices Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/arrays.html Slices an array from a start index up to, but not including, an end index. If end is None, it defaults to selecting the element at the start index. ```python >>> slice_([1, 2, 3, 4]) [1] >>> slice_([1, 2, 3, 4], 1) [2] >>> slice_([1, 2, 3, 4], 1, 3) [2, 3] ``` -------------------------------- ### Using the py_ Instance Source: https://pydash.readthedocs.io/en/latest/_sources/api.rst.txt Explains how to use the special `py_` instance for method calling and chaining. ```APIDOC ## py_ Instance ### Description The `py_` instance provides a convenient way to call pydash functions and chain them together. ### Method Calling ```python from pydash import py_ py_.initial([1, 2, 3, 4, 5]) == [1, 2, 3, 4] ``` ### Method Chaining ```python from pydash import py_ py_([1, 2, 3, 4, 5]).initial().value() == [1, 2, 3, 4] ``` ### Method Aliasing `py_` methods often alias underscore-suffixed functions, especially those shadowing built-in names. ```python from pydash import py_ py_.map is py_.map_ py_([1, 2, 3]).map(_.to_string).value() == py_([1, 2, 3]).map_(_.to_string).value() ``` ### Aliased Methods The following `py_` methods are available: - ``_.slice`` is :func:`pydash.arrays.slice_` - ``_.zip`` is :func:`pydash.arrays.zip_` - ``_.all`` is :func:`pydash.collections.all_` - ``_.any`` is :func:`pydash.collections.any_` - ``_.filter`` is :func:`pydash.collections.filter_` - ``_.map`` is :func:`pydash.collections.map_` - ``_.max`` is :func:`pydash.collections.max_` - ``_.min`` is :func:`pydash.collections.min_` - ``_.reduce`` is :func:`pydash.collections.reduce_` - ``_.pow`` is :func:`pydash.numerical.pow_` - ``_.round`` is :func:`pydash.numerical.round_` - ``_.sum`` is :func:`pydash.numerical.sum_` - ``_.property`` is :func:`pydash.utilities.property_` - ``_.range`` is :func:`pydash.utilities.range_` ``` -------------------------------- ### get Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/objects.html Get the value at any depth of a nested object based on the path described by `path`. If path doesn't exist, `default` is returned. ```APIDOC ## get ### Description Get the value at any depth of a nested object based on the path described by `path`. If path doesn't exist, `default` is returned. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **obj** (Object to process) - **path** (List or ``.`` delimited string of path describing path) - **default** (Default value to return if path doesn't exist. Defaults to ``None``) ### Returns Value of `obj` at path. ### Example: ```python get({}, "a.b.c") is None # => True ``` ``` -------------------------------- ### Importing pydash Functions Source: https://pydash.readthedocs.io/en/latest/_sources/api.rst.txt Demonstrates the recommended way to import and use pydash functions by importing the main module. Avoid importing directly from submodules as their API is not guaranteed to be stable. ```python import pydash pydash. ``` ```python # OK (importing main module) import pydash pydash.filter_({}) # OK (import from main module) from pydash import filter_ filter_({}) # NOT RECOMMENDED (importing from submodule) from pydash.collections import filter_ ``` -------------------------------- ### Late Value Chaining Example Source: https://pydash.readthedocs.io/en/latest/_sources/upgrading.rst.txt Demonstrates how to build reusable chains without an initial value, allowing them to be applied to different root values later. This is useful for creating chain templates. ```python >>> from pydash import py_ >>> square_sum = py_().power(2).sum() >>> [square_sum([1, 2, 3]), square_sum([4, 5, 6]), square_sum([7, 8, 9])] [14, 77, 194] ``` -------------------------------- ### Replace Substring at Start of String Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/strings.html Replaces a pattern with a replacement only if the pattern matches the start of the string. Supports case-insensitive matching and escaping of the pattern. ```python >>> replace_start("aabbcc", "b", "X") 'aabbcc' ``` ```python >>> replace_start("aabbcc", "a", "X") 'Xabbcc' ``` -------------------------------- ### pydash.arrays.splice Source: https://pydash.readthedocs.io/en/latest/api.html Modify the contents of array by inserting elements starting at index start and removing count number of elements after. The array is modified in place if it is a list. ```APIDOC ## pydash.arrays.splice ### Description Modify the contents of array by inserting elements starting at index start and removing count number of elements after. ### Parameters #### Path Parameters - **array** (MutableSequenceT) - List to splice. - **start** (int) - Start to splice at. - **count** (int | None) - Number of items to remove starting at start. If `None` then all items after start are removed. Defaults to `None`. - **items** (Any) - Elements to insert starting at start. Each item is inserted in the order given. ### Response #### Success Response (MutableSequenceT) - Returns the removed elements of array or the spliced string. ### Request Example ```python >>> array = [1, 2, 3, 4] >>> splice(array, 1) [2, 3, 4] >>> array [1] >>> array = [1, 2, 3, 4] >>> splice(array, 1, 2) [2, 3] >>> array [1, 4] >>> array = [1, 2, 3, 4] >>> splice(array, 1, 2, 0, 0) [2, 3] >>> array [1, 0, 0, 4] ``` ``` -------------------------------- ### Run all autoformatters Source: https://pydash.readthedocs.io/en/latest/devguide.html Execute all code autoformatting tools for the project. This is a convenient shortcut for running individual formatters. ```bash inv fmt ``` -------------------------------- ### Run unit tests and builds Source: https://pydash.readthedocs.io/en/latest/devguide.html Execute unit tests and build processes. This command ensures tests pass and that the package can be built. ```bash inv test ``` -------------------------------- ### pydash.utilities.range_ Source: https://pydash.readthedocs.io/en/latest/api.html Creates a list of numbers (positive and/or negative) progressing from start up to but not including end. If start is less than stop, a zero-length range is created unless a negative step is specified. ```APIDOC ## pydash.utilities.range_ ### Description Creates a list of numbers (positive and/or negative) progressing from start up to but not including end. If start is less than stop, a zero-length range is created unless a negative step is specified. ### Parameters #### Path Parameters - **stop** (int) - Required - Integer to stop at. - **start** (int) - Optional - Integer to start with. Defaults to `0`. - **step** (int) - Optional - The value to increment or decrement by. Defaults to `1`. ### Yields - **int** - Next integer in range. ### Example ```python >>> list(range_(5)) [0, 1, 2, 3, 4] >>> list(range_(1, 4)) [1, 2, 3] >>> list(range_(0, 6, 2)) [0, 2, 4] >>> list(range_(4, 1)) [4, 3, 2] ``` ``` -------------------------------- ### Run all unit tests Source: https://pydash.readthedocs.io/en/latest/devguide.html Execute all unit tests for the project. This is the primary command for verifying code correctness. ```bash inv unit ``` -------------------------------- ### Create a number range generator Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/utilities.html Generates a sequence of numbers from `start` up to, but not including, `stop`. Supports custom `step` values and descending order if `start` is greater than `stop` with a negative step. ```python >>> list(range_(5)) [0, 1, 2, 3, 4] >>> list(range_(1, 4)) [1, 2, 3] >>> list(range_(0, 6, 2)) [0, 2, 4] >>> list(range_(4, 1)) [4, 3, 2] ``` -------------------------------- ### Using the py_ Instance for Method Calling and Chaining Source: https://pydash.readthedocs.io/en/latest/_sources/api.rst.txt Illustrates how to use the `py_` instance for direct method calls and method chaining. The `py_` instance supports aliasing methods to underscore-suffixed names, which can shadow built-in names. ```python from pydash import py_ # Method calling py_.initial([1, 2, 3, 4, 5]) == [1, 2, 3, 4] # Method chaining py_([1, 2, 3, 4, 5]).initial().value() == [1, 2, 3, 4] # Method aliasing to underscore suffixed methods that shadow builtin names py_.map is py_.map_ py_([1, 2, 3]).map(_.to_string).value() == py_([1, 2, 3]).map_(_.to_string).value() ``` -------------------------------- ### pydash.utilities.random Source: https://pydash.readthedocs.io/en/latest/api.html Produces a random number between start and stop (inclusive). If only one argument is provided a number between 0 and the given number will be returned. If floating is truthy or either start or stop are floats a floating-point number will be returned instead of an integer. ```APIDOC ## pydash.utilities.random ### Description Produces a random number between start and stop (inclusive). If only one argument is provided a number between 0 and the given number will be returned. If floating is truthy or either start or stop are floats a floating-point number will be returned instead of an integer. ### Parameters #### Path Parameters - **start** (int | float) - Optional - Minimum value. - **stop** (int | float) - Optional - Maximum value. - **floating** (Literal[False] | bool) - Optional - Whether to force random value to `float`. Defaults to `False`. ### Returns - **int | float** - Random value. ### Example ```python >>> 0 <= random() <= 1 True >>> 5 <= random(5, 10) <= 10 True >>> isinstance(random(floating=True), float) True ``` ``` -------------------------------- ### Run individual autoformatters Source: https://pydash.readthedocs.io/en/latest/devguide.html Execute specific code autoformatting tools. Use these commands if you only need to format specific aspects of the code. ```bash inv black ``` ```bash inv isort ``` ```bash inv docformatter ``` -------------------------------- ### take Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/arrays.html Creates a new array containing the first 'n' elements from the beginning of the input array. If 'n' is not specified, it defaults to taking a single element. ```APIDOC ## take ### Description Creates a slice of `array` with `n` elements taken from the beginning. ### Method `take(array: t.Sequence[T], n: int = 1) -> t.Sequence[T]` ### Parameters #### Path Parameters - **array** (Sequence[T]) - List to process. - **n** (int) - Number of elements to take. Defaults to ``1``. ### Returns Taken list. ### Example >>> take([1, 2, 3, 4], 2) [1, 2] .. versionadded:: 1.0.0 .. versionchanged:: 1.1.0 Added ``n`` argument and removed as alias of :func:`first`. .. versionchanged:: 3.0.0 Made ``n`` default to ``1``. ``` -------------------------------- ### pydash.arrays.nth Source: https://pydash.readthedocs.io/en/latest/api.html Gets the element at index n of array. ```APIDOC ## pydash.arrays.nth ### Description Gets the element at index n of array. ### Parameters #### Path Parameters - **array** (iterable) - List passed in by the user. - **pos** (int) - Index of element to return. ### Returns Returns the element at `pos`. ### Example ```python >>> nth([1, 2, 3], 0) 1 >>> nth([3, 4, 5, 6], 2) 5 >>> nth([11, 22, 33], -1) 33 >>> nth([11, 22, 33]) 11 ``` ``` -------------------------------- ### Safely Get Nested Object Values Source: https://pydash.readthedocs.io/en/latest/api.html Use get to retrieve values from nested objects using a path. If the path does not exist, a default value (None by default) is returned. Supports dot-delimited strings or lists for paths, and array index access. ```python >>> get({}, "a.b.c") is None True >>> get({"a": {"b": {"c": [1, 2, 3, 4]}}}, "a.b.c[1]") 2 >>> get({"a": {"b": {"c": [1, 2, 3, 4]}}}, "a.b.c.1") 2 >>> get({"a": {"b": [0, {"c": [1, 2]}]}}, "a.b.1.c.1") 2 >>> get({"a": {"b": [0, {"c": [1, 2]}]}}, ["a", "b", 1, "c", 1]) 2 >>> get({"a": {"b": [0, {"c": [1, 2]}]}}, "a.b.1.c.2") is None True ``` -------------------------------- ### random Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/utilities.html Produces a random number between `start` and `stop` (inclusive). ```APIDOC ## random(start: t.Union[float, int] = 0, stop: t.Union[float, int] = 1, floating: bool = False) ### Description Produces a random number between `start` and `stop` (inclusive). If only one argument is provided a number between 0 and the given number will be returned. If floating is truthy or either `start` or `stop` are floats a floating-point number will be returned instead of an integer. ### Args start: Minimum value. stop: Maximum value. floating: Whether to force random value to ``float``. Defaults to ``False``. ### Returns Random value. ### Example >>> 0 <= random() <= 1 True >>> 5 <= random(5, 10) <= 10 True >>> isinstance(random(floating=True), float) True ``` -------------------------------- ### pydash.arrays.last_index_of Source: https://pydash.readthedocs.io/en/latest/api.html Gets the index at which the last occurrence of value is found. ```APIDOC ## pydash.arrays.last_index_of ### Description Gets the index at which the last occurrence of value is found. ### Parameters #### Path Parameters - **array** (sequence) - List to search. - **value** (any) - Value to search for. - **from_index** (int) - Index to search from. ### Returns Index of found item or `-1` if not found. ### Example ```python >>> last_index_of([1, 2, 2, 4], 2) 2 >>> last_index_of([1, 2, 2, 4], 2, from_index=1) 1 ``` ``` -------------------------------- ### sample Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/collections.html The `sample` function retrieves a single random element from a given collection. ```APIDOC ## sample(collection) ### Description Retrieves a random element from a given collection. ### Parameters #### collection Collection to iterate over. ### Returns Random element from the given collection. ### Example ```python >>> items = [1, 2, 3, 4, 5] >>> results = sample(items) >>> assert results in items ``` ``` -------------------------------- ### Chain Class Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/chaining/chaining.html The `Chain` class is the entry point for method chaining. It initializes with a value and allows subsequent methods to be chained onto it. ```APIDOC ## Chain Class ### Description Initializes a chain with a given value. ### Methods - `__init__(self, value)`: Initializes the chain with a value. - `value(self)`: Returns the current value of the chain operations. - `to_string(self)`: Returns the current value cast to a string. - `commit(self)`: Executes the chained sequence and returns the wrapped result. - `plant(self, value)`: Returns a clone of the chained sequence planting a new value. - `__call__(self, value)`: Returns the result of passing a value through the chained methods. ``` -------------------------------- ### nth Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/arrays.html Gets the element at a specific index (position) in an array. ```APIDOC ## nth ### Description Gets the element at index n of array. ### Arguments * `array` (Iterable[T]): List passed in by the user. * `pos` (int): Index of element to return. Defaults to 0. ### Returns * `Union[T, None]`: Returns the element at :attr:`pos`. ### Example ```python nth([1, 2, 3], 0) # => 1 nth([3, 4, 5, 6], 2) # => 5 nth([11, 22, 33], -1) # => 33 nth([11, 22, 33]) # => 11 ``` ``` -------------------------------- ### chop_right Source: https://pydash.readthedocs.io/en/latest/api.html Similar to `chop`, but breaks the string into substrings starting from the right. ```APIDOC ## chop_right ### Description Like `chop()` except text is chopped from right. ### Parameters - **text** (Any) - String to chop. - **step** (int) - Interval to chop text. ### Returns - List[str] - List of chopped characters. ### Example ```python >>> chop_right("abcdefg", 3) ['a', 'bcd', 'efg'] ``` ``` -------------------------------- ### Partial Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/functions.html Wraps a function to create a new function with some arguments pre-filled. Arguments can be applied from the left or right. ```APIDOC ## Partial ### Description Wraps a function in a partial context. ### Class `Partial` ### Methods #### `__init__(self, func: t.Callable[..., T], args: t.Any, kwargs: t.Any = None, from_right: bool = False) -> None` Initializes the Partial wrapper with the function, pre-filled arguments, and an option to apply arguments from the right. #### `__call__(self, *args: t.Any, **kwargs: t.Any) -> T` Returns results from the wrapped function `func` with pre-filled arguments combined with new arguments. Arguments are applied from left or right based on `from_right`. ``` -------------------------------- ### set_with Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/objects.html This method is like :func:`set_` except that it accepts customizer which is invoked to produce the objects of path. If customizer returns undefined path creation is handled by the method instead. The customizer is invoked with three arguments: ``(nested_value, key, nested_object)``. ```APIDOC ## set_with ### Description This method is like :func:`set_` except that it accepts customizer which is invoked to produce the objects of path. If customizer returns undefined path creation is handled by the method instead. The customizer is invoked with three arguments: ``(nested_value, key, nested_object)``. ### Parameters #### Arguments * **obj** (Any) - Object to modify. * **path** (PathT) - Target path to set value to. * **value** (Any) - Value to set. * **customizer** (Callable | None) - The function to customize assigned values. ### Returns * Modified `obj`. ### Warning * `obj` is modified in place. ### Example ```python set_with({}, "[0][1]", "a", lambda: {{}}) {0: {1: 'a'}} ``` ``` -------------------------------- ### slice_ Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/arrays.html Slices an array from a start index up to, but not including, an end index. ```APIDOC ## slice_ ### Description Slices `array` from the `start` index up to, but not including, the `end` index. ### Parameters #### Path Parameters - **array** (Sequence) - Array to slice. - **start** (int) - Start index. Defaults to `0`. - **end** (Union[int, None]) - End index. Defaults to selecting the value at `start` index. ### Returns (Sequence) - Sliced list. ### Example ```python slice_([1, 2, 3, 4]) # Returns [1] slice_([1, 2, 3, 4], 1) # Returns [2] slice_([1, 2, 3, 4], 1, 3) # Returns [2, 3] ``` ``` -------------------------------- ### Partial Application with pydash.functions.partial Source: https://pydash.readthedocs.io/en/latest/api.html Use partial to create a new function with some arguments pre-filled. Supports both positional and keyword arguments. ```python >>> dropper = partial(lambda array, n: array[n:], [1, 2, 3, 4]) >>> dropper(2) [3, 4] >>> dropper(1) [2, 3, 4] >>> myrest = partial(lambda array, n: array[n:], n=1) >>> myrest([1, 2, 3, 4]) [2, 3, 4] ``` -------------------------------- ### range_ Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/utilities.html Creates a generator of numbers progressing from start up to but not including end. ```APIDOC ## range_(*args) ### Description Creates a list of numbers (positive and/or negative) progressing from start up to but not including end. If `start` is less than `stop`, a zero-length range is created unless a negative `step` is specified. ### Args start: Integer to start with. Defaults to ``0``. stop: Integer to stop at. step: The value to increment or decrement by. Defaults to ``1``. ### Yields Next integer in range. ### Example >>> list(range_(5)) [0, 1, 2, 3, 4] >>> list(range_(1, 4)) [1, 2, 3] >>> list(range_(0, 6, 2)) [0, 2, 4] >>> list(range_(4, 1)) [4, 3, 2] ``` -------------------------------- ### Direct Function Call Source: https://pydash.readthedocs.io/en/latest/api.html This demonstrates the recommended way to use pydash functions by importing the main module and calling functions directly. ```APIDOC ## Direct Function Call ### Description This shows how to import the main pydash module and call functions directly. ### Method ```python import pydash pydash. ``` ### Example ```python import pydash pydash.filter_({}) ``` ``` -------------------------------- ### Test on all supported Python versions Source: https://pydash.readthedocs.io/en/latest/devguide.html Run tests across all Python versions supported by the project. This requires the specified Python versions to be available on the system's PATH. ```bash tox ``` -------------------------------- ### Get Last Element of Array Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/arrays.html Retrieves the last element from a given array. ```python >>> last([1, 2, 3, 4]) 4 ``` -------------------------------- ### pydash.strings.starts_with Source: https://pydash.readthedocs.io/en/latest/api.html Checks if a string begins with a specified target string at a given position. ```APIDOC ## pydash.strings.starts_with ### Description Checks if text starts with a given target string. ### Parameters #### Path Parameters - **text** (Any) - Required - String to check. - **target** (Any) - Required - String to check for. - **position** (int) - Optional - Position to search from. Defaults to beginning of text. ### Response #### Success Response (bool) Whether text starts with target. ### Request Example ```python >>> starts_with("abcdef", "a") True >>> starts_with("abcdef", "b") False >>> starts_with("abcdef", "a", 1) False ``` ``` -------------------------------- ### Get Values from Object or Iterable Source: https://pydash.readthedocs.io/en/latest/api.html Creates a list composed of the values of an object or iterable. ```python pydash.objects.values(_obj : Mapping[Any, T2]_) → List[T2] ``` ```python pydash.objects.values(_obj : Iterable[T]_) → List[T] ``` ```python pydash.objects.values(_obj : Any_) → List[Any] ``` -------------------------------- ### Pydash is_number Example Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/predicates.html Checks if a value is a number. This includes integers and floating-point numbers. ```python >>> is_number(1) True >>> is_number(1.0) True >>> is_number('a') False ``` -------------------------------- ### clone_with Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/objects.html This method is like :func:`clone` except that it accepts customizer which is invoked to produce the cloned value. The customizer is invoked with up to three arguments: ``(value, index|key, object)``. ```APIDOC ## clone_with ### Description This method is like :func:`clone` except that it accepts customizer which is invoked to produce the cloned value. If customizer returns ``None``, cloning is handled by the method instead. The customizer is invoked with up to three arguments: ``(value, index|key, object)``. ### Args - **value** (Any): Object to clone. - **customizer** (Callable): Function to customize cloning. ### Returns - (Any): Cloned object. ### Example ```python x = {"a": 1, "b": 2, "c": {"d": 3}} cbk = lambda v, k: v + 2 if isinstance(v, int) and k else None y = clone_with(x, cbk) y == {"a": 3, "b": 4, "c": {"d": 3}} # => True ``` ``` -------------------------------- ### Importing Specific Functions Source: https://pydash.readthedocs.io/en/latest/api.html This shows how to import specific functions from the main pydash module for direct use. ```APIDOC ## Importing Specific Functions ### Description This demonstrates importing a specific function from the main pydash module. ### Method ```python from pydash import (...) ``` ### Example ```python from pydash import filter_ filter_({}) ``` ``` -------------------------------- ### fill Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/arrays.html Fills elements of array with value from `start` up to, but not including, `end`. The `array` is modified in place. ```APIDOC ## fill ### Description Fills elements of array with value from `start` up to, but not including, `end`. ### Parameters - **array** (Sequence) - List to fill. - **value** (Any) - Value to fill with. - **start** (int, optional) - Index to start filling. Defaults to ``0``. - **end** (int or None, optional) - Index to end filling. Defaults to ``len(array)``. ### Returns - **List** - Filled `array`. ### Example ```python >>> fill([1, 2, 3, 4, 5], 0) [0, 0, 0, 0, 0] >>> fill([1, 2, 3, 4, 5], 0, 1, 3) [1, 0, 0, 4, 5] >>> fill([1, 2, 3, 4, 5], 0, 0, 100) [0, 0, 0, 0, 0] ``` ### Warning `array` is modified in place. ``` -------------------------------- ### Provide Default Values with default_to_any Source: https://pydash.readthedocs.io/en/latest/api.html Returns the first argument if it's not None, otherwise returns the first not None value from the subsequent default values. Useful for setting fallback options. ```python >>> default_to_any(1, 10, 20) 1 >>> default_to_any(None, 10, 20) 10 >>> default_to_any(None, None, 20) 20 ``` -------------------------------- ### Autoformat code with inv fmt Source: https://pydash.readthedocs.io/en/latest/contributing.html Use the 'inv fmt' command to automatically format your code according to project standards. ```bash $ inv fmt ``` -------------------------------- ### Reject elements from a collection Source: https://pydash.readthedocs.io/en/latest/api.html Use `reject` to get elements that do not satisfy the predicate. It's the inverse of `filter_`. ```python >>> reject([1, 2, 3, 4], lambda x: x >= 3) [1, 2] >>> reject([{"a": 0}, {"a": 1}, {"a": 2}], "a") [{'a': 0}] >>> reject([{"a": 0}, {"a": 1}, {"a": 2}], {"a": 1}) [{'a': 0}, {'a': 2}] ``` -------------------------------- ### last_index_of Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/arrays.html Gets the index at which the last occurrence of a value is found in an array. It can also search from a specified index. ```APIDOC ## last_index_of ### Description Gets the index at which the last occurrence of value is found. ### Arguments * `array` (Sequence[Any]): List to search. * `value` (Any): Value to search for. * `from_index` (Union[int, None]): Index to search from. Defaults to None. ### Returns * `int`: Index of found item or -1 if not found. ### Example ```python last_index_of([1, 2, 2, 4], 2) # => 2 last_index_of([1, 2, 2, 4], 2, from_index=1) # => 1 ``` ``` -------------------------------- ### pad_start Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/strings.html Pads `text` on the left side if it is shorter than the given padding length. The `chars` string may be truncated if the number of padding characters can't be evenly divided by the padding length. ```APIDOC ## pad_start ### Description Pads `text` on the left side if it is shorter than the given padding length. The `chars` string may be truncated if the number of padding characters can't be evenly divided by the padding length. ### Parameters #### Arguments - **text** (Any) - String to pad. - **length** (int) - Amount to pad. - **chars** (Any) - Characters to pad with. Defaults to ``" "``. ### Returns - **str** - Padded string. ### Example ```python >>> pad_start("abc", 5) ' abc' >>> pad_start("abc", 5, ".") '..abc' ``` ``` -------------------------------- ### Get First Element of Array Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/arrays.html Returns the first element of an array. If the array is empty, it returns None. ```python >>> head([1, 2, 3, 4]) 1 ``` -------------------------------- ### Clone the pydash repository Source: https://pydash.readthedocs.io/en/latest/contributing.html Clone your forked pydash repository locally to begin development. ```bash $ git clone git@github.com:your_username_here/pydash.git ``` -------------------------------- ### Pydash is_none Example Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/predicates.html Checks if a value is strictly equal to `None`. Returns `True` only when the input is `None`. ```python >>> is_none(None) True >>> is_none(False) False ``` -------------------------------- ### is_equal_with Source: https://pydash.readthedocs.io/en/latest/_modules/pydash/predicates.html This method is like `is_equal` except that it accepts customizer which is invoked to compare values. A customizer is provided which will be executed to compare values. If the customizer returns `None`, comparisons will be handled by the method instead. The customizer is invoked with two arguments: `(value, other)`. ```APIDOC ## is_equal_with(value, other, customizer) ### Description This method is like `is_equal` except that it accepts customizer which is invoked to compare values. A customizer is provided which will be executed to compare values. If the customizer returns `None`, comparisons will be handled by the method instead. The customizer is invoked with two arguments: `(value, other)`. ### Parameters #### Arguments - **value** - Object to compare. - **other** - Object to compare. - **customizer** - Customizer used to compare values from `value` and `other`. ### Returns - **bool** - Whether `value` and `other` are equal. ``` -------------------------------- ### pydash.utilities.nth_arg Source: https://pydash.readthedocs.io/en/latest/api.html Creates a function that gets the argument at index n. If n is negative, the nth argument from the end is returned. ```APIDOC ## pydash.utilities.nth_arg ### Description Creates a function that gets the argument at index n. If n is negative, the nth argument from the end is returned. ### Parameters #### Path Parameters * **pos** - The index of the argument to return. ### Returns Returns the new pass-thru function. ### Example ``` >>> func = nth_arg(1) >>> func(11, 22, 33, 44) 22 >>> func = nth_arg(-1) >>> func(11, 22, 33, 44) 44 ``` ``` -------------------------------- ### Using the py_ Instance for Method Chaining Source: https://pydash.readthedocs.io/en/latest/api.html The `py_` instance supports method chaining, allowing multiple operations to be applied sequentially. ```APIDOC ## py_ Instance - Method Chaining ### Description This demonstrates method chaining using the `py_` instance. ### Method ```python from pydash import py_ py_(data).().().value() ``` ### Example ```python from pydash import py_ py_([1, 2, 3, 4, 5]).initial().value() == [1, 2, 3, 4] ``` ```