Skip to content
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

docs: no docs for filter() and filterMap() #3315

Open
wbhob opened this issue Jul 21, 2024 · 5 comments
Open

docs: no docs for filter() and filterMap() #3315

wbhob opened this issue Jul 21, 2024 · 5 comments
Labels
documentation Improvements or additions to documentation

Comments

@wbhob
Copy link

wbhob commented Jul 21, 2024

What is the type of issue?

Documentation is missing

What is the issue?

I'm new to Effect and still getting the hang of things. I see there's an Effect.filter and Effect.filterMap operator that I think does what I need it to do for this situation (succeed if predicate is true, otherwise stop), but I can't figure out how it works and I can't find usage docs for them, only the API reference for its signature. There's only one mention in the Getting Started Docs on the Micro page.

Where did you find it?

https://effect-ts.github.io/effect/effect/Effect.ts.html#filter
https://effect.website/docs/other/micro/effect-users

@wbhob wbhob added the documentation Improvements or additions to documentation label Jul 21, 2024
@mikearnaldi
Copy link
Member

import { Effect, Option } from "effect"

const filtered = Effect.filter(
  [0, 1, 2, "ok", "maybe"],
  (v) => v === "nooo" ? Effect.fail(new Error(v)) : Effect.sync(() => typeof v === "number")
)

const filterMapped = Effect.filterMap(
  [Effect.succeed(0), Effect.succeed(1), Effect.succeed(2)],
  (v) => v > 3 ? Option.none() : Option.some(v + 1)
)

as much as we'd love for the docs to be more complete you won't be able to find examples for every single function in there

@wbhob
Copy link
Author

wbhob commented Jul 24, 2024

Messed around a little in REPL and I think I'm understanding how these operators work. The way I think about it is:

// if your filter is simple
array.filter(() => boolean)
// if your filter is complicated or async
Effect.filter(array, (v) => Effect<boolean>)

// if you need to filter and simple map
array.map((v) => NonNullable<any> | null).filter(element => element !== null)
// if you want to filterMap items that are effects
Effect.filterMap(arrayOfEffects, (v) => Option)

Are there plans to add operators such as these? I feel like they could add some flexibility to filtering iterable effects.

Effect.filterEffects(Effect[], () => boolean)
Effect.filterMap(Iterable<A>, () => Effect<Option>)
Effect.fiterMapEffect(Effect[], () => Effect<Option>)

@mikearnaldi
Copy link
Member

#3318

Open for discussion what set of filtering functions would be best

@wbhob
Copy link
Author

wbhob commented Jul 24, 2024

Cool, will follow that issue. Are y'all open to docs contributions from the community? Can write a couple things as I find them and learn how they work to make it easier for the next person :) I have a feeling this package is gonna be big one day 🚀

@mikearnaldi
Copy link
Member

Cool, will follow that issue. Are y'all open to docs contributions from the community? Can write a couple things as I find them and learn how they work to make it easier for the next person :) I have a feeling this package is gonna be big one day 🚀

of course! contributions are welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants