seq is short for sequence. A sequence is an ordered list of objects (or events). Like a set, it contains members (also called elements or terms), and the number of terms (possibly infinite) is called the length of the sequence. Unlike a set, order matters, and exactly the same elements can appear multiple times at different positions in the sequence. Sometimes, sequence is used as a generic name for both list, array and set for convenience.
Questions tagged [seq]
730 questions
20
votes
4 answers
Why clojure collections don't implement ISeq interface directly?
Every collection in clojure is said to be "sequable" but only list and cons are actually seqs:
user> (seq? {:a 1 :b 2})
false
user> (seq? [1 2 3])
false
All other seq functions first convert a collection to a sequence and only then operate on…

VitoshKa
- 8,387
- 3
- 35
- 59
19
votes
4 answers
How can I calculate pi using Bash command
I am learning bash scripting. While exploring the math functions i am came across a command which calculated the value of pi.
seq -f '4/%g' 1 2 99999 | paste -sd-+ | bc -l
Although i understand how the basic seq command works, I am unable to…

poorvank
- 7,524
- 19
- 60
- 102
18
votes
2 answers
Scala: map a Map to list of tuples
I tried to use Map.map to convert a map into a List of Tuples.
However this fails. I did the following experiments:
val m = Map(("a" -> 1), ("b" -> 2))
//> m : scala.collection.immutable.Map[String,Int] = Map(a -> 1, b -> 2)
val r1 =…

user2051561
- 838
- 1
- 7
- 21
17
votes
3 answers
Sliding window over seq
In Clojure, what would be the nicest way to have a sliding window over a (finite, not too large) seq? Should I just use drop and take and keep track of the current index or is there a nicer way I'm missing?

pmf
- 7,619
- 4
- 47
- 77
16
votes
2 answers
scala .seq vs .toSeq
In the Scala documentation, collections have both .seq and a .toSeq method defined on them. What is the difference between them, and why are they both there? I wasn't able to figure it out from reading the Scala collection documentation.

mp94
- 1,209
- 3
- 11
- 23
15
votes
1 answer
Bash seq to produce two separate sequences of numbers in a for loop
I would like to create a simple for bash loop that iterates over a sequence of numbers with a specific interval and then a different sequence of numbers, e.g.
for i in $(seq 0 5 15)
do
echo $i
done
But after interating through i=0, 5, 10, 15,…

Lily
- 303
- 1
- 2
- 8
15
votes
2 answers
Performance of sequences with while vs. for-do comprehensions, compared to direct `IEnumerable` implementation
(sorry for the long post, to skip directly to the question(s), see bottom)
(UPDATE: if you are revisiting, please see sections marked "update" ;)
I set myself to understand better what was going on under the hood with F# sequences. A task I needed…

Abel
- 56,041
- 24
- 146
- 247
15
votes
1 answer
How do I use tryPick to get the first element of a sequence?
I was trying to use Seq.first today, and the compiler says it has been deprecated in favor of Seq.tryPick. It says that it applies a function and returns the first result that returns Some. I guess I can just say fun x -> x!=0 since I know the first…

esac
- 24,099
- 38
- 122
- 179
14
votes
2 answers
Convert Seq to ArrayBuffer
Is there any concise way to convert a Seq into ArrayBuffer in Scala?

classicalist
- 235
- 1
- 2
- 10
14
votes
2 answers
(zsh brace expansion | seq) for character lists - how?
Bash allows me to write the statement,
$ for i in {h..k} ; do echo $i ; done
but zsh only allows number list expansion such as {8..13}.
What's the best workaround? Something like seq for characters...

nidi
- 270
- 4
- 8
14
votes
3 answers
How to produce cartesian product in bash?
I want to produce such file (cartesian product of [1-3]X[1-5]):
1 1
1 2
1 3
1 4
1 5
2 1
2 2
2 3
2 4
2 5
3 1
3 2
3 3
3 4
3 5
I can do this using nested loop like:
for i in $(seq 3)
do
for j in $(seq 5)
do
echo $i $j
done
done
is there…

Farvardin
- 5,336
- 5
- 33
- 54
13
votes
4 answers
How do turn a java Iterator-like object into a clojure sequence
I'm using the Sesame library to run SPARQL queries over an in-memory triple store.
I am using Clojure to achieve this.
A query result is a custom Iterator-like [1] object, so the clojure seq does not work on it out of the box.
What is the most…

laczoka
- 407
- 5
- 15
13
votes
1 answer
F# list to C# IEnumerable: most efficient method?
I'm currently working on an F# library with GUI written in C# and I would like to ask what is the best or correct way to pass an F# (generic) list to a C# code (generic IEnumerable).
I've found three ways so far:
[1; 2; 3; 4; 5;] |> List.toSeq
[1;…

eMko
- 1,147
- 9
- 22
13
votes
2 answers
What is the difference between Seq and IndexedSeq/LinearSeq in Scala?
In Scala Collection documentation, there is some clue to this question:
Trait Seq has two subtraits LinearSeq, and IndexedSeq. These do not add any new operations, but each offers different performance characteristics: A linear sequence has…

Milad Khajavi
- 2,769
- 9
- 41
- 66
12
votes
5 answers
Time cost of Haskell `seq` operator
This FAQ says that
The seq operator is
seq :: a -> b -> b
x seq y will evaluate x, enough to check that it is not bottom, then
discard the result and evaluate y. This might not seem useful, but it
means that x is guaranteed to be evaluated…

quant_dev
- 6,181
- 1
- 34
- 57