### InnoShop Installer Test Directory Structure Source: https://github.com/innocommerce/innoshop/blob/master/innopacks/install/tests/README.md Illustrates the directory layout for the InnoShop installer tests, showing the organization of different test categories and the main test files within the project. ```text tests/ ├── Database/ # Database related tests ├── Environment/ # Environment check tests ├── InstallerTest.php # Main installer tests └── TestCase.php # Base test class ``` -------------------------------- ### Run All InnoShop Installer Tests Source: https://github.com/innocommerce/innoshop/blob/master/innopacks/install/tests/README.md Command to execute all test cases for the InnoShop installer using the Laravel Artisan test command, targeting the entire test directory. This is useful for a full regression test. ```bash php artisan test innopacks/install/tests ``` -------------------------------- ### Run Specific InnoShop Installer Test File Source: https://github.com/innocommerce/innoshop/blob/master/innopacks/install/tests/README.md Command to execute tests from a single specified file within the InnoShop installer test suite using the Laravel Artisan test command. This allows developers to focus on specific test areas. ```bash php artisan test innopacks/install/tests/InstallerTest.php ``` -------------------------------- ### Run Specific InnoShop Installer Test Method Source: https://github.com/innocommerce/innoshop/blob/master/innopacks/install/tests/README.md Command to execute a particular test method within a specific test file for the InnoShop installer, using the Laravel Artisan test command with a --filter option. This is ideal for debugging or re-running a single failed test. ```bash php artisan test --filter test_can_install_with_my_sql innopacks/install/tests/InstallerTest.php ``` -------------------------------- ### Objective-C Class Extension and AppDelegate Example Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/index.html This Objective-C code snippet demonstrates a class extension (`MyClass ()`) with atomic and nonatomic properties, an `NS_ENUM` definition, and an `AppDelegate` implementation. It includes an initializer (`initWithString:`) and a method (`doSomething:`) showcasing string formatting, concatenation, and basic conditional logic. ```Objective-C /* This is a longer comment That spans two lines */ #import "MyClass.h" #import @import BFrameworkModule; NS_ENUM(SomeValues) { aValue = 1; }; // A Class Extension with some properties @interface MyClass () @property(atomic, readwrite, assign) NSInteger anInt; @property(nonatomic, strong, nullable) NSString *aString; @end @implementation YourAppDelegate - (instancetype)initWithString:(NSString *)aStringVar { if ((self = [super init])) { aString = aStringVar; } return self; } - (BOOL)doSomething:(float)progress { NSString *myString = @"This is a ObjC string %f "; myString = [[NSString stringWithFormat:myString, progress] stringByAppendingString:self.aString]; return myString.length > 100 ? NO : YES; } @end ``` -------------------------------- ### Implement a Netty-based HTTP Server in Kotlin Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/index.html This Kotlin code defines an `HttpServer` class using Netty for handling HTTP requests. It initializes Netty's worker groups, bootstraps the server, and provides methods to start and gracefully stop the server, binding to a specified port from the application configuration. ```kotlin package org.wasabi.http import java.util.concurrent.Executors import java.net.InetSocketAddress import org.wasabi.app.AppConfiguration import io.netty.bootstrap.ServerBootstrap import io.netty.channel.nio.NioEventLoopGroup import io.netty.channel.socket.nio.NioServerSocketChannel import org.wasabi.app.AppServer public class HttpServer(private val appServer: AppServer) { val bootstrap: ServerBootstrap val primaryGroup: NioEventLoopGroup val workerGroup: NioEventLoopGroup init { // Define worker groups primaryGroup = NioEventLoopGroup() workerGroup = NioEventLoopGroup() // Initialize bootstrap of server bootstrap = ServerBootstrap() bootstrap.group(primaryGroup, workerGroup) bootstrap.channel(javaClass()) bootstrap.childHandler(NettyPipelineInitializer(appServer)) } public fun start(wait: Boolean = true) { val channel = bootstrap.bind(appServer.configuration.port)?.sync()?.channel() if (wait) { channel?.closeFuture()?.sync() } } public fun stop() { // Shutdown all event loops primaryGroup.shutdownGracefully() workerGroup.shutdownGracefully() // Wait till all threads are terminated primaryGroup.terminationFuture().sync() workerGroup.terminationFuture().sync() } } ``` -------------------------------- ### C ZMQ Multi-threaded Communication Example Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/index.html This C code snippet demonstrates a multi-threaded ZeroMQ (ZMQ) context management. It defines `acl_zmq_context` for thread-specific data and implements `zmq_thread` to handle various ZMQ operations (socket creation, binding, sending, receiving, polling) in a loop. `zmq_thread_init` initializes the thread, using semaphores for synchronization and a signal file descriptor for communication. ```C /* C demo code */ #include #include #include #include #include #include #include typedef struct { void* arg_socket; zmq_msg_t* arg_msg; char* arg_string; unsigned long arg_len; int arg_int, arg_command; int signal_fd; int pad; void* context; sem_t sem; } acl_zmq_context; #define p(X) (context->arg_##X) void* zmq_thread(void* context_pointer) { acl_zmq_context* context = (acl_zmq_context*)context_pointer; char ok = 'K', err = 'X'; int res; while (1) { while ((res = sem_wait(&context->sem)) == EINTR); if (res) {write(context->signal_fd, &err, 1); goto cleanup;} switch(p(command)) { case 0: goto cleanup; case 1: p(socket) = zmq_socket(context->context, p(int)); break; case 2: p(int) = zmq_close(p(socket)); break; case 3: p(int) = zmq_bind(p(socket), p(string)); break; case 4: p(int) = zmq_connect(p(socket), p(string)); break; case 5: p(int) = zmq_getsockopt(p(socket), p(int), (void*)p(string), &p(len)); break; case 6: p(int) = zmq_setsockopt(p(socket), p(int), (void*)p(string), p(len)); break; case 7: p(int) = zmq_send(p(socket), p(msg), p(int)); break; case 8: p(int) = zmq_recv(p(socket), p(msg), p(int)); break; case 9: p(int) = zmq_poll(p(socket), p(int), p(len)); break; } p(command) = errno; write(context->signal_fd, &ok, 1); } cleanup: close(context->signal_fd); free(context_pointer); return 0; } void* zmq_thread_init(void* zmq_context, int signal_fd) { acl_zmq_context* context = malloc(sizeof(acl_zmq_context)); pthread_t thread; context->context = zmq_context; context->signal_fd = signal_fd; sem_init(&context->sem, 1, 0); pthread_create(&thread, 0, &zmq_thread, context); pthread_detach(thread); return context; } ``` -------------------------------- ### Generate Infinite or Finite Streams with Ceylon loop Function Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/index.html This Ceylon code defines a `loop` function that generates a stream by repeatedly applying a given function (`next`) to the previous element, starting from an initial element (`first`). The stream continues until the `next` function returns `finished`, otherwise it's infinite. An example demonstrates creating a sequence like `{ 0, 2, 4, 6, 8 }`. ```ceylon "Produces the [[stream|Iterable]] that results from repeated application of the given [[function|next]] to the given [[first]] element of the stream, until the function first returns [[finished]]. If the given function never returns `finished`, the resulting stream is infinite. For example: loop(0)(2.plus).takeWhile(10.largerThan) produces the stream `{ 0, 2, 4, 6, 8 }`." tagged("Streams") shared {Element+} loop< Element >( "The first element of the resulting stream." Element first )( "The function that produces the next element of the stream, given the current element. The function may return [[finished]] to indicate the end of the stream." Element|Finished next(Element element) ) => let (start = first) object satisfies {Element+} { first => start; empty => false; function nextElement(Element element) => next(element); iterator() => object satisfies Iterator { variable Element|Finished current = start; shared actual Element|Finished next() { if (!is Finished result = current) { current = nextElement(result); return result; } else { return finished; } } }; }; ``` -------------------------------- ### Scala API Documentation: TraversableLike Trait Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html This snippet provides the comprehensive Scaladoc for the `scala.collection.TraversableLike` trait. It explains the foundational aspects of traversable collections in Scala, including the contract for implementing `foreach` and `newBuilder`, and discusses properties such as strictness and orderedness with examples. ```APIDOC /* __ *\ ** _________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** ** __\ \/ /__// __ |/ /__// __ | http://scala-lang.org/ ** ** /____/\___/|___/|/____/|___/| | ** ** |/ ** \* */ package scala.collection import generic._ import mutable.{ Builder, ListBuffer } import annotation.{tailrec, migration, bridge} import annotation.unchecked.{ uncheckedVariance => uV } import parallel.ParIterable /** A template trait for traversable collections of type `Traversable[A]`. * * $traversableInfo * @define mutability * @define traversableInfo * This is a base trait of all kinds of $mutability Scala collections. It * * implements the behavior common to all collections, in terms of a method * * `foreach` with signature: * {{{ * * def foreach[U](f: Elem => U): Unit * * }}} * Collection classes mixing in this trait provide a concrete * * `foreach` method which traverses all the * * elements contained in the collection, applying a given function to each. * * They also need to provide a method `newBuilder` * * which creates a builder for collections of the same kind. * * * A traversable class might or might not have two properties: strictness * * and orderedness. Neither is represented as a type. * * * The instances of a strict collection class have all their elements * * computed before they can be used as values. By contrast, instances of * * a non-strict collection class may defer computation of some of their * * elements until after the instance is available as a value. * * A typical example of a non-strict collection class is a * * * `scala.collection.immutable.Stream`. * * A more general class of examples are `TraversableViews`. * * * If a collection is an instance of an ordered collection class, traversing * * its elements with `foreach` will always visit elements in the * * same order, even for different runs of the program. If the class is not * * ordered, `foreach` can visit elements in different orders for * * different runs (but it will keep the same order in the same run).' * * A typical example of a collection class which is not ordered is a * * `HashMap` of objects. The traversal order for hash maps will * * depend on the hash codes of its elements, and these hash codes might * * differ from one run to the next. By contrast, a `LinkedHashMap` * * is ordered because it's `foreach` method visits elements in the * * order they were inserted into the `HashMap`. * * @author Martin Odersky * * @version 2.8 * * @since 2.8 * * @tparam A the element type of the collection * * @tparam Repr the type of the actual collection containing the elements. * * * @define Coll Traversable * * @define coll traversable collection */ trait TraversableLike[+A, +Repr] extends HasNewBuilder[A, Repr] with FilterMonadic[A, Repr] with TraversableOnce[A] with GenTraversableLike[A, Repr] with Parallelizable[A, ParIterable[A]] { self => import Traversable.breaks._ /** The type implementing this traversable */ protected type Self = Repr /** The collection of type $coll underlying this `TraversableLike` object. * * By default this is implemented as the `TraversableLike` object itself, * * but this can be overridden. */ def repr: Repr = this.asInstanceOf[Repr] /** The underlying collection seen as an instance of `$Coll`. * * By default this is implemented as the current collection object itself, * * but this can be overridden. */ protected[this] def thisCollection: Traversable[A] = this.asInstanceOf[Traversable[A]] /** A conversion from collections of type `Repr` to `$Coll` objects. * * By default this is implemented as just a cast, but this can be overridden. */ protected[this] def toCollection(repr: Repr): Traversable[A] = repr.asInstanceOf[Traversable[A]] /** Creates a new builder for this collection type. */ protected[this] def newBuilder: Builder[A, Repr] protected[this] def parCombiner = ParIterable.newCombiner[A] /** Applies a function `f` to all elements of this $coll. * * * Note: this method underlies the implementation of most other bulk operations. * * It's important to implement this method in an efficient way. * * * @param f the function that is applied for its side-effect to every element. * * The result of function `f` is discarded. * * * @tparam U the type parameter describing the result of function `f`. * * This result will always be ignored. Typically `U` is `Unit`, * * but this is not necessary. * * * @usecase def foreach(f: A => Unit): Unit */ def foreach[U](f: A => U): Unit ``` -------------------------------- ### API Documentation for Scala Collection copyToArray Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Documents the `copyToArray` method, which copies elements from the collection into a given array starting at a specified index, up to a maximum number of elements. ```APIDOC def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit /** Copies elements of this $coll to an array. * Fills the given array `xs` with at most `len` elements of * this $coll, starting at position `start`. * Copying will stop once either the end of the current $coll is reached, * or the end of the array is reached, or `len` elements have been copied. * * $willNotTerminateInf * * @param xs the array to fill. * @param start the starting index. * @param len the maximal number of elements to copy. * @tparam B the type of the elements of the array. * * @usecase def copyToArray(xs: Array[A], start: Int, len: Int): Unit */ ``` -------------------------------- ### Scala Functional List Filtering Example Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/index.html This Scala code snippet provides a functional example of filtering a list of integers based on a threshold. It defines a `filter` function that uses a nested, recursive `process` function to iterate through the list and build a new list containing only elements that meet the specified condition. ```Scala object FilterTest extends App { def filter(xs: List[Int], threshold: Int) = { def process(ys: List[Int]): List[Int] = if (ys.isEmpty) ys else if (ys.head < threshold) ys.head :: process(ys.tail) else process(ys.tail) process(xs) } println(filter(List(1, 9, 2, 8, 3, 7, 4), 5)) } ``` -------------------------------- ### Java Generic Class, Enum, and Inner Class Example Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/index.html This Java code snippet showcases an enum definition (`Enum`), a generic class (`Class`) implementing an interface (`MyInterface`), and a private inner class (`InnerClass`). It includes a static final member and methods demonstrating the use of generics and method calls within the class. ```Java import com.demo.util.MyType; import com.demo.util.MyInterface; public enum Enum { VAL1, VAL2, VAL3 } public class Class implements MyInterface { public static final MyType member; private class InnerClass { public int zero() { return 0; } } @Override public MyType method() { return member; } public void method2(MyType value) { method(); value.method3(); member = value; } } ``` -------------------------------- ### Slicing and Sub-Collection Operations on Scala Collections Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html These methods extract sub-collections based on indices or counts. `take` gets the first 'n' elements, `drop` skips the first 'n' elements, and `slice` extracts a range of elements. Internal helper methods are also shown. ```Scala def take(n: Int): Repr = slice(0, n) ``` ```Scala def drop(n: Int): Repr = if (n <= 0) { val b = newBuilder b.sizeHint(this) b ++= thisCollection result } else sliceWithKnownDelta(n, Int.MaxValue, -n) ``` ```Scala def slice(from: Int, until: Int): Repr = sliceWithKnownBound(math.max(from, 0), until) ``` ```Scala private[this] def sliceInternal(from: Int, until: Int, b: Builder[A, Repr]): Repr = { var i = 0 breakable { for (x <- this.seq) { if (i >= from) b += x i += 1 if (i >= until) break } } b.result } ``` ```Scala private[scala] def sliceWithKnownDelta(from: Int, until: Int, delta: Int): Repr = { val b = newBuilder if (un ``` -------------------------------- ### C++ Class Template, Enum, and String Literals Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/index.html This C++ code snippet illustrates a generic class `Class` inheriting from `BaseClass`, showcasing member variables and method definitions. It includes an anonymous namespace containing an enum, a Unicode string literal, a raw string literal, and a helper function. The example also demonstrates the implementation of a templated method outside the class definition. ```C++ #include #include "mystuff/util.h" namespace { enum Enum { VAL1, VAL2, VAL3 }; char32_t unicode_string = U"\U0010FFFF"; string raw_string = R"delim(anything you want)delim"; int Helper(const MyType& param) { return 0; } } // namespace class ForwardDec; template class Class : public BaseClass { const MyType member_; public: const MyType& Method() const { return member_; } void Method2(MyType* value); } template void Class::Method2(MyType* value) { std::out << 1 >> method(); value->Method3(member_); member_ = value; } ``` -------------------------------- ### Scala Collection Slicing Operations Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Internal helper methods for slicing collections based on specified start and end indices. These methods are typically used internally by higher-level slice functions. ```scala private[scala] def sliceWithKnownBound(from: Int, until: Int): Repr = { val b = newBuilder if (until <= from) b.result else { b.sizeHintBounded(until - from, this) sliceInternal(from, until, b) } } ``` -------------------------------- ### API Documentation for Scala Collection Inits Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Documents the `inits` method, which iterates over all prefixes of the collection. The first value is the collection itself, and the last is an empty collection. ```APIDOC def inits: Iterator[Repr] /** Iterates over the inits of this $coll. The first value will be this * $coll and the final one will be an empty $coll, with the intervening * values the results of successive applications of `init`. * * @return an iterator over all the inits of this $coll * @example `List(1,2,3).inits = Iterator(List(1,2,3), List(1,2), List(1), Nil)` */ ``` -------------------------------- ### API Documentation for Scala Collection stringPrefix Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Documents the `stringPrefix` method, which defines the prefix used in the `toString` representation of the collection. ```APIDOC def stringPrefix : String = { var string = repr.asInstanceOf[AnyRef].getClass.getName val idx1 = string.lastIndexOf('.' : Int) if (idx1 != -1) string = string.substring(idx1 + 1) val idx2 = string.indexOf('$') if (idx2 != -1) string = string.substring(0, idx2) string } /** Defines the prefix of this object's `toString` representation. * * @return a string representation which starts the result of `toString` * applied to this $coll. By default the string prefix is the * simple name of the collection class $coll. */ ``` -------------------------------- ### CodeMirror C-like Language Mode API Documentation Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/index.html This documentation describes CodeMirror's generic C-like language mode, detailing its configuration parameters and the various MIME types it supports for different programming languages. ```APIDOC CodeMirror C-like Language Mode: Description: Simple mode that tries to handle C-like languages as well as it can. Configuration Parameters: - keywords: object Description: An object whose property names are the keywords in the language. - useCPP: boolean Description: Determines whether C preprocessor directives are recognized. MIME types defined: - text/x-csrc (C) - text/x-c++src (C++) - text/x-java (Java) - text/x-csharp (C#) - text/x-objectivec (Objective-C) - text/x-scala (Scala) - text/x-vertex (Shader programs) - x-shader/x-fragment (Shader programs) - text/x-squirrel (Squirrel) - text/x-ceylon (Ceylon) ``` -------------------------------- ### API Documentation for Scala Collection View Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Documents the `view` methods, which create non-strict views of the collection or a slice of it. Views are lazy and do not create new collections immediately. ```APIDOC def view = new TraversableView[A, Repr] { protected lazy val underlying = self.repr override def foreach[U](f: A => U) = self foreach f } /** Creates a non-strict view of this $coll. * * @return a non-strict view of this $coll. */ ``` ```APIDOC def view(from: Int, until: Int): TraversableView[A, Repr] = view.slice(from, until) /** Creates a non-strict view of a slice of this $coll. * * Note: the difference between `view` and `slice` is that `view` produces * a view of the current $coll, whereas `slice` produces a new $coll. * * Note: `view(from, to)` is equivalent to `view.slice(from, to)` * $orderDependent * * @param from the index of the first element of the view * @param until the index of the element following the view * @return a non-strict view of a slice of this $coll, starting at index `from` * and extending up to (but not including) index `until`. */ ``` -------------------------------- ### Initialize CodeMirror Editor for Scala Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html JavaScript code to initialize a CodeMirror editor instance, linking it to a textarea element with the ID 'code'. The editor is configured to display line numbers, match brackets, use the 'ambiance' theme, and apply Scala syntax highlighting. ```JavaScript var editor = CodeMirror.fromTextArea(document.getElementById("code"), { lineNumbers: true, matchBrackets: true, theme: "ambiance", mode: "text/x-scala" }); ``` -------------------------------- ### API Documentation for Scala Collection toString Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Documents the `toString` method, which provides a string representation of the collection, typically including its prefix and elements. ```APIDOC override def toString = mkString(stringPrefix + "(", ", ", ")") /** Converts this $coll to a string. * * @return a string representation of this collection. By default this * string consists of the `stringPrefix` of this $coll, * followed by all elements separated by commas and enclosed in parentheses. */ ``` -------------------------------- ### Initialize CodeMirror Editors for Various C-like Languages Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/index.html This JavaScript snippet demonstrates how to initialize multiple CodeMirror text areas for different C-like programming languages (C, C++, Java, Objective-C, Scala, Kotlin, Ceylon). It configures each editor with line numbers, bracket matching, and specific language modes. It also sets up a global key binding for autocompletion (Ctrl/Cmd-Space). ```javascript var cEditor = CodeMirror.fromTextArea(document.getElementById("c-code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-csrc" }); var cppEditor = CodeMirror.fromTextArea(document.getElementById("cpp-code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-c++src" }); var javaEditor = CodeMirror.fromTextArea(document.getElementById("java-code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-java" }); var objectivecEditor = CodeMirror.fromTextArea(document.getElementById("objectivec-code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-objectivec" }); var scalaEditor = CodeMirror.fromTextArea(document.getElementById("scala-code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-scala" }); var kotlinEditor = CodeMirror.fromTextArea(document.getElementById("kotlin-code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-kotlin" }); var ceylonEditor = CodeMirror.fromTextArea(document.getElementById("ceylon-code"), { lineNumbers: true, matchBrackets: true, mode: "text/x-ceylon" }); var mac = CodeMirror.keyMap.default == CodeMirror.keyMap.macDefault; CodeMirror.keyMap.default[(mac ? "Cmd" : "Ctrl") + "-Space"] = "autocomplete"; ``` -------------------------------- ### API Documentation for Scala Collection Tails Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Documents the `tails` method, which iterates over all suffixes of the collection. The first value is the collection itself, and the last is an empty collection. ```APIDOC def tails: Iterator[Repr] /** Iterates over the tails of this $coll. The first value will be this * $coll and the final one will be an empty $coll, with the intervening * values the results of successive applications of `tail`. * * @return an iterator over all the tails of this $coll * @example `List(1,2,3).tails = Iterator(List(1,2,3), List(2,3), List(3), Nil)` */ ``` -------------------------------- ### Predicate-Based Query Methods for Scala Collections Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html These methods test elements within a collection against a given predicate. `forall` checks if all elements satisfy the predicate, `exists` checks if at least one element satisfies it, and `find` returns the first element that satisfies the predicate, if any. ```Scala def forall(p: A => Boolean): Boolean = { var result = true breakable { for (x <- this) if (!p(x)) { result = false; break } } result } ``` ```Scala def exists(p: A => Boolean): Boolean = { var result = false breakable { for (x <- this) if (p(x)) { result = true; break } } result } ``` ```Scala def find(p: A => Boolean): Option[A] = { var result: Option[A] = None breakable { for (x <- this) if (p(x)) { result = Some(x); break } } result } ``` -------------------------------- ### Accessing First and Last Elements of Scala Collections Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html These methods provide ways to retrieve the first or last elements of a collection, either directly (throwing an exception if empty) or wrapped in an `Option` for safe access. `tail` returns all elements except the first, and `init` returns all elements except the last. ```Scala def head: A = { var result: () => A = () => throw new NoSuchElementException breakable { for (x <- this) { result = () => x break } } result() } ``` ```Scala def headOption: Option[A] = if (isEmpty) None else Some(head) ``` ```Scala override def tail: Repr = { if (isEmpty) throw new UnsupportedOperationException("empty.tail") drop(1) } ``` ```Scala def last: A = { var lst = head for (x <- this) lst = x lst } ``` ```Scala def lastOption: Option[A] = if (isEmpty) None else Some(last) ``` ```Scala def init: Repr = { if (isEmpty) throw new UnsupportedOperationException("empty.init") var lst = head var follow = false val b = newBuilder b.sizeHint(this, -1) for (x <- this.seq) { if (follow) b += lst else follow = true lst = x } b.result } ``` -------------------------------- ### API Documentation for Scala Collection withFilter Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Documents the `withFilter` method, which creates a non-strict filter for the collection. Unlike `filter`, `withFilter` does not create a new collection but restricts the domain for subsequent operations. ```APIDOC def withFilter(p: A => Boolean): Any /** Creates a non-strict filter of this $coll. * * Note: the difference between `c filter p` and `c withFilter p` is that * the former creates a new collection, whereas the latter only * restricts the domain of subsequent `map`, `flatMap`, `foreach`, * and `withFilter` operations. * $orderDependent * * @param p the predicate used to test elements. * @return an object of class `WithFilter`, which supports * `map`, `flatMap`, `foreach`, and `withFilter` operations. * All these operat ``` -------------------------------- ### Partitioning and Grouping Scala Collections Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html These methods allow for reorganizing collection elements based on a predicate or a grouping function. `partition` splits a collection into two based on a boolean predicate, while `groupBy` creates a map where keys are derived from elements and values are collections of elements sharing that key. ```Scala def partition(p: A => Boolean): (Repr, Repr) = { val l, r = newBuilder for (x <- this) (if (p(x)) l else r) += x (l.result, r.result) } ``` ```Scala def groupBy[K](f: A => K): immutable.Map[K, Repr] = { val m = mutable.Map.empty[K, Builder[A, Repr]] for (elem <- this) { val key = f(elem) val bldr = m.getOrElseUpdate(key, newBuilder) bldr += elem } val b = immutable.Map.newBuilder[K, Repr] for ((k, v) <- m) b += ((k, v.result)) b.result } ``` -------------------------------- ### Scala Collection: FlatMap Elements Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Applies a function `f` to each element of this collection, where `f` returns a traversable collection. The results from all applications are then concatenated into a single new collection. The type of the new collection is determined by the `CanBuildFrom` implicit parameter. ```Scala def flatMap[B, That](f: A => GenTraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) for (x <- this) b ++= f(x).seq b.result } ``` -------------------------------- ### Scala Collection Conversion Methods Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Methods for converting the current collection to other common collection types like `Traversable`, `Iterator`, and `Stream`. ```scala def toTraversable: Traversable[A] = thisCollection ``` ```scala def toIterator: Iterator[A] = toStream.iterator ``` ```scala def toStream: Stream[A] = toBuffer.toStream ``` -------------------------------- ### Scala Collection: Filter and Map with Option Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Builds a new collection by applying an option-valued function `f` to all elements. Only elements for which `f` returns `Some(value)` are included in the new collection, with `value` being the mapped element. This effectively filters out `None` results while mapping `Some` values. The order of elements is preserved. ```Scala def filterMap[B, That](f: A => Option[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) for (x <- this) f(x) match { case Some(y) => b += y case _ => } b.result } ``` -------------------------------- ### Scala Collection: Map Elements Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Applies a function `f` to each element of this collection and returns a new collection containing the results. The type of the new collection is determined by the `CanBuildFrom` implicit parameter, allowing for flexible transformations across different collection types. ```Scala def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) b.sizeHint(this) for (x <- this) b += f(x) b.result } ``` -------------------------------- ### Scala WithFilter Class API Documentation Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html API documentation for the Scala `WithFilter` class, which provides monadic operations like `map`, `flatMap`, `foreach`, and `withFilter` on elements of a collection that satisfy a given predicate. This class is typically returned by the `withFilter` method on collections. ```Scala Class: WithFilter Description: A class supporting filtered operations. Instances of this class are returned by method `withFilter`. Constructor: WithFilter(p: A => Boolean) p: A => Boolean - The predicate used to filter elements. Method: map Description: Builds a new collection by applying a function to all elements of the outer collection that satisfy predicate `p`. Signature: def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That Parameters: f: A => B - The function to apply to each element. bf: CanBuildFrom[Repr, B, That] (implicit) - Builder factory. Returns: That - A new collection of type `That` resulting from applying the given function `f` to each element of the outer collection that satisfies predicate `p` and collecting the results. Method: flatMap Description: Builds a new collection by applying a function to all elements of the outer collection that satisfy predicate `p` and concatenating the results. Signature: def flatMap[B, That](f: A => GenTraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That Parameters: f: A => GenTraversableOnce[B] - The function to apply to each element. bf: CanBuildFrom[Repr, B, That] (implicit) - Builder factory. Returns: That - A new collection of type `That` resulting from applying the given collection-valued function `f` to each element of the outer collection that satisfies predicate `p` and concatenating the results. Method: foreach Description: Applies a function `f` to all elements of the outer collection that satisfy predicate `p`. The result of function `f` is discarded. Signature: def foreach[U](f: A => U): Unit Parameters: f: A => U - The function that is applied for its side-effect to every element. Returns: Unit Method: withFilter Description: Further refines the filter for this collection. All operations apply to those elements of this collection which satisfy the predicate `q` in addition to the predicate `p`. Signature: def withFilter(q: A => Boolean): WithFilter Parameters: q: A => Boolean - The predicate used to test elements. Returns: WithFilter - An object of class `WithFilter`, which supports `map`, `flatMap`, `foreach`, and `withFilter` operations. ``` -------------------------------- ### Scanning and Folding Operations on Scala Collections Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Scan operations are similar to folds but return a collection of intermediate results. `scanLeft` applies an operation from left to right, accumulating results, while `scanRight` does so from right to left. `scan` is a convenience method that delegates to `scanLeft`. ```Scala def scan[B >: A, That](z: B)(op: (B, B) => B)(implicit cbf: CanBuildFrom[Repr, B, That]): That = scanLeft(z)(op) ``` ```Scala def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) b.sizeHint(this, 1) var acc = z b += acc for (x <- this) { acc = op(acc, x); b += acc } b.result } ``` ```Scala @migration(2, 9, "This scanRight definition has changed in 2.9.\n" + "The previous behavior can be reproduced with scanRight.reverse." ) def scanRight[B, That](z: B)(op: (A, B) => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { var scanned = List(z) var acc = z for (x <- reversed) { acc = op(x, acc) scanned ::= acc } val b = bf(repr) for (elem <- scanned) b += elem b.result } ``` -------------------------------- ### Scala Collection: Collect Elements with Partial Function Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Applies a partial function `pf` to each element of this collection. If the partial function is defined for an element, the result is included in the new collection. Elements for which the partial function is not defined are skipped. The order of elements is preserved. ```Scala def collect[B, That](pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) for (x <- this) if (pf.isDefinedAt(x)) b += pf(x) b.result } ``` -------------------------------- ### Scala Collection Predicate-Based Transformations Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Methods for transforming collections based on a predicate function. These include `takeWhile` to take elements as long as a predicate is true, `dropWhile` to drop elements as long as a predicate is true, `span` to split into two collections based on a predicate, and `splitAt` to split at a specific index. ```scala def takeWhile(p: A => Boolean): Repr = { val b = newBuilder breakable { for (x <- this) { if (!p(x)) break b += x } } b.result } ``` ```scala def dropWhile(p: A => Boolean): Repr = { val b = newBuilder var go = false for (x <- this) { if (!p(x)) go = true if (go) b += x } b.result } ``` ```scala def span(p: A => Boolean): (Repr, Repr) = { val l, r = newBuilder var toLeft = true for (x <- this) { toLeft = toLeft && p(x) (if (toLeft) l else r) += x } (l.result, r.result) } ``` ```scala def splitAt(n: Int): (Repr, Repr) = { val l, r = newBuilder l.sizeHintBounded(n, this) if (n >= 0) r.sizeHint(this, -n) var i = 0 for (x <- this) { (if (i < n) l else r) += x i += 1 } (l.result, r.result) } ``` -------------------------------- ### Scala Collection: Filter Elements (Negated) Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Selects all elements from this collection that do *not* satisfy a given predicate `p`. It returns a new collection containing only the elements for which the predicate returns `false`. This method is efficiently implemented by negating the predicate and calling the `filter` method. ```Scala def filterNot(p: A => Boolean): Repr = filter(!p(_)) ``` -------------------------------- ### Scala Collection: Check if Empty Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Tests whether the collection contains no elements. It iterates through the collection, setting a flag to false if any element is found. This implementation uses a `breakable` block for early exit. Returns `true` if the collection is empty, `false` otherwise. ```Scala def isEmpty: Boolean = { var result = true breakable { for (x <- this) { result = false break } } result } ``` -------------------------------- ### Scala Collection: Filter Elements Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Selects all elements from this collection that satisfy a given predicate `p`. It returns a new collection containing only the elements for which the predicate returns `true`. The original order of elements is preserved in the resulting collection. ```Scala def filter(p: A => Boolean): Repr = { val b = newBuilder for (x <- this) if (p(x)) b += x b.result } ``` -------------------------------- ### Scala Collection: Concatenate Collections (++) Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Concatenates this collection with the elements of another traversable collection. It creates a new collection containing all elements of the current collection followed by all elements of the `that` collection. This method has overloads to handle different traversable types, leveraging `CanBuildFrom` for flexible return types. ```Scala def ++[B >: A, That](that: GenTraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) if (that.isInstanceOf[IndexedSeqLike[_, _]]) b.sizeHint(this, that.seq.size) b ++= thisCollection b ++= that.seq b.result } ``` ```Scala @bridge def ++[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = ++(that: GenTraversableOnce[B])(bf) ``` -------------------------------- ### Scala Collection: Prepend Collections (++:) Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Concatenates this collection with elements from another traversable collection, where the right operand determines the resulting collection's type. It creates a new collection with elements of `that` followed by elements of `this` collection. Overloads exist for different traversable types, leveraging `++` for efficiency where possible. ```Scala def ++:[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) if (that.isInstanceOf[IndexedSeqLike[_, _]]) b.sizeHint(this, that.size) b ++= that b ++= thisCollection b.result } ``` ```Scala def ++:[B >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = (that ++ seq)(breakOut) ``` -------------------------------- ### Scala Collection: Check for Definite Size Source: https://github.com/innocommerce/innoshop/blob/master/public/vendor/codemirror/mode/clike/scala.html Tests if the collection is known to have a finite size. For strict collections, this is always true. For non-strict collections like `Stream`, it returns `true` if all elements have been computed, and `false` otherwise. It's important to note that many collection methods may not work on infinite-sized collections. ```Scala def hasDefiniteSize = true ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.