@Override public ListMonadic<A> reverse() { final List<A> target = newListBuilder(as); java.util.Collections.reverse(target); return mlist(target); }
@Override public ListMonadic<A> drop(int n) { int count = n; while (as.hasNext() && count > 0) { as.next(); count--; } return mlist(as); }
/** Find multiple objects with pagination wrapped in the list monad. */ public <A> Monadics.ListMonadic<A> findAllM(final EntityManager em, final String q, final int offset, final int limit, final P... params) { return mlist(this.<A>findAll(em, q, offset, limit, params)); }
@Override protected void run() { mlist(es).each(run); } };
/** * Returns the main suffix for this mime type, that identifies files containing data of this flavor. * <p> * For example, files with the suffix <code>mj2</code> will contain data of type <code>video/mj2</code>. * * @return the file suffix */ public Option<String> getSuffix() { return mlist(suffixes).headOpt(); }
@Override public ListMonadic<A> sort(Comparator<A> c) { final List<A> target = list(as); java.util.Collections.sort(target, c); return mlist(target); }
@Override public ListMonadic<A> filter(Function<? super A, Boolean> p) { final List<A> target = newListBuilder(); while (as.hasNext()) { A a = as.next(); if (p.apply(a)) { target.add(a); } } return mlist(target); }
@Override public <B, M extends Iterable<B>> ListMonadic<Tuple<A, B>> zip(M m) { final List<Tuple<A, B>> target = newListBuilder(); final Iterator<B> mi = m.iterator(); while (as.hasNext() && mi.hasNext()) { target.add(tuple(as.next(), mi.next())); } return mlist(target); }
@Override public <B> ListMonadic<Tuple<A, B>> zip(B[] bs) { final List<Tuple<A, B>> target = newListBuilder(bs.length); int i = 0; while (as.hasNext() && i < bs.length) { target.add(tuple(as.next(), bs[i++])); } return mlist(target); }
@Override public <B> ListMonadic<Tuple<A, B>> zip(Iterator<B> bs) { final List<Tuple<A, B>> target = newListBuilder(); while (as.hasNext() && bs.hasNext()) { target.add(tuple(as.next(), bs.next())); } return mlist(target); }
/** * Split a comma separated request param into a list of trimmed strings discarding any blank parts. * <p> * x=comma,separated,,%20value -> ["comma", "separated", "value"] */ public static Monadics.ListMonadic<String> splitCommaSeparatedParam(Option<String> param) { for (String p : param) return mlist(CSV_SPLIT.apply(p)).bind(trimToNil); return mlist(); }
@Override protected void run() { logger.info("[{}] Unregister service", self.getClass().getName()); for (ServiceRegistration reg : registrations.getServiceRegistrations()) reg.unregister(); mlist(registrations.getOnShutdown()).each(run); } };
/** Merge a list of objects into one (last one wins). */ public static Obj append(Obj... os) { final List<Prop> props = mlist(os).foldl(new ArrayList<Prop>(), new Function2<ArrayList<Prop>, Obj, ArrayList<Prop>>() { @Override public ArrayList<Prop> apply(ArrayList<Prop> props, Obj obj) { props.addAll(obj.getProps()); return props; } }); return new Obj(props); }
@Override public List<B> apply(List<A> as) { return mlist(as).fmap(f).value(); } };
/** * Returns <code>true</code> if this mime type is an equivalent for the specified type and subtype. * <p> * For example, a gzipped file may have both of these mime types defined, <code>application/x-compressed</code> or * <code>application/x-gzip</code>. * * @return <code>true</code> if this mime type is equal */ public boolean isEquivalentTo(String type, String subtype) { return eq(type, subtype) || mlist(equivalents).exists(eq); }
public Incident toIncident() { return new IncidentImpl(id, jobId, serviceType, processingHost, timestamp, severity, code, mlist(nullToNil(details)).map(JaxbIncidentDetail.toDetailFn).value(), mlist( nullToNil(descriptionParameters)).foldl(new HashMap<>(), new Function2<Map<String, String>, Param, Map<String, String>>() { @Override public Map<String, String> apply(Map<String, String> sum, Param param) { sum.put(param.getName(), param.getValue()); return sum; } })); }
/** Create a list of access control entries for a given role. */ public static Either<AccessControlEntry, List<AccessControlEntry>> entries(final String role, Tuple<String, Boolean>... actions) { final List<AccessControlEntry> entries = mlist(actions).map( new Function<Tuple<String, Boolean>, AccessControlEntry>() { @Override public AccessControlEntry apply(Tuple<String, Boolean> action) { return new AccessControlEntry(role, action.getA(), action.getB()); } }).value(); return right(entries); }
private static JSONArray toJsonSimple(Arr arr) { return mlist(arr.getVals()).foldl(new JSONArray(), new Function2<JSONArray, Val, JSONArray>() { @Override public JSONArray apply(JSONArray ja, Val val) { ja.add(toJsonSimple(val)); return ja; } }); }
public JaxbIncident(Incident incident) { this.id = incident.getId(); this.jobId = incident.getJobId(); this.serviceType = incident.getServiceType(); this.processingHost = incident.getProcessingHost(); this.timestamp = new Date(incident.getTimestamp().getTime()); this.severity = incident.getSeverity(); this.code = incident.getCode(); this.descriptionParameters = mlist(incident.getDescriptionParameters().entrySet()).map(Param.mkFn).value(); this.details = mlist(incident.getDetails()).map(JaxbIncidentDetail.mkFn).value(); }