1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | import { Applicative, Applicative1, Applicative2, Applicative3 } from 'fp-ts/lib/Applicative'
|
23 | import { Category2 } from 'fp-ts/lib/Category'
|
24 | import { Either } from 'fp-ts/lib/Either'
|
25 | import { Predicate, Refinement } from 'fp-ts/lib/function'
|
26 | import { HKT, Kind, Kind2, Kind3, URIS, URIS2, URIS3 } from 'fp-ts/lib/HKT'
|
27 | import { Invariant2 } from 'fp-ts/lib/Invariant'
|
28 | import * as O from 'fp-ts/lib/Option'
|
29 | import { ReadonlyNonEmptyArray } from 'fp-ts/lib/ReadonlyNonEmptyArray'
|
30 | import { ReadonlyRecord } from 'fp-ts/lib/ReadonlyRecord'
|
31 | import { Semigroupoid2 } from 'fp-ts/lib/Semigroupoid'
|
32 | import { Traversable1 } from 'fp-ts/lib/Traversable'
|
33 | import { Iso } from './Iso'
|
34 | import { Lens } from './Lens'
|
35 | import { Prism } from './Prism'
|
36 | import { Traversal } from './Traversal'
|
37 | import Option = O.Option
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | export interface Optional<S, A> {
|
43 | readonly getOption: (s: S) => Option<A>
|
44 | readonly set: (a: A) => (s: S) => S
|
45 | }
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | export declare const optional: <S, A>(
|
51 | getOption: Optional<S, A>['getOption'],
|
52 | set: Optional<S, A>['set']
|
53 | ) => Optional<S, A>
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | export declare const id: <S>() => Optional<S, S>
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | export declare const asTraversal: <S, A>(sa: Optional<S, A>) => Traversal<S, A>
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | export declare const compose: <A, B>(ab: Optional<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B>
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | export declare const composeOptional: <A, B>(ab: Optional<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B>
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | export declare const composeIso: <A, B>(ab: Iso<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B>
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | export declare const composeLens: <A, B>(ab: Lens<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B>
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | export declare const composePrism: <A, B>(ab: Prism<A, B>) => <S>(sa: Optional<S, A>) => Optional<S, B>
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | export declare const composeTraversal: <A, B>(ab: Traversal<A, B>) => <S>(sa: Optional<S, A>) => Traversal<S, B>
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | export declare const modifyOption: <A, B extends A = A>(
|
113 | f: (a: A) => B
|
114 | ) => <S>(optional: Optional<S, A>) => (s: S) => Option<S>
|
115 |
|
116 |
|
117 |
|
118 |
|
119 | export declare const setOption: <A>(a: A) => <S>(optional: Optional<S, A>) => (s: S) => O.Option<S>
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | export declare const modify: <A, B extends A = A>(f: (a: A) => B) => <S>(optional: Optional<S, A>) => (s: S) => S
|
125 |
|
126 |
|
127 |
|
128 |
|
129 | export declare function modifyF<F extends URIS3>(
|
130 | F: Applicative3<F>
|
131 | ): <A, R, E>(f: (a: A) => Kind3<F, R, E, A>) => <S>(sa: Optional<S, A>) => (s: S) => Kind3<F, R, E, S>
|
132 | export declare function modifyF<F extends URIS2>(
|
133 | F: Applicative2<F>
|
134 | ): <A, E>(f: (a: A) => Kind2<F, E, A>) => <S>(sa: Optional<S, A>) => (s: S) => Kind2<F, E, S>
|
135 | export declare function modifyF<F extends URIS>(
|
136 | F: Applicative1<F>
|
137 | ): <A>(f: (a: A) => Kind<F, A>) => <S>(sa: Optional<S, A>) => (s: S) => Kind<F, S>
|
138 | export declare function modifyF<F>(
|
139 | F: Applicative<F>
|
140 | ): <A>(f: (a: A) => HKT<F, A>) => <S>(sa: Optional<S, A>) => (s: S) => HKT<F, S>
|
141 | /**
|
142 | * Return an `Optional` from a `Optional` focused on a nullable value.
|
143 | *
|
144 | * @category combinators
|
145 | * @since 2.3.3
|
146 | */
|
147 | export declare const fromNullable: <S, A>(sa: Optional<S, A>) => Optional<S, NonNullable<A>>
|
148 | /**
|
149 | * @category combinators
|
150 | * @since 2.3.0
|
151 | */
|
152 | export declare function filter<A, B extends A>(refinement: Refinement<A, B>): <S>(sa: Optional<S, A>) => Optional<S, B>
|
153 | export declare function filter<A>(predicate: Predicate<A>): <S>(sa: Optional<S, A>) => Optional<S, A>
|
154 | /**
|
155 | * Return a `Optional` from a `Optional` and a prop.
|
156 | *
|
157 | * @category combinators
|
158 | * @since 2.3.0
|
159 | */
|
160 | export declare const prop: <A, P extends keyof A>(prop: P) => <S>(sa: Optional<S, A>) => Optional<S, A[P]>
|
161 | /**
|
162 | * Return a `Optional` from a `Optional` and a list of props.
|
163 | *
|
164 | * @category combinators
|
165 | * @since 2.3.0
|
166 | */
|
167 | export declare const props: <A, P extends keyof A>(
|
168 | props_0: P,
|
169 | props_1: P,
|
170 | ...props_2: P[]
|
171 | ) => <S>(sa: Optional<S, A>) => Optional<S, { [K in P]: A[K] }>
|
172 | /**
|
173 | * Return a `Optional` from a `Optional` focused on a component of a tuple.
|
174 | *
|
175 | * @category combinators
|
176 | * @since 2.3.0
|
177 | */
|
178 | export declare const component: <A extends readonly unknown[], P extends keyof A>(
|
179 | prop: P
|
180 | ) => <S>(sa: Optional<S, A>) => Optional<S, A[P]>
|
181 | /**
|
182 | * Return a `Optional` from a `Optional` focused on an index of a `ReadonlyArray`.
|
183 | *
|
184 | * @category combinators
|
185 | * @since 2.3.0
|
186 | */
|
187 | export declare const index: (i: number) => <S, A>(sa: Optional<S, ReadonlyArray<A>>) => Optional<S, A>
|
188 | /**
|
189 | * Return a `Optional` from a `Optional` focused on an index of a `ReadonlyNonEmptyArray`.
|
190 | *
|
191 | * @category combinators
|
192 | * @since 2.3.8
|
193 | */
|
194 | export declare const indexNonEmpty: (i: number) => <S, A>(sa: Optional<S, ReadonlyNonEmptyArray<A>>) => Optional<S, A>
|
195 | /**
|
196 | * Return a `Optional` from a `Optional` focused on a key of a `ReadonlyRecord`.
|
197 | *
|
198 | * @category combinators
|
199 | * @since 2.3.0
|
200 | */
|
201 | export declare const key: (key: string) => <S, A>(sa: Optional<S, ReadonlyRecord<string, A>>) => Optional<S, A>
|
202 | /**
|
203 | * Return a `Optional` from a `Optional` focused on a required key of a `ReadonlyRecord`.
|
204 | *
|
205 | * @category combinators
|
206 | * @since 2.3.0
|
207 | */
|
208 | export declare const atKey: (
|
209 | key: string
|
210 | ) => <S, A>(sa: Optional<S, Readonly<Record<string, A>>>) => Optional<S, O.Option<A>>
|
211 | /**
|
212 | * Return a `Optional` from a `Optional` focused on the `Some` of a `Option` type.
|
213 | *
|
214 | * @category combinators
|
215 | * @since 2.3.0
|
216 | */
|
217 | export declare const some: <S, A>(soa: Optional<S, Option<A>>) => Optional<S, A>
|
218 | /**
|
219 | * Return a `Optional` from a `Optional` focused on the `Right` of a `Either` type.
|
220 | *
|
221 | * @category combinators
|
222 | * @since 2.3.0
|
223 | */
|
224 | export declare const right: <S, E, A>(sea: Optional<S, Either<E, A>>) => Optional<S, A>
|
225 | /**
|
226 | * Return a `Optional` from a `Optional` focused on the `Left` of a `Either` type.
|
227 | *
|
228 | * @category combinators
|
229 | * @since 2.3.0
|
230 | */
|
231 | export declare const left: <S, E, A>(sea: Optional<S, Either<E, A>>) => Optional<S, E>
|
232 | /**
|
233 | * Return a `Traversal` from a `Optional` focused on a `Traversable`.
|
234 | *
|
235 | * @category combinators
|
236 | * @since 2.3.0
|
237 | */
|
238 | export declare function traverse<T extends URIS>(
|
239 | T: Traversable1<T>
|
240 | ): <S, A>(sta: Optional<S, Kind<T, A>>) => Traversal<S, A>
|
241 | /**
|
242 | * @category combinators
|
243 | * @since 2.3.2
|
244 | */
|
245 | export declare function findFirst<A, B extends A>(
|
246 | refinement: Refinement<A, B>
|
247 | ): <S>(sa: Optional<S, ReadonlyArray<A>>) => Optional<S, B>
|
248 | export declare function findFirst<A>(predicate: Predicate<A>): <S>(sa: Optional<S, ReadonlyArray<A>>) => Optional<S, A>
|
249 | /**
|
250 | * @category combinators
|
251 | * @since 2.3.8
|
252 | */
|
253 | export declare function findFirstNonEmpty<A, B extends A>(
|
254 | refinement: Refinement<A, B>
|
255 | ): <S>(sa: Optional<S, ReadonlyNonEmptyArray<A>>) => Optional<S, B>
|
256 | export declare function findFirstNonEmpty<A>(
|
257 | predicate: Predicate<A>
|
258 | ): <S>(sa: Optional<S, ReadonlyNonEmptyArray<A>>) => Optional<S, A>
|
259 | /**
|
260 | * @category Invariant
|
261 | * @since 2.3.0
|
262 | */
|
263 | export declare const imap: <A, B>(f: (a: A) => B, g: (b: B) => A) => <E>(fa: Optional<E, A>) => Optional<E, B>
|
264 | /**
|
265 | * @category instances
|
266 | * @since 2.3.0
|
267 | */
|
268 | export declare const URI = 'monocle-ts/Optional'
|
269 | /**
|
270 | * @category instances
|
271 | * @since 2.3.0
|
272 | */
|
273 | export declare type URI = typeof URI
|
274 | declare module 'fp-ts/lib/HKT' {
|
275 | interface URItoKind2<E, A> {
|
276 | readonly [URI]: Optional<E, A>
|
277 | }
|
278 | }
|
279 | /**
|
280 | * @category instances
|
281 | * @since 2.3.0
|
282 | */
|
283 | export declare const Invariant: Invariant2<URI>
|
284 | /**
|
285 | * @category instances
|
286 | * @since 2.3.8
|
287 | */
|
288 | export declare const Semigroupoid: Semigroupoid2<URI>
|
289 | /**
|
290 | * @category instances
|
291 | * @since 2.3.0
|
292 | */
|
293 | export declare const Category: Category2<URI>
|
294 |
|
\ | No newline at end of file |