sequence

How to enumerate a list of non-string objects in Python?

There is a nice class Enum from enum, but it only works for strings. I'm currently using: for index in range(len(objects)): # do something with index and objects[index] I guess it's not the optimal solution due to the premature use of len. How is it possible to do it more efficiently? ...

Do recursive sequences leak memory?

I like to define sequences recursively as follows: let rec startFrom x = seq { yield x; yield! startFrom (x + 1) } I'm not sure if recursive sequences like this should be used in practice. The yield! appears to be tail recursive, but I'm not 100% sure since its being called from inside another IEnumerable. From...

F# using sequence cache correctly

I'm trying to use Seq.cache with a function that I made that returns a sequence of primes up to a number N excluding the number 1. I'm having trouble figuring out how to keep the cached sequence in scope but still use it in my definition. let rec primesNot1 n = {2 .. n} |> Seq.filter (fun i -> (primesNot1 (i / 2) |> S...

Best Practice to renumber items in a list? SQL or C#/VB.NET

I have a database table that has a SortOrder integer column. In the UI for adding and editing table items, I have a drop down list of Integer to let the user select where in the sortorder they would like this item to appear. My question is, say the list, {1,2,3,4,5,"last"}, if the user picks a a number, I want that to be the items SortOr...

How do I get the current sequence number in an iteration in F#?

Consider the following code to demonstrate the question: let sequence = Seq.initInfinite (fun _ -> "Element") Seq.iter (fun _ -> printf "Element no: ?") sequence Is it in any way possible to get the current sequence number (e.g. its rank) to print? ...

What would be the smartest way of running permutational code sequences to run via enumerator?

I have the following enum ( pseudo code ) enum RunSequence : int { ABCD = 1 , BCDA = 2 , DABC = 3 , .... } You get the idea ... Now if each letter represents some 4 lines of code , what would be the smartest way of building the logic for running those 16 lines of code in the desired sequence according to the RunSequence passed ...

How to "convert" a Dictionary into a sequence in F#?

How do I "convert" a Dictionary into a sequence so that I can sort by key value? let results = new Dictionary() results.Add("George", 10) results.Add("Peter", 5) results.Add("Jimmy", 9) results.Add("John", 2) let ranking = results ??????? |> Seq.Sort ?????? |> Seq.iter (fun x -> (... some function ...)) ...

Tracking which image in a list of images is clicked?

I have a set of images that correspond to video thumbnails. The user clicks a thumb which loads the browser. This would be simple enough, but I need to track which of the thumbs was clicked, so that I can automatically cue up the next video in sequence. My first thought was to do something like this (highly simplified example): <div ...

How to bind i at the end of a sequence using Seq.iteri

mySequence |> Seq.iteri (fun i x -> ...) ... How do I bind i at the end of the sequence? In other words how do I bind the value representing the number of iterations iterated by iteri? Of course I could create a ref and assign i for all iterations, but I wonder if there is a more elegant way? ...

Simple Sequence Generation?

I'm looking for an ultra-easy way to generate a list of numbers, 1-200. (it can be a List, Array, Enumerable... I don't really care about the specific type) Apparently .Net 4.0 has a Sequence.Range(min,max) method. But I'm currently on .Net 3.5. Here is a sample usage, of what I'm after, shown with Sequence.Range. public void ShowOut...

sequential autogenerated Id with help of linq

I have a class Booking public class Booking { public int Id { get; set; } public string From { get; set; } public string To { get; set; } } I create a List bookings with the help of linq and I want some mechanism with which I want to autogenerate the 'Id' property to increment by 1. I.e. if the List ...

Oracle Broken Sequence

I am using EJB3, JBoss AS 4.2.1 and Oracle 10g. The thing is every time i deploy to the AS the sequence is broken. Ex: when i am looking to the sequence from toad, its last value is 41 but the actual id which is set for the new entry is 1050. Do you have any idea or a known bug about this issue. Thanks. ...

How to force sequence of updates in DB

I have this table: old_id integer NOT NULL, new_id integer Now I want to update new_id with a sequence in such a way that the order of old_id is preserved. Basically: update table set new_id = sequence.NEXTVAL order by old_id Is something like this possible? If it matters, I'm on Oracle 10g. ...

jQuery Sequential List Problem

Hi Everyone This is probably very simple! I followed a tutorial from http://webdesignerwall.com/demo/jquery-sequential/jquery-sequential-list.html It works fine when there is one ol list on the page. But when there are 2 ol lists I have an issue: $(document).ready(function(){ $("ol.step li").each(function (i) { i = i+1; ...

How can I auto-generate unique fake names for users?

We would like to give each of users an alias so that we can refer to them in discussions while protecting their identity. These aliases should be unique. The easy way would be to simply use a SERIAL column, but ints aren't memorable. We would like to use real people names so that we can remember the aliases. The other easy way would be...

nextval sequence for varchar in sql?

HI there, i was wondering if there was a way of making a nextval sequence for a varchar value? I am using iSQL plus, oracle. For e.g. I have a sales table which consists of sale_id, prod_id, cust_name, sale_name. where i insert the data by doing the following: insert into sales select sale_id_seq.nextval, trunc(dbms_random.value(1,100))...

How to sequence elements based on attribute value in XSD

Given the following XML: <results> <result type="1">pass</result> <result type="2">pass</result> <result type="3">pass</result> </results> How do I create the XSD that forces the "result" elements to be ordered by the value of the "type" attribute? Also note, I don't necessarily need an ambiguous sort on the "type" ...

PNG image sequence playing problem

Hi, Ok, I have a button that, when pressed, should animate/play a png image sequence. My problem is - I press the button (button A) and the image sequence plays - which is good! but then I press (button A) again and nothing happens. - bad. but then... if I press (button A) a third time - the image sequence plays. So basically, the ...

How do you "ping pong" a UIView image sequence animation

Hi, I have a UIImageView which has a png image sequence loaded into it. My question is - Do you know of any way I can "ping pong" the animation sequence? So that it plays forward from 1-24 then plays backwards from 24-1 and loops. (technically it should be : 1-24 then 23-1 then 2-24 then 23-1...etc) - (void) loadAnim01 { mon01 = [[U...

Is there a practical way of migrating from identity columns to hilo keys?

I work with a database that depends heavily on identity columns. However as we have now moved all applications over to NHibernate I wanted to look into using HiLo as seems to be recommended with NHibernate. Are there any strategies to do this, or any common problems to watch out for? ...