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

fix non standard imports #1913

Merged
merged 2 commits into from
Oct 24, 2023
Merged
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
22 changes: 19 additions & 3 deletions docs/guides/code-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ nav_order: 1

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Import Statements

To properly import modules from `fp-ts`, you should use the following syntax:

```ts
import ... from 'fp-ts/<module>'
```

For instance, when importing the `Option` module, you can use the following code:

```ts
import * as Option from 'fp-ts/Option'
```

This ensures that you're importing the required modules correctly.

## Module structure

In general a module containing the definition of a data structure has the following structure
Expand Down Expand Up @@ -128,7 +144,7 @@ pipe(
`K` means *K*leisli. A _Kleisli arrow_ is a function with the following signature

```ts
(a: A) => F<B>
;(a: A) => F<B>
```

where `F` is a type constructor.
Expand Down Expand Up @@ -159,13 +175,13 @@ how can we parse `input`?
We could lift the Kleisli arrow `parse`, i.e. transform a function

```ts
(s: string) => E.Either<Error, number>
;(s: string) => E.Either<Error, number>
```

into a function

```ts
(s: string) => IE.IOEither<Error, number>
;(s: string) => IE.IOEither<Error, number>
```

That's what `fromEitherK` is all about
Expand Down
16 changes: 8 additions & 8 deletions docs/modules/Array.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ export declare const filter: {

```ts
import { filter } from 'fp-ts/Array'
import { isString } from 'fp-ts/lib/string'
import { isString } from 'fp-ts/string'

assert.deepStrictEqual(filter(isString)(['a', 1, {}, 'b', 5]), ['a', 'b'])
assert.deepStrictEqual(filter((x: number) => x > 0)([-3, 1, -2, 5]), [1, 5])
Expand Down Expand Up @@ -608,7 +608,7 @@ export declare const partition: {

```ts
import { partition } from 'fp-ts/Array'
import { isString } from 'fp-ts/lib/string'
import { isString } from 'fp-ts/string'

assert.deepStrictEqual(partition(isString)(['a', 1, {}, 'b', 5]), { left: [1, {}, 5], right: ['a', 'b'] })
assert.deepStrictEqual(partition((x: number) => x > 0)([-3, 1, -2, 5]), { left: [-3, -2], right: [1, 5] })
Expand All @@ -632,7 +632,7 @@ export declare const partitionMap: <A, B, C>(f: (a: A) => Either<B, C>) => (fa:

```ts
import { partitionMap } from 'fp-ts/Array'
import { Either, left, right } from 'fp-ts/lib/Either'
import { Either, left, right } from 'fp-ts/Either'

const upperIfString = <B>(x: B): Either<B, string> => (typeof x === 'string' ? right(x.toUpperCase()) : left(x))
assert.deepStrictEqual(partitionMap(upperIfString)([-2, 'hello', 6, 7, 'world']), {
Expand All @@ -659,7 +659,7 @@ export declare const partitionMapWithIndex: <A, B, C>(

```ts
import { partitionMapWithIndex } from 'fp-ts/Array'
import { Either, left, right } from 'fp-ts/lib/Either'
import { Either, left, right } from 'fp-ts/Either'

const upperIfStringBefore3 = <B>(index: number, x: B): Either<B, string> =>
index < 3 && typeof x === 'string' ? right(x.toUpperCase()) : left(x)
Expand Down Expand Up @@ -1383,7 +1383,7 @@ export declare function fromPredicate<A>(predicate: Predicate<A>): (a: A) => Arr
```ts
import { fromPredicate } from 'fp-ts/Array'
import { pipe } from 'fp-ts/function'
import { isString } from 'fp-ts/lib/string'
import { isString } from 'fp-ts/string'

assert.deepStrictEqual(pipe('a', fromPredicate(isString)), ['a'])
assert.deepStrictEqual(pipe(7, fromPredicate(isString)), [])
Expand Down Expand Up @@ -1859,7 +1859,7 @@ export declare const traverseWithIndex: PipeableTraverseWithIndex1<'Array', numb

```ts
import { traverseWithIndex } from 'fp-ts/Array'
import { Applicative, left, right } from 'fp-ts/lib/Either'
import { Applicative, left, right } from 'fp-ts/Either'

const f = (index: number, x: unknown) =>
typeof x === 'string' ? right(x.toUpperCase() + index) : left(new Error('not a string'))
Expand Down Expand Up @@ -1892,7 +1892,7 @@ export declare const sequence: Sequence1<'Array'>

```ts
import { sequence } from 'fp-ts/Array'
import { Applicative, left, right } from 'fp-ts/lib/Either'
import { Applicative, left, right } from 'fp-ts/Either'

assert.deepStrictEqual(sequence(Applicative)([right('a'), right('b')]), right(['a', 'b']))
assert.deepStrictEqual(
Expand Down Expand Up @@ -1925,7 +1925,7 @@ export declare const traverse: PipeableTraverse1<'Array'>

```ts
import { traverse } from 'fp-ts/Array'
import { Applicative, left, right } from 'fp-ts/lib/Either'
import { Applicative, left, right } from 'fp-ts/Either'

const f = (x: unknown) => (typeof x === 'string' ? right(x.toUpperCase()) : left(new Error('not a string')))
assert.deepStrictEqual(traverse(Applicative)(f)(['a', 'b']), right(['A', 'B']))
Expand Down
16 changes: 8 additions & 8 deletions src/Array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export const replicate = <A>(n: number, a: A): Array<A> => makeBy(n, () => a)
* @example
* import { fromPredicate } from 'fp-ts/Array'
* import { pipe } from 'fp-ts/function'
* import { isString } from "fp-ts/lib/string";
* import { isString } from "fp-ts/string";
*
* assert.deepStrictEqual(pipe("a", fromPredicate(isString)), ["a"]);
* assert.deepStrictEqual(pipe(7, fromPredicate(isString)), []);
Expand Down Expand Up @@ -1728,7 +1728,7 @@ export const separate = <A, B>(fa: Array<Either<A, B>>): Separated<Array<A>, Arr
*
* @example
* import { filter } from 'fp-ts/Array'
* import { isString } from "fp-ts/lib/string";
* import { isString } from "fp-ts/string";
*
* assert.deepStrictEqual(filter(isString)(["a", 1, {}, "b", 5]), ["a", "b"]);
* assert.deepStrictEqual(filter((x:number) => x > 0)([-3, 1, -2, 5]), [1, 5]);
Expand All @@ -1753,7 +1753,7 @@ export const filter: {
*
* @example
* import { partition } from 'fp-ts/Array'
* import { isString } from "fp-ts/lib/string";
* import { isString } from "fp-ts/string";
*
* assert.deepStrictEqual(partition(isString)(["a", 1, {}, "b", 5]), { left: [1, {}, 5], right: ["a", "b"] });
* assert.deepStrictEqual(partition((x: number) => x > 0)([-3, 1, -2, 5]), { left: [-3, -2], right: [1, 5] });
Expand Down Expand Up @@ -1811,7 +1811,7 @@ export const partitionWithIndex: {
*
* @example
* import { partitionMap } from 'fp-ts/Array'
* import { Either, left, right } from "fp-ts/lib/Either";
* import { Either, left, right } from "fp-ts/Either";
*
* const upperIfString = <B>(x: B): Either<B, string> =>
* typeof x === "string" ? right(x.toUpperCase()) : left(x);
Expand All @@ -1832,7 +1832,7 @@ export const partitionMap: <A, B, C>(f: (a: A) => Either<B, C>) => (fa: Array<A>
*
* @example
* import { partitionMapWithIndex } from 'fp-ts/Array'
* import { Either, left, right } from "fp-ts/lib/Either";
* import { Either, left, right } from "fp-ts/Either";
*
* const upperIfStringBefore3 = <B>(index: number, x: B): Either<B, string> =>
* index < 3 && typeof x === "string" ? right(x.toUpperCase()) : left(x);
Expand Down Expand Up @@ -2071,7 +2071,7 @@ export const reduceRightWithIndex: <A, B>(b: B, f: (i: number, a: A, b: B) => B)
*
* @example
* import { traverse } from 'fp-ts/Array'
* import { Applicative, left, right } from "fp-ts/lib/Either";
* import { Applicative, left, right } from "fp-ts/Either";
*
* const f = (x: unknown) =>
* typeof x === "string" ? right(x.toUpperCase()) : left(new Error("not a string"));
Expand Down Expand Up @@ -2100,7 +2100,7 @@ export const traverse: PipeableTraverse1<URI> = <F>(
*
* @example
* import { sequence } from 'fp-ts/Array'
* import { Applicative, left, right } from "fp-ts/lib/Either";
* import { Applicative, left, right } from "fp-ts/Either";
*
* assert.deepStrictEqual(sequence(Applicative)([right("a"), right("b")]), right(["a", "b"]));
* assert.deepStrictEqual(
Expand All @@ -2127,7 +2127,7 @@ export const sequence: Traversable1<URI>['sequence'] =
*
* @example
* import { traverseWithIndex } from 'fp-ts/Array'
* import { Applicative, left, right } from "fp-ts/lib/Either";
* import { Applicative, left, right } from "fp-ts/Either";
*
* const f = (index:number, x:unknown) =>
* typeof x === "string" ? right(x.toUpperCase() + index) : left(new Error("not a string"));
Expand Down
Loading