Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(curry module): add search terms and popular use cases #213

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
10 changes: 10 additions & 0 deletions docs/curry/chain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ const getUpperName = _.chain(getName, upperCase)
getUpperName(gods[0]) // => 'RA'
gods.map(getUpperName) // => ['RA', 'ZEUS', 'LOKI']
```

### Search terms

- Often called `compose`, `pipe`, or `flow`

### Popular use cases

- **Function composition**: Chain together multiple transformations, applying the result of each function as the input to the next. For example, first add a value, then multiply the result.
- **Data pipeline creation**: Build complex data transformation pipelines where each function modifies the data in sequence, improving readability and modularity.
- **Middleware processing**: Apply a series of middleware functions where the output of one is passed as input to the next, common in frameworks or request handling.
11 changes: 11 additions & 0 deletions docs/curry/compose.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,14 @@ const decomposed = useZero(objectize(increment(increment(_.returnArg('num')))))

decomposed() // => 2
```

### Search terms

- Often called `composeFunctions`, `chain`, or `pipeline`

### Popular use cases

- Combining multiple transformation functions into a single function to process data sequentially.
- Creating middleware stacks where each function modifies data and passes it to the next one.
- Building reusable and composable utility functions by composing different operations in a modular way.
- Simplifying complex logic by breaking it into smaller, maintainable pieces that are composed together.
11 changes: 11 additions & 0 deletions docs/curry/debounce.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,14 @@ setTimeout(() => {
myDebouncedFunc.isPending() // => false
}, 100)
```

### Search terms

- Often called `debounce`, `debouncedFunc`, or `throttleDebounce`

### Popular use cases

- Delaying execution of expensive operations, such as API requests or calculations, until a user has stopped interacting with the interface.
- Controlling the frequency of function execution, particularly for user inputs like typing, scrolling, or resizing events.
- Reducing the number of times a heavy computation or UI update is triggered in response to frequent actions.
- Ensuring that a function is called after a pause in actions, with methods to cancel, check status, or force execution.
11 changes: 11 additions & 0 deletions docs/curry/flip.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ _.flip(subtract)(1, 2) // => 1
```

Note that functions with more than two arguments are not supported.

### Search terms

- Often called `flipArgs`, `reverseArgs`, or `swapParams`

### Popular use cases

- Reversing the order of the first two arguments in a function, making it easier to work with curried or partial applications.
- Adapting functions to match the argument order expected by other higher-order functions or utilities.
- Swapping arguments for improved readability in specific contexts, especially in functional programming.
- Simplifying complex function compositions by adjusting the argument order dynamically.
11 changes: 11 additions & 0 deletions docs/curry/memo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,14 @@ const beta = timestamp({ group: 'beta' })
now === later // => true
beta === now // => false
```

### Search terms

- Often called `memoize`, `cacheFunction`, or `remember`

### Popular use cases

- Optimizing performance by caching the results of expensive computations and reusing them when the same inputs occur.
- Reducing redundant calculations in recursive functions, such as those for generating Fibonacci sequences or factorials.
- Enhancing API efficiency by storing and reusing responses within a specified time window, preventing unnecessary calls.
- Controlling cache expiration using TTL (time-to-live) to ensure stale data is eventually recalculated or refetched.
11 changes: 11 additions & 0 deletions docs/curry/once.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@ once.reset(fn)
fn() // 0.3
fn() // 0.3
```

### Search terms

- Often called `once`, `runOnce`, or `singleCall`

### Popular use cases

- Ensuring that a function executes only a single time, regardless of how many times it is invoked.
- Protecting sensitive or resource-heavy operations by restricting their execution to just one successful call.
- Managing initialization logic, such as setting up global state or event listeners, so they only occur once.
- Offering the ability to reset the function, allowing the operation to be executed again if needed, without repeated execution by default.
11 changes: 11 additions & 0 deletions docs/curry/partial.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ const addFive = _.partial(add, 5)

addFive(2) // => 7
```

### Search terms

- Often called `partial`, `partialApply`, or `preFillArgs`

### Popular use cases

- Pre-filling some arguments of a function, creating a new function with fewer parameters for easier reuse.
- Simplifying complex operations by partially applying constant values, reducing the need for repetitive code.
- Adapting functions with multiple parameters for use in situations where fewer arguments are passed over time.
- Streamlining callback creation in scenarios where only a subset of the original function's arguments is known upfront.
11 changes: 11 additions & 0 deletions docs/curry/partob.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ const addFive = _.partob(add, { a: 5 })

addFive({ b: 2 }) // => 7
```

### Search terms

- Often called `partialObject`, `partob`, or `partialProps`

### Popular use cases

- Partially applying default properties or options to a function that accepts a single object argument, reducing code repetition.
- Creating specialized versions of object-based functions by pre-filling certain properties while allowing others to be supplied later.
- Simplifying configuration-heavy functions by breaking them down into smaller steps, where each step completes the object with additional fields.
- Reducing verbosity when working with functions that rely heavily on object destructuring by providing default values upfront.
11 changes: 11 additions & 0 deletions docs/curry/proxied.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,14 @@ person.name // => Joe
person.size // => 20
person.getLocation() // => here
```

### Search terms

- Often called `proxied`, `dynamicProxy`, or `propertyInterceptor`

### Popular use cases

- Dynamically transforming or computing the values of object properties based on their names when accessed.
- Creating virtual objects that derive values on-the-fly, avoiding the need for pre-defined properties.
- Implementing flexible APIs where property access triggers custom logic or data retrieval, based on the property name.
- Simplifying code by allowing properties to be accessed without explicitly defining them, with logic applied during access.
11 changes: 11 additions & 0 deletions docs/curry/throttle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,14 @@ Source Invocations: x - - - - - - - - - - - - x - - - - - - - - - - - - - x - -
```

In this diagram, 'x' represents function invocations, and '-' represents time passing.

### Search terms

- Often called `throttle`, `limitCalls`, or `rateLimit`

### Popular use cases

- Limiting the frequency of function calls in response to rapidly occurring events like scrolling, resizing, or key presses.
- Ensuring a function is not executed more than once within a specified time interval to optimize performance.
- Delaying execution of repeated function calls but allowing a final trailing call to execute after the last event in some cases.
- Useful for scenarios like logging, network requests, or animation triggers that shouldn't be triggered too frequently.
Loading