These are chat archives for evhub/coconut

12th
Jun 2017
José Carlos Micó
@mpjoseca_twitter
Jun 12 2017 10:55

Hi Evan! I have some problems when I have to use inheritance from classes that uses the init() method. For example, using SQLAlchemy I have this code in python:

class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, Sequence('user_id_seq'), primary_key=True)
    name = Column(String(50))
    fullname = Column(String(50))
    password = Column(String(12))

    def __repr__(self):
        return "<User(name='%s', fullname='%s', password='%s')>" % (
                                self.name, self.fullname, self.password)

And that's the Coconut version:

data User from Base:
    __tablename__ = 'users'
    id = Column(Integer, Sequence('user_id_seq'), primary_key=True)
    name = Column(String(50))
    fullname = Column(String(50))
    password = Column(String(12))

    def __repr__(self):
        return "<User(name='%s', fullname='%s', password='%s')>" % (
                                self.name, self.fullname, self.password)

From the SQLAlchemy tutorial (http://docs.sqlalchemy.org/en/latest/orm/tutorial.html): the init() method

Our User class, as defined using the Declarative system, has been provided with a constructor (e.g. init() method) which automatically accepts keyword names that match the columns we’ve mapped. We are free to define any explicit init() method we prefer on our class, which will override the default method provided by Declarative.

José Carlos Micó
@mpjoseca_twitter
Jun 12 2017 11:00
Another question is how to pass arguments to a function in pipeline style. With Coconut you could do 50 |> fun but you couldn't do (50, "Name") |> fun