-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Curried and args switched #23
Comments
@dacz I agree it would be nice, will investigate for an FP variant |
can we also support // Current
const results = of(1, 2, 3)
.chain(source => filter(source, x => x % 2 === 0))
.chain(source => map(source, x => x * x));
import * as ix from 'ix/fp/es';
import flow from 'lodash.flow';
// Possible with args switched (and curried)
const results = ix.flow(
v => ix.of(...v),
ix.filter(x => x % 2 === 0),
ix.map(x => x * x),
)([1, 2, 3]);
assert(ix.flow === flow); |
@dacz @graingert is the |
@mattpodwysocki I'd like to be able to use a flow function to create other functions: import * as ix from 'ix/fp/es';
const process = ix.flow(
v => ix.of(...v),
ix.filter(x => x % 2 === 0),
ix.map(x => x * x),
);
process([1, 2, 3]); // a new iterable. (eg I'd like to be able to use the whole of IxJS without ever calling a method, or worrying about |
and if/when import * as ix from 'ix/fp/es';
const process = v => ix.of(...v)
|> ix.filter(x => x % 2 === 0)
|> ix.map(x => x * x)
);
process([1, 2, 3]); // a new iterable. |
@graingert that's already supported since import { AsyncIterableX as AsyncIterable } from 'ix';
import { map, filter } from 'ix/asynciterable';
const process = v => AsyncIterable.of(...v)
|> _ => filter(_, x => x % 2 === 0)
|> _ => map(_, x => x * x)
);
process([1, 2, 3]); Or you can use the import { AsyncIterableX as AsyncIterable } from 'ix';
import { map, filter } from 'ix/asynciterable/pipe';
const process = v => AsyncIterable.of(...v)
|> filter(x => x % 2 === 0)
|> map(x => x * x)
);
process([1, 2, 3]); |
@mattpodwysocki ah good stuff. how about a single namespace to import from? |
@graingert that's why we have an |
@mattpodwysocki I mean the whole library in fp/pipe form. Currently you're doing it like: import { AsyncIterableX as AsyncIterable } from 'ix';
import { map, filter } from 'ix/asynciterable/pipe'; I want: import { * as ix } from 'ix/fp'; |
@graingert the present structure is in place to support all three styles. At a minimum operators for the iterable/asyncIterable will stay separate, since they share names. Importing everything from the root is convenient, but won't tree shake. |
Would be nice to have some methods curried (and because of that switched arguments) to align with FP style.
Example:
The text was updated successfully, but these errors were encountered: