Questions tagged [peek]

Refers to a non-destructive operation performed on sequential, collection-like data structures that have the notion of "top element" or "next element", such as stacks, queues and streams. The `peek` operation returns the value of the "top" (or "next") element without "consuming" that element, i.e. without removing that element from the data structure.

163 questions
5
votes
2 answers

Python: How to peek into a pty object to avoid blocking?

I am using pty to read non blocking the stdout of a process like this: import os import pty import subprocess master, slave = pty.openpty() p = subprocess.Popen(cmd, stdout = slave) stdout = os.fdopen(master) while True: if p.poll() != None: …
Woltan
  • 13,723
  • 15
  • 78
  • 104
5
votes
0 answers

3D Touch Peek and Pop messes up SpriteKit physics

I have implemented 3DTouch peek and pop actions in my game. Essentially I have a MenuScene and a GameScene. In the MenuScene I have 2 CollectionViewControllers (world select and level select). I can use peek and pop from the world select menu to get…
crashoverride777
  • 10,581
  • 2
  • 32
  • 56
5
votes
2 answers

synchronized LinkedList - peek

A LinkedList has convenient peek, pop, ... methods. Unfortunately, I need a thread-safe LinkedList. So, my first idea was to wrap it as follows: List list = Collections.synchronizedList(new LinkedList<>()); However, since the List interface…
bvdb
  • 22,839
  • 10
  • 110
  • 123
5
votes
1 answer

Peek into Conn without reading in go

I have a server net.Conn, and I'd like to peek into it before reading out bytes, to check if it's a plain text protocol the client is trying to use, or SSL/TLS. Checking http://golang.org/pkg/net/, it seems the Conn interface does not have anything…
ldx
  • 3,984
  • 23
  • 28
5
votes
2 answers

Peek on QTextStream

I would like to peek the next characters of a QTextStream reading a QFile, in order to create an efficient tokenizer. However, I don't find any satisfying solution to do so. QFile f("test.txt"); f.open(QIODevice::WriteOnly); f.write("Hello…
FabienRohrer
  • 1,794
  • 2
  • 15
  • 26
4
votes
2 answers

How to peek at the next value in a Javascript Iterator

Let's say I have an iterator: function* someIterator () { yield 1; yield 2; yield 3; } let iter = someIterator(); ... that I look at the next element to be iterated: let next = iter.next(); // {value: 1, done: false} ... and I then…
pwilcox
  • 5,542
  • 1
  • 19
  • 31
4
votes
4 answers

Java: Consumer interface in a stream doesn't work as expected

I've got 2 statements, I expected that they should "print" same result: Arrays.stream("abc".split("")).forEach(System.out::println);//first Arrays.stream("abc".split("")).peek(new Consumer() {//second @Override public void…
Troskyvs
  • 7,537
  • 7
  • 47
  • 115
4
votes
2 answers

StreamReader, C#, peek

I have a StreamReader that once in a while check if it has more to read from a simple text file. It uses peek property. The problem is that when I am using peek the position is changed, althougth not suppose to. FileStream m_fsReader = new…
Boris Raznikov
  • 2,373
  • 10
  • 34
  • 56
4
votes
3 answers

How to look at the next line of a file in Perl

I have a piece of code which opens up a file and parses it. This text document has a redundant structure and has multiple entries. I need to peek ahead within my loop to see if there is a new entry, if there is, I will be able to parse all of the…
user1876508
  • 12,864
  • 21
  • 68
  • 105
3
votes
4 answers

C++ unable to use peek() function in stack

I am trying to use the peek function in Visual Studio 2010 with these libraries: #include "stdafx.h" #include #include #include #include #include #include #include However, I…
Saliha Uzel
  • 141
  • 2
  • 5
  • 17
3
votes
3 answers

C equivalent to c++ cin.peek()

What is the equivalent of cin.peek() for C programming? I need to scan files for '/r' and '/r/n' (these are the end of line markers for DOS files) so I need to "peek" ahead to the next character if the current character is a '/r' Thanks!
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
3
votes
3 answers

How to code a peek method for Linked List

I am creating a linked list implementation for a stack. I've got the pop and push method done, but I can't seem to get the peek methods right. The code I have now in there, returns the memory address I think. Here is my code: public class…
Brock
  • 125
  • 1
  • 2
  • 10
3
votes
0 answers

multiple depth "peek definition" in vs code as in visual studio

in visual studio there is an option to keep "peeking definitions" from inside a definition, so you can always keep "entering" to the code depth, but easily can navigate between the "depths". multiple depth peek this make editing a code, and…
amir w
  • 31
  • 1
3
votes
3 answers

how to detect if Aero Peek mode is on

I'm trying to find out how to detect if windows desktop Aero Peek mode is on. In particular I'm need to detect if my window content is shown or drawn as a frame with transparent background. I know I can exclude my window from Aero Peek, but this not…
Nadine
  • 93
  • 4
3
votes
2 answers

Why PriorityQueue.peek() returns null, when PriorityQueue.size() > 0

I have a problem when PriorityQueue.peek() returns null when PriorityQueue.size() > 0 on android. I think this could be device issue. Does anybody have something in mind?
1 2
3
10 11