-
Notifications
You must be signed in to change notification settings - Fork 337
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
Add fp
export
#564
base: main
Are you sure you want to change the base?
Add fp
export
#564
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Hello, I find this task interesting and believe it will bring high productivity and convenience. Are there any additional updates? I’d love to collaborate on this. How about structuring the API interface as shown below? (This is just one suggestion.) import { array } from 'es-toolkit/fp';
array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]).pipe(
filter(isEven),
map(double),
join(", "),
) // Expect: "4, 8, 12, 16, 20" This structure holds several potential advantages
|
any progress on this thread? |
While I am trying to work as quickly as possible, but it is not a very high priority, so I am falling behind. I hope to be able to work on it this week. 🥲 |
The syntax for the pipe function is planned as follows. function toString(value: unknown) {
return `string:${value}`;
}
function toStringAsync(value: unknown) {
return Promise.resolve(`string:${value}`);
}
function length(value: string) {
return value.length;
}
const result = pipe(1, toString, length);
console.log(result); // 8
// Use pipe with async function
const asyncResult = await pipe(1, toStringAsync, length);
console.log(asyncResult); // 8
// Use pipe with curried function
const mapKeyResult = await pipe(
{ a: 1, b: 2 },
mapKeys((value, key) => key + value)
);
console.log(mapKeyResult); // { a1: 1, b2: 2 }
|
As far as I remember, this team was not interested in that work, but it is a work that I am interested in. But is there a reason why I have to copy the implementation? const pipeableCountBy = <T>(fn: (arg: T) => boolean) => (arr: Array<T>) => countBy(arr, fn);
pipe(
[1, 2, 3, 4],
pipeableCountBy(v => v % 2 == 0)
); If you're not going to make it in consideration of curring from the beginning, like fxts, that seems to be the best option. The advantage of p.spipe comes as a delay assessment. |
Maybe we don't need to copy original implementation even if there is a script for copying it... I agree with that idea. But it would be better to keep current design that 'auto-currying' the function by number of received argument to avoid situations like the one below. // BAD
import { omit } from "es-toolkit";
import { omit as pipableOmit } from "es-toolkit/fp";
const omitted = omit(obj, ['a', 'b']); // usage without pipe
// ...
pipe(
obj,
pipableOmit(['a', 'b'])
); // usage with pipe // GOOD
import { omit } from "es-toolkit/fp";
const omitted = omit(obj, ['a', 'b']); // usage without pipe
// ...
pipe(
obj,
omit(['a', 'b'])
); // usage with pipe I gonna fix the implementation and script to refer it, not copy the implementation of original one. |
I think that's a good idea, too. |
Move functions to
|
Add
es-toolkit/fp
export to support functional programming and pipeline syntax.TODO
Scripts
Codes
pipe
,map
,filter
...)Documents
es-toolkit/fp