@@ -3,7 +3,6 @@ import { Monad2 } from 'fp-ts/lib/Monad';
33import { map as readerMap , Reader } from 'fp-ts/lib/Reader' ;
44import { sequenceT } from 'fp-ts/lib/Apply' ;
55import { Omit } from 'typelevel-ts' ;
6- import { combineLatest , Observable } from 'rxjs' ;
76import {
87 ProductLeft ,
98 ProductMap ,
@@ -12,11 +11,10 @@ import {
1211import { deferReader } from '@devexperts/utils/dist/adt/reader.utils' ;
1312import { pipe , pipeable } from 'fp-ts/lib/pipeable' ;
1413import { memoOnce } from '@devexperts/utils/dist/function/memoize' ;
15- import { eqShallow } from '@devexperts/utils/dist/typeclasses/eq/eq.utils' ;
1614import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray' ;
1715import { array } from 'fp-ts/lib/Array' ;
18- import { URI as URIObservable } from 'fp-ts-rxjs/lib/Observable ' ;
19- import { instanceObservable } from './observable.utils ' ;
16+ import { instanceSink , sink , Sink , URI as URISink } from './sink2.utils ' ;
17+ import { strictEqual } from 'fp-ts/lib/Eq ' ;
2018
2119export const URI = '@devexperts/dx-utils//Context' ;
2220export type URI = typeof URI ;
@@ -26,14 +24,15 @@ declare module 'fp-ts/lib/HKT' {
2624 }
2725}
2826
29- export interface Context < E , A > extends Reader < E , Observable < A > > { }
27+ export interface Context < E , A > extends Reader < E , Sink < A > > { }
3028
31- const memo = memoOnce ( eqShallow ) ;
32- export const instanceContext : Monad2 < URI > & ProductLeft < URI > & ReaderM1 < URIObservable > = {
29+ const memo = memoOnce ( {
30+ equals : strictEqual ,
31+ } ) ;
32+ export const instanceContext : Monad2 < URI > & ProductLeft < URI > = {
3333 URI ,
34- ...getReaderM ( instanceObservable ) ,
35- asks : f => memo ( e => instanceObservable . of ( f ( e ) ) ) ,
36- productLeft : ( fa , fb ) => e => combineLatest ( fa ( e ) , fb ( e ) ) ,
34+ ...getReaderM ( instanceSink ) ,
35+ productLeft : ( fa , fb ) => e => sink . sequenceT ( fa ( e ) , fb ( e ) ) ,
3736} ;
3837
3938const sequenceT_ = sequenceT ( instanceContext ) ;
@@ -42,7 +41,7 @@ const sequenceArray = array.sequence(instanceContext);
4241const defer = < E extends object , A , K extends keyof E > (
4342 fa : Context < E , A > ,
4443 ...keys : K [ ]
45- ) : Context < Omit < E , K > , Context < Pick < E , K > , A > > => pipe ( deferReader ( fa , ...keys ) , readerMap ( instanceObservable . of ) ) ;
44+ ) : Context < Omit < E , K > , Context < Pick < E , K > , A > > => pipe ( deferReader ( fa , ...keys ) , readerMap ( instanceSink . of ) ) ;
4645
4746const combine : ProductMap < URI > = < E , A , R > ( ...args : NonEmptyArray < Context < E , A > | ProjectMany < A , R > > ) => {
4847 const last = args . length - 1 ;
@@ -51,11 +50,14 @@ const combine: ProductMap<URI> = <E, A, R>(...args: NonEmptyArray<Context<E, A>
5150 return instanceContext . map ( fas , as => project ( ...as ) ) ;
5251} ;
5352
53+ const key = < A > ( ) => < K extends PropertyKey > ( key : K ) : Context < Record < K , A > , A > => e => sink . of ( e [ key ] ) ;
54+
5455export const context = {
5556 ...instanceContext ,
5657 ...pipeable ( instanceContext ) ,
5758 sequenceT : sequenceT_ ,
5859 sequenceArray,
5960 combine,
6061 defer,
62+ key,
6163} ;
0 commit comments