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(function module): add search terms and popular use cases #214

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions docs/function/always.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ alwaysTrue() // true
alwaysTrue(1, 2, 3) // true
```

### Use cases
### Search terms

You can avoid using `always` if the value is a primitive (use `() => true` instead), but it can be useful if you need a function that always returns the same object reference, or if you want to memoize a calculation across multiple calls.
- Often called `alwaysReturn`, or `fixedValue`.

### Popular use cases

- You can avoid using `always` if the value is a primitive (use `() => true` instead), but it can be useful if you need a function that always returns the same object reference, or if you want to memoize a calculation across multiple calls.

```ts
// Not memoized
Expand All @@ -31,3 +35,5 @@ _.always(someCalculation())
// Same object
_.always({ a: 1, b: 2 })
```

- Defining placeholder functions in place of complex logic during development or for mock implementations in unit testing.
9 changes: 9 additions & 0 deletions docs/function/castComparator.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,12 @@ const compareByFullName = _.castComparator(
users.sort(compareByFullName)
// [Alice, Charlie, Drew]
```

### Search terms

- Often called `makeComparator`, `createComparator`, or `compareBy`.

### Popular use cases

- Dynamically creating comparison functions based on object properties or mapping functions, streamlining sorting operations for arrays of complex objects.
- Simplifying array sorting logic by allowing custom compare functions for properties such as names, dates, or other comparable values, making code more modular and reusable.
10 changes: 10 additions & 0 deletions docs/function/castMapping.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,13 @@ The term "castMapping" combines two key concepts from programming:
2. "Mapping" as a noun refers to a correspondence between elements of two sets, or a function that defines such a correspondence. In programming, it often represents a data structure that associates keys with values, or a function that transforms one set of data into another.

Together, "castMapping" describes a function that takes a value (which could be a function, a property name, or undefined) and converts or "casts" it into a standardized mapping. This resulting mapping can then be used to transform data consistently, regardless of the initial input type. The process enhances flexibility in data manipulation by allowing various input types to be treated uniformly as mappings for data transformation.

### Search terms

- Often called `mapBy`, `getMappedValue`, or `propertyOrFunction`.

### Popular use cases

- Creating flexible mapping functions that can handle dynamic keys or property names, which is useful for data transformation in functional programming.
- Simplifying access to object properties in array mapping or filtering operations by converting a string key into a reusable function.
- Providing a fallback identity function when no specific mapping is defined, useful in cases where a default behavior is needed for operations on various data types.
10 changes: 10 additions & 0 deletions docs/function/noop.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ _.noop() // => undefined

- **Shouldn't I just use `?.` operator?**
Where possible, yes you should. The `noop` is best for cases where you're not in control of the code that calls it and a function is required.

### Search terms

- Often called `getUndefined`, `doNothing`, or `emptyCallback`.

### Popular use cases

- Providing a placeholder function where a callback is required but no action is needed, such as in optional event handlers or asynchronous operations.
- Preventing potential errors by using it as a default argument for functions expecting callbacks, ensuring graceful handling of undefined or null callbacks.
- Serving as a no-op for testing scenarios, mock functions, or as a temporary placeholder during development.
Loading