Use exists?
Ruby:
package cisconacpoller | |
import scala.util.matching.Regex | |
trait Response | |
case class FailResponse(reason: String) extends Response | |
object NoSuchUserFailure extends FailResponse("No logged in user matches the criteria") | |
object InvalidCredentialsFailure extends FailResponse("Username or password is incorrect") |
def union[A](a: Set[A], b: Set[A]) { | |
var c = b | |
for(item <- a) { | |
c += item | |
} | |
c | |
} | |
OR: |
package com.proceranetworks.psm.leasepoller | |
package twpoller | |
import java.net.InetAddress | |
import java.nio.ByteBuffer | |
object ByteBufferImplicits { | |
implicit def byteBuffer2PimpedByteBuffer(buffer: ByteBuffer): PimpedByteBuffer = new PimpedByteBuffer(buffer) | |
} | |
class PimpedByteBuffer(buffer: ByteBuffer) { |
using terms from application "Messages" | |
on message received theMessage from theBuddy for theChat | |
set buddyId to id of theBuddy as text | |
if (makelower(theMessage) begins with "todo:") then | |
set trim1 to trim_line(theMessage, "todo:", 0) | |
set trim2 to trim_line(trim1, " ", 0) | |
tell application "Things 2" | |
set newToDo to make new to do ¬ | |
with properties {name:trim2, notes:"From: " & buddyId} |
import scalaz._ | |
import Scalaz._ | |
import scala.concurrent.Future | |
import scalaz.contrib.std.scalaFuture._ // typeclass instances for Scala Future | |
import scala.concurrent.ExecutionContext.Implicits.global // implicit execution context...you probably want a better one for real-world | |
type ErrorsOrT[M[+_], +A] = EitherT[M, NonEmptyList[String], A] // String could be your error type of choice | |
for { | |
thing1 <- EitherT(Future.successful(1.right)) |
import shapeless.{Poly1, Coproduct} | |
import shapeless.ops.coproduct.Folder | |
import argonaut.{_} | |
import argonaut.Argonaut._ | |
/** | |
* Generic encoder for Coproducts, will only resolve if all types in a Coproduct has an EncodeJson in scope | |
*/ | |
object CoproductToArgonautFolder extends Poly1 { |
/* Actions.scala */ | |
package actions | |
trait Action // Trait ~= abstract class / interface. Can't be directly instantiated. | |
sealed trait Feed extends Actions // Sealing is not required but important as the compiler will know that this class can't be extended by any other code, meaning we can do static typechecking that anything that is supposed to handle all cases of Feed actually does so. More reading: http://underscore.io/blog/posts/2015/06/02/everything-about-sealed.html | |
/* Objects are often used similar to packages in Scala. In this case you can just think of them as a grouping, no other special meaning */ | |
object Feed { | |
class FetchRequest extends Feed |
function generator(baseType) { | |
// Need to handle variable length argument lists | |
const fun = (payload) => ({ | |
type: fun, | |
payload: payload, | |
baseType: baseType | |
}); | |
return fun; | |
} |
// lib/actions.js | |
import identity from 'lodash/identity'; | |
export const ActionType = { | |
REQUEST: 'REQUEST', | |
SUCCESS: 'SUCCESS', | |
FAILURE: 'FAILURE' | |
}; | |
function createActionCreatorFlat(prefix, type, requestPayloadCreator = identity) { |