MystPi / act

🎬 Compose stateful actions to simulate mutable state
https://hexdocs.pm/act
Apache License 2.0
16 stars 1 forks source link

Helpers for combining Actions with Stdlib #1

Closed darky closed 2 months ago

darky commented 3 months ago

Examples:

act/iterator

pub fn flat_map(
  iterator: Iterator(Action(a, x)),
  f: fn(action: Action(a, x)) -> Action(a, Iterator(b))
) -> Iterator(Action(a, b))

pub fn filter_map(
  iterator: Iterator(Action(a, x)),
  keeping_with f: fn(Action(a, x)) -> Action(a, Result(b, c)),
) -> Iterator(Action(a, b))

act/list

pub fn flat_map(
  lst: List(Action(a, x)),
  f: fn(action: Action(a, x)) -> Action(a, List(b))
) -> List(Action(a, b))

Etc...

MystPi commented 2 months ago

I'm happy to accept PRs for the list/flat_map one, however I would like it to be inside of the act module, possibly also with a better name to help out those who are not as familiar with FP jargon.

MystPi commented 2 months ago

On second thought I'm not sure how useful these functions would actually be to the average user. I think the way to go is to roll them yourself when needed in your projects.

I am more willing to add functions that are vital to a variety of projects. Highly specific functions that may only be useful in a few niche places won't add much value to the package. I'm trying to keep the package simple so newcomers to Gleam and FP in general won't be too overwhelmed by what's available.

darky commented 2 months ago

👌 no problem