Code Monkey home page Code Monkey logo

Comments (5)

mikearnaldi avatar mikearnaldi commented on August 11, 2024 1
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

from effect.

wbhob avatar wbhob commented on August 11, 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>)

from effect.

mikearnaldi avatar mikearnaldi commented on August 11, 2024

#3318

Open for discussion what set of filtering functions would be best

from effect.

wbhob avatar wbhob commented on August 11, 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 🚀

from effect.

mikearnaldi avatar mikearnaldi commented on August 11, 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 🚀

of course! contributions are welcome

from effect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.