alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (MapOps.scala)

This example Scala source code file (MapOps.scala) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Scala by Example" TM.

Learn more about this Scala project at its project page.

Java - Scala tags/keywords

applicative, bkc, buildkeyconstraint, map, mapops, option, tomapopsfrommap, xmap

The MapOps.scala Scala example source code

package scalaz
package syntax
package std

final class MapOps[Map[_, _], BKC[_], K, A](self: Map[K, A])
                  (dict: scalaz.std.MapSubFunctions{
                     type XMap[A, B] = Map[A, B]
                     type BuildKeyConstraint[A] = BKC[A]
                   }) {
  final def alter(k: K)(f: (Option[A] => Option [A]))(implicit bk: BKC[K]): Map[K, A] = dict.alter(self, k)(f)
  final def intersectWithKey[B, C](m: Map[K, B])(f: (K, A, B) => C)(implicit bk: BKC[K]): Map[K, C] = dict.intersectWithKey(self, m)(f)
  final def intersectWith[B, C](m: Map[K, B])(f: (A, B) => C)(implicit bk: BKC[K]): Map[K, C] = dict.intersectWith(self, m)(f)
  final def mapKeys[K2: BKC](f: K => K2): Map[K2, A] = dict.mapKeys(self)(f)
  final def unionWithKey(m: Map[K, A])(f: (K, A, A) => A)(implicit bk: BKC[K]): Map[K, A] = dict.unionWithKey(self, m)(f)
  final def unionWith(m: Map[K, A])(f: (A, A) => A)(implicit bk: BKC[K]): Map[K, A] = dict.unionWith(self, m)(f)
  final def insertWith(k: K, v: A)(f: (A, A) => A)(implicit bk: BKC[K]): Map[K, A] = dict.insertWith(self, k, v)(f)
  final def getOrAdd[F[_]](k: K)(fa: => F[A])(implicit F: Applicative[F], bk: BKC[K]): F[(Map[K, A], A)] = dict.getOrAdd(self, k)(fa)
}

trait ToMapOps {
  import scalaz.std.{map => dict}

  implicit def ToMapOpsFromMap[K, V](m: Map[K, V]): MapOps[Map, dict.BuildKeyConstraint, K, V] = new MapOps[Map, dict.BuildKeyConstraint, K, V](m)(dict)
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala MapOps.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.