Posts

Showing posts with the label lambda

Can lambda expressions be the alternative of polymorphism?

Image
Clash Royale CLAN TAG #URR8PPP Can lambda expressions be the alternative of polymorphism? I am learning lambda expressions and functional interfaces. We can directly write an implementation of the interface by the lambda expression. So I think, it could be the alternative for polymorphism. I have some code using polymorphism, interface Drawable { public void draw(); } class Shape { protected String name; public Shape(String name) { this.name = name; } } class Rectangle extends Shape implements Drawable { public Rectangle(String name) { super(name); } @Override public void draw() { System.out.println("I am "+this.name); System.out.println("Drawing rectangle with 2 equal sides."); } } class Square extends Shape implements Drawable { public Square(String name) { super(name); } @Override public void draw() { System.out.println("I am "+this.name); System...

AWS lambda VPC cannot reach internet with IG attached

Image
Clash Royale CLAN TAG #URR8PPP AWS lambda VPC cannot reach internet with IG attached I have an AWS lambda function that makes a request to the internet. When it makes the request with NO VPC, it's ok, but when I add it to the VPC, it stops working. I've attached an Internet Gateway to the VPC and created a NAT Gateway with RT to use outbound 0.0.0.0/0, but it stills not working. With 15seconds timeout, it's always throwing TO. Could you please help me? I've already follow these sites: - https://gist.github.com/reggi/dc5f2620b7b4f515e68e46255ac042a7 - http://derpturkey.com/lambda-vpc-and-internet-access-configuration/ Everything seems to be well configured. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Return null or new object using Optional object fields

Image
Clash Royale CLAN TAG #URR8PPP Return null or new object using Optional object fields We have a method, wherein we receive an Optional<SomeType> object. If the contained SomeType object is not null then we have to initialize a SomeOtherType object using the fields of the SomeType object and return that new object; otherwise we have to return null Optional<SomeType> SomeType SomeOtherType SomeType We found multiple different solutions where we perform this task with two statements, first retrieving the optional object and then second creating the other type object e.g. private SomeOtherType ourMethod() { SomeType someObject = getOptionalSomeTypeFromSomeWhere().orElse(null); return someObject != null ? new SomeOtherType(someObject.getField1(), someObject.getField2(), ...) : null; } Is it possible to cover this with one statement? So far we could not figure to do the null checks, accessing the fields, new object creation etc. all in one Basically a more complex case of...

Lambda expression in place of a left join

Image
Clash Royale CLAN TAG #URR8PPP Lambda expression in place of a left join I try to convert T-SQL to lambda expression but I met a problem. Data is not correct. This is my query SELECT A.* FROM (SELECT UserId, MIN(ID) AS ID FROM FingerMachineUsers GROUP BY UserId ) A LEFT OUTER JOIN FingerTimeSheets B ON A.ID = B.UserNo AND B.DayOfCheck = '2018-08-02 00:00:00.000' WHERE B.UserNo IS NULL This is my lambda expression dbContext.FingerMachineUsers .GroupBy(x => x.UserId) .Select(g => new { ID = g.Min(p => p.ID), UserId=g.Select(p => p.UserId) }) .GroupJoin(dbContext.FingerTimeSheets.Where(x=>x.DayOfCheck==shortDate),x=>x.ID,y=>y.UserNo,(x,y)=> new { ID = x, UserNo = y }) .SelectMany(x=>x.UserNo.DefaultIfEmpty(),(x,y)=>new { x.ID,y.UserNo}); Data returned is not correct. It's a lambda (yes - b before d) expression - not a "lamda" .....

capture alexa response json

capture alexa response json I would like to capture Alexa response and do some processing outside AWS Lambda. Maybe a view I would like to create with bar charts and on update it at runtime based on alexa response. How should I do that? I can create an independent alexa working skill. 2 Answers 2 From AWS Lambda, you need to make an HTTP Post request to your website where your bar chart is served so that you can update your bar chart. In order to post the response of the user, you need have an intent and then capture the user's response via slots. I am assuming you are using Node.JS for the implementation of skill, otherwise you can find similar section of documentation for the language of your choice. You can leverage Response Interceptor for your purpose. Follow this link: https://ask-sdk-for-nodejs.readthedocs.io/en/latest/Request-Processing.html#request-and-response-interceptors https://a...