Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jun 24, 2024
1 parent 5860f63 commit 8bd6ab6
Show file tree
Hide file tree
Showing 33 changed files with 138 additions and 250 deletions.
2 changes: 1 addition & 1 deletion chiller.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
"Typed"
]
}
}
}
2 changes: 1 addition & 1 deletion docs/array/boil.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ const gods = [
}
]

boil(gods, (a, b) => (a.power > b.power ? a : b))
boil(gods, (a, b) => (a.power > b.power ? a : b))
// => { name: 'Ra', power: 100 }
```
13 changes: 12 additions & 1 deletion docs/array/cluster.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ split as evenly as possible.
```ts
import { cluster } from 'radash'

const gods = ['Ra', 'Zeus', 'Loki', 'Vishnu', 'Icarus', 'Osiris', 'Thor', 'Apollo', 'Artemis', 'Athena']
const gods = [
'Ra',
'Zeus',
'Loki',
'Vishnu',
'Icarus',
'Osiris',
'Thor',
'Apollo',
'Artemis',
'Athena'
]

cluster(gods, 3)
// => [
Expand Down
26 changes: 13 additions & 13 deletions docs/array/list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ _A hat tip to Python's `range` functionality_
```ts
import { list } from 'radash'

list(3) // [0, 1, 2, 3]
list(0, 3) // [0, 1, 2, 3]
list(0, 3, 'y') // [y, y, y, y]
list(0, 3, () => 'y') // [y, y, y, y]
list(0, 3, i => i) // [0, 1, 2, 3]
list(3) // [0, 1, 2, 3]
list(0, 3) // [0, 1, 2, 3]
list(0, 3, 'y') // [y, y, y, y]
list(0, 3, () => 'y') // [y, y, y, y]
list(0, 3, i => i) // [0, 1, 2, 3]
list(0, 3, i => `y${i}`) // [y0, y1, y2, y3]
list(0, 3, obj) // [obj, obj, obj, obj]
list(0, 6, i => i, 2) // [0, 2, 4, 6]
list(0, 3, obj) // [obj, obj, obj, obj]
list(0, 6, i => i, 2) // [0, 2, 4, 6]
```

## Signatures
Expand Down Expand Up @@ -50,16 +50,16 @@ list(2, 6) // [2, 3, 4, 5, 6]
When given a third argument it's treated as the `value` to be used in the list. If the `value` is a function it will be called, with an index argument, to create every value.

```ts
list(2, 4, {}) // [{}, {}, {}]
list(2, 4, null) // [null, null, null]
list(2, 4, (i) => i) // [2, 3, 4]
list(2, 4, {}) // [{}, {}, {}]
list(2, 4, null) // [null, null, null]
list(2, 4, i => i) // [2, 3, 4]
```

### list(start, end, value, step)

When given a fourth argument it's treated as the `step` size to skip when generating values from `start` to `end`.

```ts
list(2, 4, i => i, 2) // [2, 4]
list(25, 100, i => i, 25) // [25, 50, 75, 100]
```
list(2, 4, i => i, 2) // [2, 4]
list(25, 100, i => i, 25) // [25, 50, 75, 100]
```
26 changes: 13 additions & 13 deletions docs/array/range.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ _A hat tip to Python's `range` functionality_
```ts
import { range } from 'radash'

range(3) // yields 0, 1, 2, 3
range(0, 3) // yields 0, 1, 2, 3
range(0, 3, 'y') // yields y, y, y, y
range(0, 3, () => 'y') // yields y, y, y, y
range(0, 3, i => i) // yields 0, 1, 2, 3
range(3) // yields 0, 1, 2, 3
range(0, 3) // yields 0, 1, 2, 3
range(0, 3, 'y') // yields y, y, y, y
range(0, 3, () => 'y') // yields y, y, y, y
range(0, 3, i => i) // yields 0, 1, 2, 3
range(0, 3, i => `y${i}`) // yields y0, y1, y2, y3
range(0, 3, obj) // yields obj, obj, obj, obj
range(0, 6, i => i, 2) // yields 0, 2, 4, 6
range(0, 3, obj) // yields obj, obj, obj, obj
range(0, 6, i => i, 2) // yields 0, 2, 4, 6

for (const i of range(0, 200, 10)) {
console.log(i) // => 0, 10, 20, 30 ... 190, 200
Expand Down Expand Up @@ -58,16 +58,16 @@ range(2, 6) // yields 2, 3, 4, 5, 6
When given a third argument it's treated as the `value` to be yielded in the generator. If the `value` is a function it will be called, with an index argument, to create every value.

```ts
range(2, 4, {}) // yields {}, {}, {}
range(2, 4, null) // yields null, null, null
range(2, 4, (i) => i) // yields 2, 3, 4
range(2, 4, {}) // yields {}, {}, {}
range(2, 4, null) // yields null, null, null
range(2, 4, i => i) // yields 2, 3, 4
```

### range(start, end, value, step)

When given a fourth argument it's treated as the `step` size to skip when yielding values from `start` to `end`.

```ts
range(2, 4, i => i, 2) // yields 2, 4
range(25, 100, i => i, 25) // yields 25, 50, 75, 100
```
range(2, 4, i => i, 2) // yields 2, 4
range(25, 100, i => i, 25) // yields 25, 50, 75, 100
```
4 changes: 2 additions & 2 deletions docs/array/toggle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { toggle } from 'radash'

const gods = ['ra', 'zeus', 'loki']

toggle(gods, 'ra') // => [zeus, loki]
toggle(gods, 'ra') // => [zeus, loki]
toggle(gods, 'vishnu') // => [ra, zeus, loki, vishnu]
```

Expand All @@ -31,7 +31,7 @@ const vishnu = { name: 'Vishnu' }

const gods = [ra, zeus, loki]

toggle(gods, ra, g => g.name) // => [zeus, loki]
toggle(gods, ra, g => g.name) // => [zeus, loki]
toggle(gods, vishnu, g => g.name) // => [ra, zeus, loki, vishnu]
```

Expand Down
2 changes: 1 addition & 1 deletion docs/array/unique.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const fish = [
}
]

unique( fish, f => f.name )
unique(fish, f => f.name)
// [
// { name: 'Marlin', weight: 105, source: 'ocean' },
// { name: 'Salmon', weight: 22, source: 'river' }
Expand Down
26 changes: 8 additions & 18 deletions docs/async/defer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ group: 'Async'
description: Run an async function with deferred functions
---




## Basic usage

The `_.defer` functions lets you run an async function, registering functions as you go
that should be deferred until the async function completes, and then executed. This is
really useful in scripts where failure up to or after a specific point will require some
cleanup. It's a bit like a `finally` block.
The `_.defer` functions lets you run an async function, registering functions as you go
that should be deferred until the async function completes, and then executed. This is
really useful in scripts where failure up to or after a specific point will require some
cleanup. It's a bit like a `finally` block.

A hat tip to Swift's `defer` for the inspiration.
A hat tip to Swift's `defer` for the inspiration.

The function passed to `_.defer` is called with a single `register` function argument that
The function passed to `_.defer` is called with a single `register` function argument that
can be used to register the work you want to be called when the function completes. If your function throws an error and then a registered cleanup function throws
and error it is ignored by default. The register
function supports an optional second `options` argument that lets you configure a rethrow
Expand All @@ -25,15 +22,15 @@ strategy so that error in the cleanup function is rethrown.
```ts
import { defer } from 'radash'

await defer(async (cleanup) => {
await defer(async cleanup => {
const buildDir = await createBuildDir()

cleanup(() => fs.unlink(buildDir))

await build()
})

await defer(async (register) => {
await defer(async register => {
const org = await api.org.create()
register(async () => api.org.delete(org.id), { rethrow: true })

Expand All @@ -43,10 +40,3 @@ await defer(async (register) => {
await executeTest(org, user)
})
```







12 changes: 1 addition & 11 deletions docs/async/map.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ group: 'Async'
description: Map an array with an async function
---




## Basic usage

A map that handles callback functions that return a promise.
Expand All @@ -16,14 +13,7 @@ import { map } from 'radash'

const userIds = [1, 2, 3, 4]

const users = await map(userIds, async (userId) => {
const users = await map(userIds, async userId => {
return await api.users.find(userId)
})
```







16 changes: 3 additions & 13 deletions docs/async/parallel.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ group: 'Async'
description: Run many async function in parallel
---




## Basic usage

Like `_.map` but built specifically to run the async callback functions
Expand All @@ -20,34 +17,27 @@ const userIds = [1, 2, 3, 4, 5, 6, 7, 8, 9]

// Will run the find user async function 3 at a time
// starting another request when one of the 3 is freed
const users = await parallel(3, userIds, async (userId) => {
const users = await parallel(3, userIds, async userId => {
return await api.users.find(userId)
})
```

## Errors

When all work is complete parallel will check for errors. If any
occurred they will all be thrown in a single `AggregateError` that
occurred they will all be thrown in a single `AggregateError` that
has an `errors` property that is all the errors that were thrown.

```ts
import { parallel, try as tryit } from 'radash'

const userIds = [1, 2, 3]

const [err, users] = await tryit(parallel)(3, userIds, async (userId) => {
const [err, users] = await tryit(parallel)(3, userIds, async userId => {
throw new Error(`No, I don\'t want to find user ${userId}`)
})

console.log(err) // => AggregateError
console.log(err.errors) // => [Error, Error, Error]
console.log(err.errors[1].message) // => No, I don't want to find user 2
```







28 changes: 11 additions & 17 deletions docs/async/reduce.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ group: 'Async'
description: Reduce an array with an async function
---




## Basic usage

A reduce that handles callback functions that return a promise.
Expand All @@ -16,18 +13,15 @@ import { reduce } from 'radash'

const userIds = [1, 2, 3, 4]

const users = await reduce(userIds, async (acc, userId) => {
const user = await api.users.find(userId)
return {
...acc,
[userId]: user
}
}, {})
const users = await reduce(
userIds,
async (acc, userId) => {
const user = await api.users.find(userId)
return {
...acc,
[userId]: user
}
},
{}
)
```







16 changes: 3 additions & 13 deletions docs/async/retry.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ group: 'Async'
description: Run an async function retrying if it fails
---




## Basic usage

The `_.retry` function allows you to run an async function and automagically retry it if it fails. Given the async func to run, an optional max number of retries (`r`), and an optional milliseconds to delay between retries (`d`), the given async function will be called, retrying `r` many times, and waiting `d` milliseconds between retries.
The `_.retry` function allows you to run an async function and automagically retry it if it fails. Given the async func to run, an optional max number of retries (`r`), and an optional milliseconds to delay between retries (`d`), the given async function will be called, retrying `r` many times, and waiting `d` milliseconds between retries.

The `times` option defaults to `3`. The `delay` option (defaults to null) can specify milliseconds to sleep between attempts.
The `times` option defaults to `3`. The `delay` option (defaults to null) can specify milliseconds to sleep between attempts.

The `backoff` option is like delay but uses a function to sleep -- makes for easy exponential backoff.

Expand All @@ -23,12 +20,5 @@ await retry({ times: 10 }, api.users.list)
await retry({ times: 2, delay: 1000 }, api.users.list)

// exponential backoff
await retry({ backoff: i => 10**i }, api.users.list)
await retry({ backoff: i => 10 ** i }, api.users.list)
```







11 changes: 0 additions & 11 deletions docs/async/sleep.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ group: 'Async'
description: Asynchronously wait for time to pass
---




## Basic usage

The `_.sleep` function allows you to delay in milliseconds.
Expand All @@ -16,11 +13,3 @@ import { sleep } from 'radash'

await sleep(2000) // => waits 2 seconds
```








9 changes: 4 additions & 5 deletions docs/core-concepts.mdx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
title: "Core Concepts"
group: "Getting Started"
description: "Why is Radash so dashing?"
title: 'Core Concepts'
group: 'Getting Started'
description: 'Why is Radash so dashing?'
---

## Keep it Simple

### Readable

The Radash source is easy to read and understand. We don't make you navigate through internal library modules and classes, reading a hundred lines of code, to understand what a function does or how it works.
The Radash source is easy to read and understand. We don't make you navigate through internal library modules and classes, reading a hundred lines of code, to understand what a function does or how it works.

As an example, here's a look at [the source](https://github.com/rayepps/radash/blob/master/src/curry.ts#L11-L13) for the `_.compose` function.

Expand All @@ -29,4 +29,3 @@ Functional programming has incredible design patterns that we often pull from. H
### Types

Radash is written in TypeScript and provides full typing out of the box.

Loading

0 comments on commit 8bd6ab6

Please sign in to comment.