Thank you Rajith.

That answers my question.

On Thu, Jan 4, 2018 at 9:35 PM, Rajith Vitharana <[email protected]> wrote:

>
>
> On 5 January 2018 at 09:04, Rajith Vitharana <[email protected]> wrote:
>
>> Hi Shazni,
>>
>> Yes, you can, those are called structs, you can find a sample in [1]. For
>> the second question what you have to do is as follows
>>
>> struct Person {
>>     string firstname;
>>     string lastname;
>> }
>>
>> function <Person p1> getFirstName() (string) {
>>     return p1.firstname;
>> }
>>
>> so the invocation would be as follows
>>
>> function main(string[] args) {
>>     Person person = { firstName:"abc", lasstName:"cde"};
>>     string firstName = person.getFirstName();
>> }
>>
>> What we are doing here is we are binding the function to the given struct
>> type inside the angle brackets, so that the function needs to be invoked on
>> top of that struct type object. So inside the function, you can use that
>> object as well.
>> Hope this helps.
>>
>> [1] - https://ballerinalang.org/docs/by-example/structs
>>
>> Thanks,
>>
>> On 5 January 2018 at 07:58, Shazni Nazeer <[email protected]> wrote:
>>
>>> I am curious to know whether a developer can define his/her own types,
>>> under his preferred package, using ballerina? Excuse me if this is a basic
>>> question. I couldn't figure it out looking at the docs at [1]. Also, we
>>> have the type 'Time' with a given set of utility methods by default. Say if
>>> I want a type 'Calendar'. Can I do that? If yes, is there any examples?
>>>
>>> [1] https://ballerinalang.org/docs/
>>>
>>> --
>>> Shazni Nazeer
>>>
>>> Mob : +94 777737331
>>> LinkedIn : http://lk.linkedin.com/in/shazninazeer
>>>
>>> Blogs :
>>>
>>> https://medium.com/@mshazninazeer
>>> http://shazninazeer.blogspot.com
>>>
>>> <http://wso2.com/signature>
>>>
>>
>>
>>
>> --
>> Rajith Vitharana
>>
>> Associate Technical Lead,
>> WSO2 Inc. : wso2.com
>> Mobile : +94715883223
>> Blog : http://lankavitharana.blogspot.com/
>> <http://wso2.com/signature>
>>
>
>
>
> --
> Rajith Vitharana
>
> Associate Technical Lead,
> WSO2 Inc. : wso2.com
> Mobile : +94715883223
> Blog : http://lankavitharana.blogspot.com/
> <http://wso2.com/signature>
>



-- 
Shazni Nazeer

Mob : +94 777737331
LinkedIn : http://lk.linkedin.com/in/shazninazeer

Blogs :

https://medium.com/@mshazninazeer
http://shazninazeer.blogspot.com

<http://wso2.com/signature>
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to