Skip to content

Ch12: array is not a monad #581

@antonklimov

Description

@antonklimov

sequence(Either.of, [Either.of('wing')]); // Right(['wing']) : how is this supposed to work? Array does not have .sequence.
sequence(Either.of, new List([Either.of("wing")])) might work here.

Later

const firstWords = compose(join(' '), take(3), split(' '));

// tldr :: FileName -> Task Error String
const tldr = compose(map(firstWords), readFile);

traverse(Task.of, tldr, ['file1', 'file2']);

Two problems here. First is again with array being treated as a monad. And second that join which is defined in support\index.js is a monadic join

// join :: Monad m => m (m a) -> m a
const join = (m) => m.join();

whereas here the join needs to be an array join like:

// arrayJoin :: String -> [String] -> String
const arrayJoin = curry((sep, arr) => arr.join(sep));
exports.arrayJoin = arrayJoin;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions