-
-
Notifications
You must be signed in to change notification settings - Fork 231
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 do notation for Array #2678
Conversation
🦋 Changeset detectedLatest commit: 0f50aa2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 24 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine, but I must know:
why? What can this be used for? 🤔
Also please add more jsdocs, preferably with example 🙏🏻
Do in array is as important as do in stream it's used to build up on products basically (zipWith on steroids) |
I use this to generate independent props for stories in storybook const btnProps = pipe(
RA.Do,
RA.bind("size", () => ["small", "medium", "large"] as const),
RA.bind("theme", () => ["dark", "light", "contrast-light", "contrast-dark"] as const),
RA.bind("disabled", () => [false, true]),
RA.bind("loading", () => [false, true]),
RA.bind("leftIcon", () => [null, "arrow-left", "disk"]),
RA.bind("rightIcon", () => [null, "arrow-right", "save"]),
RA.bind("text", () => [lorem(1), lorem(3), lorem(10)])
) |
can be used to simulate "array comprehension"
Haskell [(x,y) | x <- [1,3,5], y <- [2,4,6], x < y]
-- Output: [(1,2),(1,4),(1,6),(3,4),(3,6),(5,6)] Effect import { Array as Arr, pipe } from "effect"
const result = pipe(
Arr.Do,
Arr.bind("x", () => [1, 3, 5]),
Arr.bind("y", () => [2, 4, 6]),
Arr.filter(({ x, y }) => x < y), // condition
Arr.map(({ x, y }) => [x, y] as const) // transformation
)
console.log(result)
/*
Output:
[ [ 1, 2 ], [ 1, 4 ], [ 1, 6 ], [ 3, 4 ], [ 3, 6 ], [ 5, 6 ] ]
*/ We could use this short explanation / example (without the Haskell bit) in the docs @KhraksMamtsov I've merged this PR that makes it easier to define the do notation for Array #2681 |
@gcanti If you don't mind, I'll add // doNotation.ts
export type EmptyScope<F extends TypeLambda> = Kind<F, never, never, never, {}>
// module
export const Do: doNotation.EmptyScope<ModuleTypeLambda> = ... |
I think our convention is not to export anything public from the |
I conceptualize this well 🤔 but the size doesn't explode? const btnProps = pipe(
RA.Do,
RA.bind("size", () => ["small", "medium", "large"] as const),
RA.bind("theme", () => ["dark", "light", "contrast-light", "contrast-dark"] as const),
RA.bind("disabled", () => [false, true]),
RA.bind("loading", () => [false, true]),
RA.bind("leftIcon", () => [null, "arrow-left", "disk"]),
RA.bind("rightIcon", () => [null, "arrow-right", "save"]),
RA.bind("text", () => [lorem(1), lorem(3), lorem(10)])
) thats an array of 1,296 members, no? This is not to say not to add this, I'm purely interested in the concept and utility |
Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz> Co-authored-by: Tim <hello@timsmart.co> Co-authored-by: Giulio Canti <giulio.canti@gmail.com>
Type
Description
Do notation (pipe version) for Array module.
Related