Quantcast
Channel: alvinalexander.com - sequence
Browsing all 25 articles
Browse latest View live

MySQL drop table and foreign keys tip - the FOREIGN_KEY_CHECKS variable

MySQL DROP TABLE FAQ: Help, my MySQL database tables have a lot of foreign keys, and as a result it's a pain to use the MySQL DROP TABLE command in my scripts; they keep failing because of all the...

View Article



Scala - How to create a range of characters (list, sequence)

Scala range FAQ: How can I easily create a range of characters in Scala, such as a range of alpha or alphanumeric characters?I learned recently that you can easily create a range of characters (a...

View Article

Scala - How to create a list of alpha or alphanumeric characters

While looking for code on how to create a random string in Scala, I came across this article, which shows one approach for creating a random string. For my brain today, it also shows a nice way to...

View Article

How to convert a Scala array (sequence) to string with mkString

Scala collections FAQ: How can I convert a Scalaarray to a String? (Or, more, accurately, how do I convert any Scala sequence to a String.)A simple way to convert a Scala array to a String is with the...

View Article

Scala - How to find the unique items in a List, Array, Vector (sequence)

Scala FAQ: How do I find the unique items in a List, Array, Vector, or other Scala sequence?Use the distinct method. Here's a simple example using a List of integers:scala> val x =...

View Article


Scala tip: How to extract a field from a sequence of objects to create a new...

A fun thing you can do with the map method on Scala sequences (Array, List, Seq, Vector, etc.), is convert a sequence of objects into a sequence of something else, typically extracting a field from the...

View Article

Converting a sequence of Scala objects to JSON using the Play Framework

The code in this blog post shows how to convert a Seq of Scala objects to their equivalent JSON representation. Specifically, I’m working on an application to display Twitter data, and I want to...

View Article

Scala: Extracting data from an array of XML elements

Problem: Your XML data has an array of elements, and you need to extract the first element, second element, or more generally, the Nth element, using Scala.SolutionThe following simplified version of...

View Article


How to use a Scala Set as a function predicate

There’s a nice Scala Set tip in the book, Functional Programming Patterns in Scala and Clojure. The tip is this:You can use a Set as a predicate to a function.(A predicate is just a function/method...

View Article


Getting a random element from a list of elements in Scala

In working on projects like SARAH and other apps where I’m trying to make a computer seem more “human”, I’ve been making my software reply to me in random ways. What I’ve found is that this ends up...

View Article

How to flatten a List of Lists in Scala with flatten

Scala problem: You have a list of lists (or more generally, a sequence of sequences) and want to create one list (sequence) from them.(The following solution comes from the Scala Cookbook, which I...

View Article

How to generate random numbers, characters, and sequences in Scala

Scala FAQ: How do I generate random numbers (or characters) in Scala, such as when testing an application, performing a simulation, and many other situations?SolutionCreate random numbers with the...

View Article

How to choose a collection class in Scala

This is an excerpt from the Scala Cookbook (partially re-worded for the internet). This is Recipe 10.2.Scala FAQ: How do I choose a Scala collection class to solve a particular problem?SolutionTo being...

View Article


Make the Vector class your default immutable sequence (Scala best practice)

This is an excerpt from the Scala Cookbook (partially re-worded for the internet). This is Recipe 10.7, “Make the Vector Class Your ‘Go To’ Immutable Sequence.”ProblemYou want a fast, general-purpose,...

View Article

Make the ArrayBuffer class your default mutable indexed sequence (Scala best...

This is an excerpt from the Scala Cookbook (partially re-worded for the internet). This is Recipe 10.8, “Make the Scala ArrayBuffer Class Your ‘Go To’ Mutable Indexed Sequence”ProblemYou want to use a...

View Article


Scala: How to use zipWithIndex or zip to create loop counters

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 10.11, “How to Use zipWithIndex or zip to Create Loop Counters”ProblemYou want to loop over a sequential...

View Article

How to extract a sequence of elements from a Scala Collection

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 10.18, “How to Extract a Sequence of Elements from a Scala Collection”ProblemYou want to extract a...

View Article


How to extract unique elements from a Scala sequence

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 10.21, “How to Extract Unique Elements from a Scala Sequence”ProblemYou have a collection that contains...

View Article

How to merge Scala sequential collections (List, Vector, ArrayBuffer, Array,...

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 10.22, “How to Merge Scala Sequential Collections”ProblemYou want to join two sequences into one...

View Article

How to populate Scala collections with a Range

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 10.25, “How to Populate a Scala Collection with a Range”ProblemYou want to populate a List, Array,...

View Article
Browsing all 25 articles
Browse latest View live




Latest Images