Skip to content

Commit

Permalink
docs: add use cases for always
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jul 14, 2024
1 parent 1712bc0 commit c1e9d14
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/function/always.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,19 @@ const alwaysTrue = _.always(true)
alwaysTrue() // true
alwaysTrue(1, 2, 3) // true
```

### 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
() => someCalculation()
// Memoized
_.always(someCalculation())

// Not same object
() => ({ a: 1, b: 2 })
// Same object
_.always({ a: 1, b: 2 })
```

0 comments on commit c1e9d14

Please sign in to comment.