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