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

DbConnection or IO(DbConnection) #106

Closed
tonyday opened this issue Jul 23, 2015 · 2 comments
Closed

DbConnection or IO(DbConnection) #106

tonyday opened this issue Jul 23, 2015 · 2 comments

Comments

@tonyday
Copy link
Contributor

tonyday commented Jul 23, 2015

Hi

[@DrBoolean - Thank you. Great content and (for my taste) an eminently readable style. It is rare for technical book to make me chuckle.]

In Chapter 8 I am battling to figure out how connectDb has a type of Config -> Either(Error, IO(DbConnection)) given that Postgres.connect only has a type of Url -> DbConnection.
How does the DbConnection become an IO(DbConnection) ?
Am I confused or is there an IO.for missing somewhere ?

@xujihui1985
Copy link

yes, I have the same confuse,

// dbUrl :: Config -> Either(Error, url)
var dbUrl = function(c) {
  return (c.uname && c.pass && c.host && c.db)
    ? Right.of("db:pg://"+c.uname+":"+c.pass+"@"+c.host+"5432/"+c.db)
    : Left.of(Error("Invalid config!"));
}

dbUrl takes a config object and return an Either monad, and connectDb map over it, calling it should return an Either(Error, DbConnection)

//  connectDb :: Config -> Either(Error, DbConnection)
var connectDb = compose(map(Postgres.connect), dbUrl);

@DrBoolean
Copy link

Totally correct! Sorry, that's my mistake. Good eyes :) I'll update.

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

No branches or pull requests

3 participants