diff --git a/docs/guides/code-conventions.md b/docs/guides/code-conventions.md index 377865ee9..9f39d7f86 100644 --- a/docs/guides/code-conventions.md +++ b/docs/guides/code-conventions.md @@ -21,6 +21,22 @@ nav_order: 1 +## Import Statements + +To properly import modules from `fp-ts`, you should use the following syntax: + +```ts +import ... from 'fp-ts/' +``` + +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 @@ -128,7 +144,7 @@ pipe( `K` means *K*leisli. A _Kleisli arrow_ is a function with the following signature ```ts -(a: A) => F +;(a: A) => F ``` where `F` is a type constructor. @@ -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 +;(s: string) => E.Either ``` into a function ```ts -(s: string) => IE.IOEither +;(s: string) => IE.IOEither ``` That's what `fromEitherK` is all about diff --git a/docs/modules/Array.ts.md b/docs/modules/Array.ts.md index c6ec536a5..929fcbddf 100644 --- a/docs/modules/Array.ts.md +++ b/docs/modules/Array.ts.md @@ -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]) @@ -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] }) @@ -632,7 +632,7 @@ export declare const partitionMap: (f: (a: A) => Either) => (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 = (x: B): Either => (typeof x === 'string' ? right(x.toUpperCase()) : left(x)) assert.deepStrictEqual(partitionMap(upperIfString)([-2, 'hello', 6, 7, 'world']), { @@ -659,7 +659,7 @@ export declare const partitionMapWithIndex: ( ```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 = (index: number, x: B): Either => index < 3 && typeof x === 'string' ? right(x.toUpperCase()) : left(x) @@ -1383,7 +1383,7 @@ export declare function fromPredicate(predicate: Predicate): (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)), []) @@ -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')) @@ -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( @@ -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'])) diff --git a/src/Array.ts b/src/Array.ts index 1668856aa..d49925c41 100644 --- a/src/Array.ts +++ b/src/Array.ts @@ -183,7 +183,7 @@ export const replicate = (n: number, a: A): Array => 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)), []); @@ -1728,7 +1728,7 @@ export const separate = (fa: Array>): Separated, 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]); @@ -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] }); @@ -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 = (x: B): Either => * typeof x === "string" ? right(x.toUpperCase()) : left(x); @@ -1832,7 +1832,7 @@ export const partitionMap: (f: (a: A) => Either) => (fa: Array * * @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 = (index: number, x: B): Either => * index < 3 && typeof x === "string" ? right(x.toUpperCase()) : left(x); @@ -2071,7 +2071,7 @@ export const reduceRightWithIndex: (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")); @@ -2100,7 +2100,7 @@ export const traverse: PipeableTraverse1 = ( * * @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( @@ -2127,7 +2127,7 @@ export const sequence: Traversable1['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"));