All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.memeticlabs.spark.rdd.trycatch.ValueWithSource.scala Maven / Gradle / Ivy

The newest version!
/**
	* Copyright 2017 Tristan Nixon
	*
	* Licensed under the Apache License, Version 2.0 (the "License");
	* you may not use this file except in compliance with the License.
	* You may obtain a copy of the License at
	*
	* http://www.apache.org/licenses/LICENSE-2.0
	*
	* Unless required by applicable law or agreed to in writing, software
	* distributed under the License is distributed on an "AS IS" BASIS,
	* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	* See the License for the specific language governing permissions and
	* limitations under the License.
	*
	* Created by Tristan Nixon on 7/13/17.
	*/
package org.memeticlabs.spark.rdd.trycatch

import scala.reflect.ClassTag

case class ValueWithSource[V, S]( value: V, source: S )

private[memeticlabs] object ValueWithSource
{
	def vwsMapFn[T,U,S]( f: (T) => U )
	                   ( vws: ValueWithSource[T,S] )
	                   (implicit tt: ClassTag[T],
	                    ut: ClassTag[U],
	                    st: ClassTag[S]): ValueWithSource[U,S] =
		ValueWithSource( f(vws.value), vws.source )

	def vwsFlatMapFn[T,U,S]( f: (T) => TraversableOnce[U] )
	                       ( vws: ValueWithSource[T,S] )
	                       (implicit tt: ClassTag[T],
	                        ut: ClassTag[U],
	                        st: ClassTag[S]): TraversableOnce[ValueWithSource[U,S]] =
		f(vws.value).map( u => ValueWithSource( u, vws.source ) )

	def vwsOrdering[T,S]( ord: Ordering[T] )
	                    (implicit tt: ClassTag[T], st: ClassTag[S]): Ordering[ValueWithSource[T,S]] =
		ord.on[ValueWithSource[T,S]]( _.value )
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy