Skip to content

Instantly share code, notes, and snippets.

Created November 10, 2014 10:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
package com.mechanitis.talks.stayingahead;
import com.mongodb.DBCollection;
import org.mongojack.JacksonDBCollection;
import org.mongojack.WriteResult;
public class BadLambdas {
private final DBCollection database;
public BadLambdas(final DBCollection database) {
this.database = database;
public Response saveOrder(final Order order) {
DBCollection orders = database.getCollection("orders");
JacksonDBCollection<Order, String> collection = JacksonDBCollection.wrap(orders, Order.class, String.class);
return save(order, collection,
() -> Response.created(URI.create(order.getId())).entity(order).build(),
() -> Response.serverError().build());
private Response save(final Order order,
final JacksonDBCollection<Order, String> collection,
final SuccessHandler successHandler,
final ErrorHandler errorHandler) {
WriteResult<Order, String> writeResult =;
if (writeResult == null) {
return errorHandler.onError();
} else {
return successHandler.onSuccess();
private interface SuccessHandler {
Response onSuccess();
private interface ErrorHandler {
Response onError();
Copy link

mwanji commented Nov 11, 2014

Do you have the "Lambdas the right way" code anywhere? In curious to see it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment