export function whereDeepFn(map, collection) { map = mori.toClj(map); // create a reducing function that will test each attribute let reduce = (map) => mori.reduceKV( (func, mapKey, mapValue) => { return mori.comp(func, (record) => { if (record === false ) return false; let recordValue = mori.get(record, mapKey); if (mori.isCollection(mapValue)) { return (reduce(mapValue)(recordValue) === true ? record : false); } if ( record && mori.equals(recordValue, mapValue) ) { return record; } return false; }) }, result => { return (result !== false ? true : false); }, map ); return mori.into( mori.empty(collection), mori.filter(reduce(map), collection) ); }
/** * Adds the results to the existing search results for the * respective search term. Creates a new entry if none is * available. * * @param {Array} results */ receiveSearchResultsFrom(results) { const TERM = results._term, SOURCE = results._source, // check if term exists in state EXISTS = _m.get(this.state.results, TERM) !== null; // if not, make it a new seq let old = EXISTS ? _m.get(this.state.results, TERM) : _m.vector(), // convert results in vector newResults = _m.toClj(results); // add a _source field so the view can display where this result came from newResults = _m.map(res => _m.assoc(res, '_source', SOURCE), newResults); // add a _url field so that we can link inside yourturn newResults = _m.map( res => _m.assoc( res, '_url', getLocalUrlForService(SOURCE, _m.get(res, Services[SOURCE].id))), newResults); // append results in seq old = _m.into(old, newResults); // sort seq by matched_rank desc old = _m.sortBy(res => _m.get(res, 'matched_rank'), sortDesc, old); // PROFIT this.setState({ results: _m.assoc(this.state.results, TERM, old) }); }
it("preserves collection type", function () { var v = mori.vector(1, 2, 3); var v_ = mori.conj(v, 4); mori.subvec(v_, 0); // operation requires type to be a `Vector<*>` var n/*: ?number */ = mori.first(v_); // requires `number` type parameter to be preserved var m = mori.hashMap('foo', 1, 'bar', 2); var m_ = mori.into(m, mori.list(mori.vector('nao', 3))) mori.keys(m_); // operation requires `Map<*,*>` type to be preserved });
atom.updateIn(s.todos, function(list){ /** If we simply add a new item to a vector using mori.conj() it will be pushed at the end. Instead, we create a new vector containing the new item, and concatenate the new with the old one using mori.into(col1, col2) **/ var newTodo = _.vector(createTodo(todoText)); //append at list beginning return _.into(newTodo, list); });
wrapCore('with-meta', function (meta, obj) { if (obj === null || obj === undefined) { return null; } else if (mori.is_collection(obj)) { var result; if (mori.is_list(obj)) { result = mori.list(); } else if (mori.is_vector(obj)) { result = mori.vector(); } else if (mori.is_map(obj)) { result = mori.hash_map(); } var copy = mori.into(result, obj); copy.__meta = meta; return Promise.resolve(copy); } else if (typeof obj.withMeta === 'function') { return obj.withMeta(meta); } else { return Promise.reject(new Error(printString(obj) + ' does not support metadata')); } }),
it('upload csv', function() { let csv = [ ["name","email","language","experience"], ["jichao","*****@*****.**", "js","2"], ["sun","*****@*****.**", "js","2"] ] let [head, ...body] = csv; expect(m.toJs(m.into(m.vector(),xf(head),body))).toEqual([ { email: '*****@*****.**', experience: '2', language: 'js', name: 'jichao' }, { email: '*****@*****.**', experience: '2', language: 'js', name: 'sun' } ]) })
function surroundWithSea(map) { var seaTileConfig = M.toClj({ units: { Sea: M.toJs(M.get(everyUnitDefaultConfigDebug, 'Sea')), }, color: 'Gray', }); var rowLength = M.count(M.first(map)); var row = M.repeat(rowLength, seaTileConfig); var newMap = M.concat([row], butLast(M.rest(map)), [row]); // columns newMap = M.map(row => { return M.into( M.vector(), M.concat([seaTileConfig], butLast(M.rest(row)), [seaTileConfig]) ); }, newMap); return M.into(M.vector(), newMap); }
newMap = M.map(row => { return M.into( M.vector(), M.concat([seaTileConfig], butLast(M.rest(row)), [seaTileConfig]) ); }, newMap);
export function where(map, collection) { collection = mori.isMap(collection) ? mori.vals(collection) : collection; return mori.into( mori.empty(collection), mori.filter(matcher(map), collection)); }