Skip to content

Commit dccf7fb

Browse files
committed
pure should be applicative pure, from state -> FantasyX
1 parent c0d8580 commit dccf7fb

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

src/__tests__/fantasy-test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { mount } from 'enzyme';
33
import '@reactivex/rxjs'
4-
import { Plan, X, pure, map, lift2, lift, lift3, lift4, lift5, concat } from '..'
4+
import { Plan, X, fromPlan, map, lift2, lift, lift3, lift4, lift5, concat } from '..'
55
import * as rx from '../xs/rx'
66
import { Observable } from '@reactivex/rxjs'
77
import '@reactivex/rxjs/dist/cjs/add/observable/combineLatest'
@@ -31,7 +31,7 @@ interface CountProps {
3131

3232
let mountx = compose(mount, y => React.createFactory(X)({ x: rx }, y))
3333

34-
const fantasyX = pure<rx.URI, Intent, CountProps>((intent$) => {
34+
const fantasyX = fromPlan<rx.URI, Intent, CountProps>((intent$) => {
3535
return {
3636
update$: intent$.map((intent) => {
3737
switch (intent.type) {
@@ -153,7 +153,7 @@ describe('actions', () => {
153153
describe('concat', () => {
154154
let fantasyXB;
155155
beforeEach(() => {
156-
fantasyXB = pure<rx.URI, Intent, CountProps>((intent$) => {
156+
fantasyXB = fromPlan<rx.URI, Intent, CountProps>((intent$) => {
157157
return {
158158
update$: intent$.map((intent) => {
159159
switch (intent.type) {
@@ -244,7 +244,7 @@ describe('liftN', () => {
244244

245245
beforeEach(() => {
246246
let fan = [1, 2, 3, 4, 5];
247-
Fa = fan.map(i => pure<rx.URI, Intent, CountProps>(intent$ => {
247+
Fa = fan.map(i => fromPlan<rx.URI, Intent, CountProps>(intent$ => {
248248
return {
249249
update$: Observable.of(state => ({ count: i })),
250250
actions: {

src/fantasy/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { HKTS, streamOps } from '../xs'
1+
import { HKTS, streamOps, HKT } from '../xs'
22
import { FantasyX } from './fantasyx'
33
import { Plan, Update } from '../interfaces'
44
import { StateP, Partial } from './interfaces'
55
import { State } from './state'
66

7-
export function pure<E extends HKTS, I, S>(plan: Plan<E, I, S>): FantasyX<E, I, S> {
7+
export function fromPlan<E extends HKTS, I, S>(plan: Plan<E, I, S>): FantasyX<E, I, S> {
88
return new FantasyX<E, I, S>(intent$ => {
99
let { update$, actions } = plan(intent$)
1010
return {
@@ -16,6 +16,14 @@ export function pure<E extends HKTS, I, S>(plan: Plan<E, I, S>): FantasyX<E, I,
1616
})
1717
}
1818

19+
export function pure<E extends HKTS, I, S>(s: S) {
20+
return new FantasyX<E, I, S>(intent$ => {
21+
return {
22+
update$: streamOps.map<I, StateP<S>>(() => State.pure<S>(s), intent$ as HKT<I>[E])
23+
}
24+
})
25+
}
26+
1927
export function map<E extends HKTS, I, A>(
2028
f: (s: Partial<A>) => Partial<A>, fa: FantasyX<E, I, A>
2129
): FantasyX<E, I, A> {

src/forms/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { HKTS, streamOps, HKT } from '../xs'
2-
import { Update, pure } from '..'
2+
import { Update, fromPlan } from '..'
33
import { FantasyX } from '../fantasy/fantasyx'
44
import { Partial } from '../fantasy/interfaces'
55

@@ -11,7 +11,7 @@ export function xinput<
1111
E extends HKTS,
1212
I extends Event,
1313
S extends AnyProps>(name: keyof S) {
14-
return pure<E, I, S>(intent$ => {
14+
return fromPlan<E, I, S>(intent$ => {
1515
return {
1616
update$:
1717
streamOps.map<string, Update<S>>(

src/xs/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface XStream<F extends HKTS> {
1919
export class StreamOps<F extends HKTS> { }
2020
export interface StreamOps<F extends HKTS> {
2121
empty<A>(): HKT<A>[F]
22+
just<A>(a: A): HKT<A>[F]
2223
merge<A>(
2324
a: HKT<A>[F],
2425
b: HKT<A>[F]

src/xs/most.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Stream, empty, combineArray } from 'most'
1+
import { Stream, empty, just, combineArray } from 'most'
22
import { sync, SyncSubject, Subject } from 'most-subject'
33
import { Subscription, StreamOps } from './index'
44

@@ -9,6 +9,7 @@ declare module './index' {
99
}
1010

1111
StreamOps.prototype.empty = empty
12+
StreamOps.prototype.just = just
1213
StreamOps.prototype.merge = function(a, b) {
1314
return a.merge(b)
1415
}

src/xs/rx.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ declare module './index' {
1616

1717
StreamOps.prototype.empty = Observable.empty
1818

19+
StreamOps.prototype.just = Observable.of
20+
1921
StreamOps.prototype.combine = function(f, ...v) {
2022
return Observable.combineLatest(v, f)
2123
}

0 commit comments

Comments
 (0)