Questions tagged [take]

Take is a common keyword or function name used to return a given number of elements, usually contiguously and from the beginning of a collection. Only use this tag for the take keyword or function name; usage such as "take a picture/screenshot" is out of scope.

Take functions usually only require two pieces of information: the number of elements to be returned from the sequence, and the sequence itself.

If take is a method in a particular library or language, it is called on the object and would only require the number parameter.

This concept is found in many languages and libraries, some of which are listed below.

Reference

142 questions
3
votes
3 answers

LINQ to SQL group by with take

I have a table that looks like this: Id GroupId Value and it has about 100 rows How can I return the top 10 rows for value but with no duplicating GroupId?
Taho
  • 833
  • 1
  • 10
  • 9
3
votes
1 answer

Take-while and take-nth in clojure

I'm trying to get n messages from a queue (using langohr). I have a working version but I would like to know if there is a better clojurist way of doing this: (def not-nil? (complement nil?)) (defn get_message [queue] (let [[_ payload] (lb/get…
Félix
  • 579
  • 4
  • 21
3
votes
1 answer

cassandra snapshot without nodetool but by java api only

How to take cassandra snapshot without nodetool but by java api only? I need to take snapshot of keyspace in cassandra by not using nodetool utility. I have to do it by java api If any one know how to do it kindly answer it . I have to implement..
gangatharan
  • 781
  • 1
  • 12
  • 28
3
votes
2 answers

Aborting a linq query after finding x items?

If I know there is only one matching item in a collection, is there any way to tell Linq about this so that it will abort the search when it finds it? I am assuming that both of these search the full collection before returning one item? var fred =…
GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103
2
votes
2 answers

RavenDB OrderByDescending and Take - Incorrect Results

This query was working for me until recently. I now have 135 InstallationSummary documents in my RavenDB. Instead of getting the most recent by start time, it's mostly working, but the last couple, most recent documents aren't showing up from this…
Bob Horn
  • 33,387
  • 34
  • 113
  • 219
2
votes
1 answer

`take n (take n xs) ≡ take n xs` for `Vec` in Agda

I want to prove a nearly trivial property of the take function for Vec in Agda. open import Data.Vec open import Data.Nat open import Relation.Binary.PropositionalEquality take-idempotent : ∀ n (xs : Vec ℕ n) → take n (take n xs) ≡ take n…
ymorii47
  • 21
  • 2
2
votes
1 answer

Ngrx store take(1), but reset after logout/login

So, imagine you have an ngrx store with a list of books. When you log in to your profile page you fetch your books using: this.store.dispatch(getBooks()); Which will trigger the effect: getBooks$ = createEffect(() => …
2
votes
2 answers

Take while running total smaller than value

I am trying to generate a list of even integers while the sum of the items in the list is less equal a given number. For instance if the threshold k is 20, then the expected output is [0;2;4;6;8] I can generate a list where the largest value is…
Thanasis K
  • 125
  • 6
2
votes
1 answer

What is the use of Take method ? Flutter & dart

take-->What role does it play (flutter and Dart) class Ticker { Stream tick({int ticks}) => Stream.periodic(Duration(seconds: 1), (x) { return ticks - x - 1; }).take(ticks); }
2
votes
4 answers

clojure split collection in chunks of increasing size

Hi I am a clojure newbie, I am trying to create a function that splits a collection into chunks of increasing size something along the lines of (apply #(#(take %) (range 1 n)) col) where n is the number of chunks example of expected output: with n…
maazza
  • 7,016
  • 15
  • 63
  • 96
2
votes
2 answers

Is it possible to combine rake task and bundle install into one command?

I have several rake tasks combined into one rake command. Just wondering is it possible to have one command run the "bundle install" within a rake task ? Or other way around ? So when I deploy my rails app to a new server all I need to do is just…
Jonathan
  • 598
  • 6
  • 16
  • 33
2
votes
2 answers

Angular/RxJs - Unsubscribing dependent http services using take(1)?

--Component.ts-- getGenCoreLabs() { this.checkinService .getLaboratories() .pipe( switchMap(outerResp => { const total = outerResp.headers.get(outerResp.headers.get('total')); return…
Usman Majied
  • 121
  • 1
  • 7
2
votes
1 answer

.Take(5) returns a count of 0 on an ObservableCollection

I'm trying to use LINQ to return the top 5 ping results from an ObservableCollection but the resulting IEnumerable has a count of 0. Can anyone explain why the lastFive object in the code below returns a count of 0 when .Take(5) is…
Darbio
  • 11,286
  • 12
  • 60
  • 100
2
votes
2 answers

Scala - List take - OrElse - with default value

I am trying to implement a way to take n from a Scala List, but if n > list.length, specify a default value. Something like takeOrElse. Say, val l = List(4, 6, 10) val taken = l.takeOrElse(5, 0) //List(4, 5, 6, 0, 0) Is there a way to do this…
irrelevantUser
  • 1,172
  • 18
  • 35
2
votes
2 answers

Numpy: Combine list of arrays by another array (np.choose alternative)

I have a list of numpy arrays, each of the same shape. Let's say: a = [np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), np.array([[11, 12, 13], [14, 15, 16], [17, 18, 19]]), …
Max16hr
  • 438
  • 2
  • 5
  • 20
1 2
3
9 10