score:5
Accepted answer
as per stream.map
documentation:
returns the stream resulting from applying the given function f to each element of this stream. this returns a lazy stream such that it does not need to be fully realized.
so using map
does not evaluate the stream, it produces a new stream.
score:2
don't map
but loop if you are after the side effect of println
.
scala> var flist = stream(new java.io.file("foo1") , new java.io.file("foo2"))
flist: scala.collection.immutable.stream[java.io.file] = stream(foo1, ?)
scala> flist.foreach(f => println(f.getabsolutepath))
/tmp/foo1
/tmp/foo2
scala> flist take 2 foreach(f => println(f.getabsolutepath))
/tmp/foo1
/tmp/foo2
Source: stackoverflow.com
Related Query
- Unable to map over a Stream of files
- Unable to use for comprehension to map over List within Future
- Unable to read files by using akka stream
- What's the new way to iterate over a Java Map in Scala 2.8.0?
- Scala - Iterator over all the lines in the files in a directory
- Scala: why can't I map a function accepting Seq[Char] over a collection of Strings
- scala build up string from iterating over map
- Reading JSON files into Spark Dataset and adding columns from a separate Map
- When map over a function is useful when you have andThen
- Unable to map on HList
- How to map over Hlist of objects that extend common trait?
- Map and reduce/fold over HList of scalaz.Validation
- Scala: Iterate over CSV files in a functional way?
- With scala, can I unapply a tuple and then run a map over it?
- Iterate with hasNext() and next() over an asynchronously generated stream of elements
- Functional way to map over a list with an accumulator in Scala
- Splitting the fs2 stream output to two files
- Akka stream - Splitting a stream of ByteString into multiple files
- Function to return List of Map while iterating over String, kmer count
- Iterate over an existing map against a list of tuples scala
- Type-level map over list of types
- How to ignore None values when I map over a collection
- Numeric Map Over With Functor
- How to use the traverse TypeClass to accumulate state based on the elements and then map over the state and elements?
- Result of map and mapAsync(1) in Akka Stream
- How to map a function over the HList of functions from a certain type to some type?
- Map a tagged HList (record) of functions over a record of their argument types
- Loop over java Map with scalate's mustache implementation
- Scala - map over sequence, stopping immediately when element cannot be processed
- Stream paginated API response over WebSocket using Akka
More Query from same tag
- What's the correct way to convert from StringBuilder to String?
- Flatten Array of tuples in Spark RDD
- Sbt to download list of jars specified
- Adding not-yet-saved objects to MappedManyToMany
- Defining an object as an operation on two other objects in Scala
- Copy a single dependency jar into a folder via build.sbt
- Union type with upper bound
- Scalac hanging on phase typer of RegexParser
- Liftweb - Convert List[Box[T]] into Box[List[T]]
- iterate over a list of custom object scala
- Caused by: java.lang.ClassNotFoundException: org.jets3t.service.ServiceException
- Scala Regex help on UCI data set
- Get and remove an arbitrary element from a mutable HashSet in Scala
- Play Framework with React in Webjar
- Intersection types with Covariance
- Scala lazy evaluation and apply function
- compile with sbt in emacs failed
- Generating a random String using functional principles
- Covariance in a function reference
- Lettuce 6.0.1.RELEASE deprecated .withPassword
- How to combine for-yield loop with if/else construct
- How to call Scala's Queue.enqueue(iter: Iterable[B])?
- Install scalatest in Scala IDE for Eclipse
- concurrent requests limit of Twitter-Finagle
- Error when importing into a spark dataframe a mssql table named as an integer
- Use the function form of "use strict". angularjs authentication (with scala, play framework)
- when testing for convergence using successive approximation technique, why does this code divide by the guess twice?
- What's the rationale behind curried functions in Scala?
- Inject a list of injected instances
- Throttle HTTP request on Akka/Spray