Move forEach from Array to Task to Avoid Cyclic Dependency #126
Labels
breaking
effort: 1
Takes roughly 1 hour (w/ docs+testing)
good first issue
Good for newcomers
package: core
Related to the core libraries
state: approved
type: chore
work: obvious
Straightforward tasks with known solutions; follow best practices
Currently, the
forEach
method is defined in theArray
module and is responsible for iterating over each element while executing anIO
action. However, in NeoHaskell, side-effectful functions should useTask
instead ofIO
.Attempting to fix this by importing
Task
into theArray
module leads to a cyclic dependency. To resolve this,forEach
should be moved to theTask
module and implemented using theTraversable
type class. This would allowforEach
to work generically over any collection type that supportstraverse
, ensuring proper separation of concerns and avoiding cyclic dependencies.Expected Solution
forEach
implementation fromArray
toTask
.forEach
to useTraversable
instead of being specific toArray
.forEach
can be used infor
loops over any collection that implementsTraversable
.forEach
inArray
.Additional Context
This change aligns with NeoHaskell's design philosophy by ensuring that effectful computations use
Task
, rather thanIO
, and by leveragingTraversable
to generalize the iteration process.The text was updated successfully, but these errors were encountered: