Return the first document matching the filter
4685
def one(cls, filter=None, **kwargs):
        """"""
        from mongoframes.queries import Condition, Group, to_refs

        # Flatten the projection
        kwargs['projection'], references, subs = \
                cls._flatten_projection(
                    kwargs.get('projection', cls._default_projection)
                    )

        # Find the document
        if isinstance(filter, (Condition, Group)):
            filter = filter.to_dict()

        document = cls.get_collection().find_one(to_refs(filter), **kwargs)

        # Make sure we found a document
        if not document:
            return

        # Dereference the document (if required)
        if references:
            cls._dereference([document], references)

        # Add sub-frames to the document (if required)
        if subs:
            cls._apply_sub_frames([document], subs)

        return cls(document)
1102234
def find_doc(self, name=None, ns_uri=None, first_only=False):
        
        return self.document.find(name=name, ns_uri=ns_uri,
            first_only=first_only)
964285
def first(self):
        """"""
        self.open()
        seq = SeqIO.parse(self.handle, self.format).next()
        self.close()
        return seq
254252
def get_documents(self):
        
        return self.session.query(Document).order_by(Document.name).all()
700778
public function getFirstRecord($filter = '', $order = ['.id'], $page = 1, $count = null, $dataDimensions = null)
    {
        $records = $this->getRecords($filter, $order, $page, $count, $dataDimensions);
        if ($records) {
            return array_shift($records);
        }

        return false;
    }
140757
def find_one(self, resource, req, **lookup):
        """"""

        if config.ID_FIELD in lookup:
            return self._find_by_id(resource=resource, _id=lookup[config.ID_FIELD], parent=lookup.get('parent'))
        else:
            args = self._es_args(resource)
            filters = [{'term': {key: val}} for key, val in lookup.items()]
            query = {'query': {'constant_score': {'filter': {'and': filters}}}}

            try:
                args['size'] = 1
                hits = self.elastic(resource).search(body=query, **args)
                docs = self._parse_hits(hits, resource)
                return docs.first()
            except elasticsearch.NotFoundError:
                return
1164482
def find_first(data, what):
    '''
    
    '''
    for i, line in enumerate(data):
        if contains(line, what):
            return i
            
    return None
132320
def search_first(self, *criterion, **kwargs):
        
        query = self._query(*criterion)
        query = self._order_by(query, **kwargs)
        query = self._filter(query, **kwargs)
        # NB: pagination must go last
        query = self._paginate(query, **kwargs)
        return query.first()
932916
def first(self):
        """"""
        page = self.get_page(num_elements=1)
        data = self.extract_data(page)
        if data:
            return data[0]
904078
def query_one(cls, *args, **kwargs):
        
        doc = cls._coll.find_one(*args, **kwargs)
        if doc:
            return cls.from_storage(doc)
801269
def find_first_match(basedir, string):
    
    matches = find(basedir, string)
    return matches[0] if matches else matches
719197
def first(self):
        

        if self.total and self.limit < self.total:
            return {'page[offset]': 0, 'page[limit]': self.limit}
        else:
            return None
943818
def find_first_object(self, ObjectClass, **kwargs):
        

        # Convert each name/value pair in 'kwargs' into a filter
        query = ObjectClass.query
        for field_name, field_value in kwargs.items():

            # Make sure that ObjectClass has a 'field_name' property
            field = getattr(ObjectClass, field_name, None)
            if field is None:
                raise KeyError("BaseAlchemyAdapter.find_first_object(): Class '%s' has no field '%s'." % (ObjectClass, field_name))

            # Add a case sensitive filter to the query
            query = query.filter(field==field_value)  # case sensitive!!

        # Execute query
        return query.first()
105541
function firstOrDefault(arr, filter) {
    for (const item of arr) {
        if (filter(item))
            return item;
    }
    return null;
}
303806
function(attrs, first) {
      if (!attrs || !Object.keys(attrs).length) return first ? void 0 : [];
      return this[first ? 'find' : 'filter'](function(model) {
        for (var key in attrs) {
          if (attrs[key] !== model.get(key)) return false;
        }
        return true;
      });
    }
90198
def findFirstHref(link_attrs_list, target_rel):
    """"""
    # XXX: TESTME
    matches = findLinksRel(link_attrs_list, target_rel)
    if not matches:
        return None
    first = matches[0]
    return first.get('href')
531952
def filter_query(key, expression):
    """"""
    if (isinstance(expression, dict)
            and len(expression) == 1
            and list(expression.keys())[0].startswith('$')):
        compiled_expression = compile_query(expression)
    elif callable(expression):
        def _filter(index, expression=expression):
            result = [store_key
                      for value, store_keys in index.get_index().items()
                      if expression(value)
                      for store_key in store_keys]
            return result
        compiled_expression = _filter
    else:
        compiled_expression = expression

    def _get(query_function, key=key, expression=compiled_expression):
        """Get document key and check against expression."""
        return query_function(key, expression)

    return _get