tupled (A ⇒ B ⇒ C) GH
Convert curried function to a tupled one
between Random GH
Generate a random number between two others
Random.between(0, 10)
9
promote Ordering[A] GH
Promote occurences of the provided values when sorting
List(10, 7, 5, 2, 7).sorted(Ordering.Int.promote(5, 7))
List(5, 7, 7, 2, 10)
demote Ordering[A] GH
Demote occurences of the provided values when sorting
List(10, 7, 5, 2, 7).sorted(Ordering.Int.demote(5, 7))
List(2, 10, 5, 7, 7)
tap Either[L, R] GH
Perform one action or another
Left(1).tap(l ⇒ print("left: " + l), r ⇒ print("right: " + r))
Prints "left: 1"
Right(true).tap(l ⇒ print("left: " + l), r ⇒ print("right: " + r))
Prints "right: true"
tapLeft Either[L, R] GH
Perform action if Left
Left(1).tapLeft(l ⇒ print("left: " + l))
Prints "left: 1"
Right(true).tapLeft(l ⇒ print("left: " + l))
Does nothing
tapRight Either[L, R] GH
Perform action if Right
Left(1).tap(r ⇒ print("right: " + r))
Does nothing
Right(true).tap(r ⇒ print("right: " + r))
Prints "right: true"
addTo Either[L, R] GH
Adds values into growables
Left(1).addTo(ints, strings)
ints += 1
Right("foo").addTo(ints, strings)
strings += "foo"
removeFrom Either[L, R] GH
Removes values from a shrinkables
Left(1).removeFrom(ints, strings)
ints -= 1
Right("foo").removeFrom(ints, strings)
strings -= "foo"
getOrThrow Map[K, V] GH
Retrieve value associated with key or throw exception with message
Map(1 → 2).getOrThrow(1, "Alas, no 1")
2
Map(2 → 3).getOrThrow(1, "Alas, no 1")
throw new IllegalArgumentException("Alas no 1")
getOrThrow Map[K, V] GH
Retrieve value associated with key or throw exception
Map(1 → 2).getOrThrow(1, new Exception("No such element"))
2
Map(2 → 3).getOrThrow(1, new Exception("No such element"))
throw new Exception("No such element")
mapKeysEagerly Map[K, V] GH
Eagerly applies a function to each key
Map(1 → 2, 2 → 3).mapKeysEagerly(_ * 10)
Map(10 → 2, 20 → 3)
mapValuesEagerly Map[K, V] GH
Eagerly applies a function to each value
Map(1 → 2, 2 → 3).mapValuesEagerly(_ * 10)
Map(1 → 20, 2 → 30)
mapEntries Map[K, V] GH
Applies a function to each entry, result must be a Tuple2
Map(1 → 2, 2 → 3).mapEntries(k ⇒ v ⇒ (k * 10, v + 0.5))
Map(10 → 2.5, 20 → 3.5)
seqMapKeys Map[K, V] GH
Eagerly applies a function to each key, produces a Map if it never equals None
Map(2 → 4, 4 → 6).seqMapKeys(k ⇒ (k % 2 == 0).option(k / 2)))
Some(Map(1 → 4, 2 → 6))
Map(1 → 3).seqMapKeys(k ⇒ (k % 2 == 0).option(k / 2)))
None
seqMapValues Map[K, V] GH
Eagerly applies a function to each value, produces a Map if it never equals None
Map(2 → 4, 4 → 6).seqMapValues(v ⇒ (v % 2 == 0).option(v / 2)))
Some(Map(2 → 2, 4 → 3))
Map(1 → 3).seqMapValues(v ⇒ (v % 2 == 0).option(v / 2)))
None
seqMapEntries Map[K, V] GH
Applies a function to each entry, produces a Map if it never equals None
Map(2 → 4, 4 → 6).seqMapEntries(k ⇒ v => (k % 2 == 0).option((k / 2) -> (v / 2)))
Some(Map(1 → 2, 2 → 3))
Map(1 → 3).seqMapEntries(k ⇒ v => (k % 2 == 0).option((k / 2) -> (v / 2)))
None
collectKeys Map[K, V] GH
Applies a partial function to each key
Map(1 → 2, 2 → 3).collectKeys { case 2 → 20 }
Map(20 → 3)
updateKeys Map[K, V] GH
Applies a partial function to each key
Map(1 → 2, 2 → 3).updateKeys { case 2 → 20 }
Map(20 → 3)
updateKeys Map[K, V] GH
Applies a function to each key, retains only Somes
Map(1 → 2, 2 → 3).updateKeys(k ⇒ if (k == 2) Some(20) else None)
Map(20 → 3)
updateValue Map[K, V] GH
Update or remove a single entry
Map(1 → 2, 2 → 3).updateValue(1, _ ⇒ None)
Map(2 → 3)
collectValues Map[K, V] GH
Applies a partial function to each value
Map(1 → 2, 2 → 3).collectValues { case 2 ⇒ 20 }
Map(1 → 20)
updateValues Map[K, V] GH
Applies a partial function to each value
Map(1 → 2, 2 → 3).updateValues { case 2 ⇒ 20 }
Map(1 → 20)
updateValues Map[K, V] GH
Applies a function to each value, retains only Somes
Map(1 → 2, 2 → 3).updateValues(v ⇒ if (v == 2) Some(20) else None)
Map(1 → 20)
keyExists Map[K, V] GH
Determine if any key matches the predicate
Map(1 → 2).keyExists(_ > 1)
false
Map(2 → 3).keyExists(_ > 1)
true
valueExists Map[K, V] GH
Determine if any value matches the predicate
Map(1 → 2).valueExists(_ > 2)
false
Map(2 → 3).valueExists(_ > 2)
true
filterValues Map[K, V] GH
Retain those values that match a predicate
Map(1 → 2, 2 → 3).filterValues(_ > 2)
Map(2 → 3)
filterValuesNot Map[K, V] GH
Discard those value that match a predicate
Map(1 → 2, 2 → 3).filterValuesNot(_ > 2)
Map(1 → 2)
filterKeysNot Map[K, V] GH
Discard those keys that match a predicate
Map(1 → 2, 2 → 3).filterKeysNot(_ > 1)
Map(1 → 2)
findValue Map[K, V] GH
Search for a value that matches a predicate
Map(1 → 2).findValue(_ > 2)
None
Map(2 → 3).findValue(_ > 2)
Some(3)
findKey Map[K, V] GH
Search for a key that matches a predicate
Map(1 → 2).findValue(_ > 1)
None
Map(2 → 3).findValue(_ > 1)
Some(2)
sorted Map[K, V] GH
Sort map by keys
Map(1 → 2, 2 → 3).sorted(Ordering.Int.reverse)
SortedMap(2 → 3, 1 → 2)
reverse Map[K, V] GH
Reverse the keys & values, using the function to choose between keys
Map(1 → 2, 2 → 3, 3 → 3).reverse(_.min)
Map(2 → 1, 3 → 2)
reverseToMultiMap Map[K, V] GH
Reverse the keys & values, retaining all data
Map(1 → 2, 2 → 3, 3 → 3).reverseToMultiMap
Map(2 → Set(1), 3 → Set(2, 3))
containsAll Map[K, V] GH
Determine if the map contains all the provided keys
Map(1 → 2).containsAll(None)
true
Map(1 → 2).containsAll(Some(10))
false
Map(1 → 2).containsAll(Some(1))
true
containsAll Map[K, V] GH
Determine if the map contains all the provided keys
Map(1 → 2).containsAll(Nil)
true
Map(1 → 2).containsAll(List(10))
false
Map(1 → 2).containsAll(List(1))
true
containsAny Map[K, V] GH
Determine if the map contains any of the provided keys
Map(1 → 2).containsAny(None)
false
Map(1 → 2).containsAny(Some(10))
false
Map(1 → 2).containsAny(Some(1))
true
containsAny Map[K, V] GH
Determine if the map contains any of the provided keys
Map(1 → 2).containsAny(Nil)
true
Map(1 → 2).containsAny(List(10))
false
Map(1 → 2).containsAny(List(1))
true
containsEntry Map[K, V] GH
Determine if the map contains the provided entry
Map(1 → 2).containsEntry(1, 2)
true
Map(1 → 2).containsEntry(1, 1)
false
containsEntry Map[K, V] GH
Determine if the map contains the provided entry
Map(1 → 2).containsEntry((1, 2))
true
Map(1 → 2).containsEntry((1, 1))
false
get Map[K, V] GH
Lookup the provided key if Some
Map(1 → 2).get(None)
None
Map(1 → 2).get(Some(2))
None
Map(1 → 2).get(Some(1))
Some(2)
emptyTo Map[K, V] GH
Converts empty map to provided value, leaves other maps alone
Map(1 → 2).emptyTo(Map(2 → 3))
Map(1 → 2)
Map().emptyTo(Map(2 → 3))
Map(2 → 3)
uncons Map[K, V] GH
Convert to A depending on whether the map is empty or not
Map().uncons("empty", m ⇒ "non-empty: " + m.size)
"empty"
Map(1 → 2).uncons("empty", m ⇒ "non-empty: " + m.size)
"non-empty: 1"
entryFor.minKey Map[K, V] GH
The entry with the minimum key
Map(1 → 2, 2 → 3).entryFor.minKey
Some((1, 2))
Map(1 → 2, 2 → 3).entryFor.minKey(Ordering.Int.reverse)
Some((2, 3))
entryFor.maxKey Map[K, V] GH
The entry with the maximum key
Map(1 → 2, 2 → 3).entryFor.maxKey
Some((2, 3))
Map(1 → 2, 2 → 3).entryFor.maxKey(Ordering.Int.reverse)
Some((1, 2))
entryFor.minValue Map[K, V] GH
The entry with the minimum value
Map(1 → 2, 2 → 3).entryFor.minValue
Some((1, 2))
Map(1 → 2, 2 → 3).entryFor.minValue(Ordering.Int.reverse)
Some((2, 3))
entryFor.maxValue Map[K, V] GH
The entry with the maximum value
Map(1 → 2, 2 → 3).entryFor.maxValue
Some((2, 3))
Map(1 → 2, 2 → 3).entryFor.maxValue(Ordering.Int.reverse)
Some((1, 2))
entryFor.matchingKey Map[K, V] GH
The entry whose key matches the predicate
Map(1 → 2, 2 → 3).entryFor.matchingKey(_ > 2)
Some((2, 3))
entryFor.matchingValue Map[K, V] GH
The entry whose value matches the predicate
Map(1 → 2, 2 → 3).entryFor.matchingValue(_ > 3)
Some((2, 3))
keyFor.minValue Map[K, V] GH
The key whose entry has the minimum value
Map(1 → 2, 2 → 3).keyFor.minValue
Some(1)
Map(1 → 2, 2 → 3).keyFor.minValue(Ordering.Int.reverse)
Some(2)
keyFor.maxValue Map[K, V] GH
The key whose entry has the maximum value
Map(1 → 2, 2 → 3).keyFor.maxValue
Some(2)
Map(1 → 2, 2 → 3).keyFor.maxValue(Ordering.Int.reverse)
Some(1)
valueFor.minKey Map[K, V] GH
The value whose entry has the minimum key
Map(1 → 2, 2 → 3).valueFor.minKey
Some(2)
Map(1 → 2, 2 → 3).valueFor.minKey(Ordering.Int.reverse)
Some(3)
valueFor.maxKey Map[K, V] GH
The value whose entry has the maximum key
Map(1 → 2, 2 → 3).valueFor.maxKey
Some(3)
Map(1 → 2, 2 → 3).valueFor.maxKey(Ordering.Int.reverse)
Some(2)
andThenM Map[K, V] GH
Join the values of the map with the keys of another
Map(1 → 2, 2 → 3).andThenM(Map(2 → "two"))
Map(1 → "two")
composeM Map[K, V] GH
Join the keys of the map with the values of another
Map(1 → 2, 2 → 3).composeM(Map("two" → 2))
Map("two" → 3)
partitionKeysBy Map[K, V] GH
Applies a partial function to each key but retain the subset of the input where the function isn't defined
Map(1 → 2, 2 → 3).partitionKeysBy { case 2 ⇒ "two" }
(Map(1 → 2), Map("two" → 3))
partitionValuesBy Map[K, V] GH
Applies a partial function to each value but retain the subset of the input where the function isn't defined
Map(1 → 2, 2 → 3).partitionValuesBy { case 2 ⇒ "two" }
(Map(2 → 3), Map(1 → "two"))
partitionEntriesBy Map[K, V] GH
Applies a partial function to each entry but retain the subset of the input where the function isn't defined
Map(1 → 2, 2 → 3).partitionValuesBy { case (1, 2) ⇒ ("one", "two") }
(Map(2 → 3), Map("one" → "two"))
calcIfNonEmpty Map[K, V] GH
Calculate result if non empty, None otherwise
Map(1 → 2, 2 → 3).calcIfNonEmpty(_.length)
Some(2)
Map().calcIfNonEmpty(_.length)
None
mutable Map[K, V] GH
Convert to mutable Map
toMutable Map[K, V] GH
Convert to mutable Map
contramapKeys EncodeJson[Map[K, V]] GH
Converts map keys before encoding
mapEncoder.contramapKeys(_.reverse).encodeJson(Map("foo" → "bar"))
{ "oof" → "bar" }
contramapValues EncodeJson[Map[K, V]] GH
Converts map values before encoding
mapEncoder.contramapValues(_.reverse).encodeJson(Map("foo" → "bar"))
{ "foo" → "rab" }
xmapKeys CodecJson[Map[K, V]] GH
Converts map keys before encoding & after decoding
xmapValues CodecJson[Map[K, V]] GH
Converts map values before encoding & after decoding
xmap Numeric[A] GH
Converts to operate on a new type
implicitly[Numeric[Int]].xmap[String](_.toString, Integer.parseInt).plus("2", "3")
"5"
toFailureNel Option[E] GH
Converts Some to FailureNel & None to Success
Some(1).toFailureNel("succeed")
Failure(NonEmptyList(1))
None.toFailureNel("succeed")
Success("succeed")
getOrThrow Option[A] GH
Return value or throw exception with message
None.getOrThrow("No potatoes!")
throws NoSuchElementException("No potatoes")
Some("Potatoes").getOrThrow("No potatoes")
"Potatoes"
getOrThrow Option[A] GH
Return value or throw exception
None.getOrThrow(new PotatoException("No potatoes!"))
throws PotatoException("No potatoes")
Some("Potatoes").getOrThrow(new PotatoException("No potatoes"))
"Potatoes"
invert Option[A] GH
Convert Some to None and vice versa
None.invert(456)
Some(456)
Some(123).invert(456)
None
toTry Option[A] GH
Convert Some to Success and None to Failure
None.toTry
Failure(new NoSuchElementException)
Some(123).toTry
Success(123)
tap Option[A] GH
Perform one action or another
None.tap(println("none"), i ⇒ println(s"some: $i"))
prints "none"
Some(123).tap(println("none"), i ⇒ println(s"some: $i"))
prints "some: 123"
tapNone Option[A] GH
Perform action if None
None.tapNone(println("none"))
prints "none"
Some(123).tapNone(println("none"))
Does nothing
tapSome Option[A] GH
Perform action if Some
None.tapSome(i ⇒ println(s"some: $i"))
Does nothing
Some(123).tapSome(i ⇒ println(s"some: $i"))
prints "some: 123"
amass Option[A] GH
Applies partial function if Some
None amass { case 123 ⇒ Some(456) }
None
Some(321) amass { case 123 ⇒ Some(456) }
None
Some(123) amass { case 123 ⇒ Some(456) }
Some(456)
toSuccessNel Option[A] GH
Converts Some to Success & None to FailureNel
Some(1).toSuccessNel("fail")
Success(1)
None.toSuccessNel("fail")
Failure(NonEmptyList("fail"))
append NestedMap[K1, K2, V] GH
Append a value
Map(1 → Map(2 → 3)).append(1, 2, 4)
Map(1 → Map(2 → 4))
Map(1 → Map(2 → 3)).append(1, 3, 4)
Map(1 → Map(2 → 3, 3 → 4))
Map(1 → Map(2 → 3)).append(2, 3, 4)
Map(1 → Map(2 → 3), 2 → Map(3 → 4))
+ NestedMap[K1, K2, V] GH
Append a value
Map(1 → Map(2 → 3)) + ((1, 2, 4))
Map(1 → Map(2 → 4))
Map(1 → Map(2 → 3)) + ((1, 3, 4))
Map(1 → Map(2 → 3, 3 → 4))
Map(1 → Map(2 → 3)) + ((2, 3, 4))
Map(1 → Map(2 → 3), 2 → Map(3 → 4))
flipNesting NestedMap[K1, K2, V] GH
Flips the inner & outer keys
Map(1 → Map(2 → 3), 6 → Map(3 → 4, 4 → 5)).flipNesting
Map(2 → Map(1 → 3), 3 → Map(6 → 4), 4 → Map(6 → 5))
getOrEmpty NestedMap[K1, K2, V] GH
Retrive the values associated with a key or an empty collection
Map(1 → Map(2 → 3)).getOrEmpty(1)
Map(2 → 3)
Map(1 → Map(2 → 3)).getOrEmpty(2)
Map()
nestedMap.mapValuesEagerly NestedMap[K1, K2, V] GH
Eagerly applies a function to each value
Map(1 → Map(2 → 3)).nestedMap.mapValueEagerly(_ * 10)
Map(1 → Map(2 → 30))
nestedMap.mapKeysEagerly NestedMap[K1, K2, V] GH
Eagerly applies a function to each inner key
Map(1 → Map(2 → 3)).nestedMap.mapKeysEagerly(_ * 10)
Map(1 → Map(20 → 3))
closeAfter OutputStream GH
Close after applying a function
attemptClose OutputStream GH
Close & catch exceptions
closeIf OutputStream GH
Close if boolean is true
closeUnless OutputStream GH
Close if boolean is false
drain OutputStream GH
Drain all bytes from an InputStream, optionally closing each afterwards
<< OutputStream GH
Drain all bytes from an InputStream
buffered OutputStream GH
Wrap in a BufferedOutputStream
gzip OutputStream GH
Wrap in a GZIPOutputStream
writeN OutputStream GH
Write n bytes into an InputStream & throw if unable to
writeUpToN OutputStream GH
Write up to n bytes into an InputStream
asMap... NonEmptyList[V] GH
asMultiMap... NonEmptyList[V] GH
asInt Boolean GH
Converts to int
false.asInt
0
true.asInt
1
either.or Boolean GH
Construct a Right if true, Left if false
false.either(1).or("foo")
Left("foo")
true.either(1).or("foo")
Right(1)
option Boolean GH
Construct a Some if true, None if false
false.option(1)
None
true.option(1)
Some(1)
cond Boolean GH
Returns first value if true, second if false
false.cond(123, 456)
456
true.cond(123, 456)
123
implies Boolean GH
Logical implication
false implies false
true
false implies true
true
true implies false
false
true implies true
true
nor Boolean GH
Logical NOR
false nor false
true
false nor true
false
true nor false
false
true nor true
false
nand Boolean GH
Logical NAND
false nand false
true
false nand true
true
true nand false
true
true nand true
false
calc A GH
Applies a function
12.calc(_ + 3)
15
2.calc(_ * 3)
6
|> A GH
Applies a function
12 |> (_ + 3)
15
2 |> (_ * 3)
6
calcIf A GH
Applies a function if a predicate holds
1.calcIf(_ > 1)(_ * 10)
None
2.calcIf(_ > 1)(_ * 10)
Some(20)
calcUnless A GH
Applies a function if a predicate does not hold
1.calcUnless(_ > 1)(_ * 10)
Some(10)
2.calcUnless(_ > 1)(_ * 10)
None
calcPF A GH
Applies a partial function
1 calcPF { case 2 ⇒ 20 }
None
2 calcPF { case 2 ⇒ 20 }
Some(20)
transform A GH
Applies a partial function
1 transform { case 2 ⇒ 20 }
1
2 transform { case 2 ⇒ 20 }
20
tapIf A GH
Performs some actions if a predicate holds
1.tapIf(_ > 1)(print)
Does nothing
2.tapIf(_ > 1)(print)
prints "2"
tapUnless A GH
Performs some actions if a predicate does not hold
1.tapUnless(_ > 1)(print)
prints "1"
2.tapUnless(_ > 1)(print)
Does nothing
tapPF A GH
Performs an action
1 tapPF { case 2 ⇒ println("two !") }
Does nothing
2 tapPF { case 2 ⇒ println("two !") }
Prints "two !"
attempt A GH
Applies a function that can fail
1.attempt(_ ⇒ sys.error("boom !"))
Failure(Exception("boom !"))
1.attempt(_ * 2)
Success(2)
partialMatch A GH
Applies a partial function
1 partialMatch { case 2 ⇒ "two" }
None
2 partialMatch { case 2 ⇒ "two" }
Some("two")
lpair A GH
Applies a function & retain original value
1.lpair(_ * 2)
(2, 1)
rpair A GH
Retain original value & applies a function
1.rpair(_ * 2)
(1, 2)
filterSelf A GH
Retain original value if a predicate holds
1.filterSelf(_ > 1)
None
2.filterSelf(_ > 1)
Some(2)
ifSelf A GH
Retain original value if a predicate holds
1.ifSelf(_ > 1)
None
2.ifSelf(_ > 1)
Some(2)
filterNotSelf A GH
Retain original value if a predicate does not hold
1.filterNotSelf(_ > 1)
Some(1)
2.filterNotSelf(_ > 1)
None
unlessSelf A GH
Retain original value if a predicate does not hold
1.unlessSelf(_ > 1)
Some(1)
2.unlessSelf(_ > 1)
None
isOneOf A GH
Test if value is contained in a sequence
1.isOneOf(1, 2, 3)
true
4.isOneOf(1, 2, 3)
false
isNotOneOf A GH
Test if value is missing from a sequence
1.isNotOneOf(1, 2, 3)
false
4.isNotOneOf(1, 2, 3)
true
containedIn A GH
Test if value is contained in a set
1.containedIn(Set(1, 2, 3()
true
4.containedIn(Set(1, 2, 3))
false
notContainedIn A GH
Test if value is missing from a set
1.notContainedIn(Set(1, 2, 3))
false
4.notContainedIn(Set(1, 2, 3))
true
withFinally A GH
Applies a function and perform a cleanup action
1.withFinally(println)(_ * 2)
2 (and prints 1)
tryFinally A GH
Applies a function and perform a cleanup action
1.tryFinally(_ * 2)(println)
2 (and prints 1)
cond A GH
Applies a choice of functions depending on whether a predicate holds
1.cond(_ > 1)("true: " + _)("false: " + _)
false: 1
2.cond(_ > 1)("true: " + _)("false: " + _)
true: 2
addTo A GH
Adds value into a growable
1.addTo(ints)
ints += 1
removeFrom A GH
Removed value from a shrinkable
1.removeFrom(ints)
ints -= 1
unfold A GH
Builds a stream by repeatedly applying a function
64.unfold(i ⇒ if (i > 1) Some((i, i/2)) else None)
Stream(64, 32, 16, 8, 4, 2)
update A GH
Performs some actions
1.tap(println)
Prints 1
withSideEffect A GH
Performs some actions
1.withSideEffect(println)
Prints 1
tap A GH
Performs some actions
1.update(println)
Prints 1
bounded A GH
Constrain value to be between two others
0.bounded(1, 3)
1
2.bounded(1, 3)
2
5.bounded(1, 3)
3
ensure A GH
Validates predicate
1.ensure("<= 1")(_ > 1)
Failure("<= 1")
2.ensure("<= 1")(_ > 1)
Success(2)
ensureNel A GH
1.ensureNel("<= 1")(_ > 1)
Failure(NonEmptyList("<= 1"))
2.ensureNel("<= 1")(_ > 1)
Success(2)
partitionEithers GTL[Either[L, R]] GH
Partition eithers into lefts & rights
List(Right(3.0), Left(1), Right(4.0), Left(1)).partitionEithers
(List(1, 1), List(3.0, 4.0))
retainKeys mutable.Map[K, V] GH
Retain entries whose keys match the predicate
retainValues mutable.Map[K, V] GH
Retain entries whose values match the predicate
copyTo Array[A] GH
Copy subset of an array to another
Array(1, 2, 3, 4, 5).copyTo(2, Array(0, 0, 0, 0, 0), 1, 3)
Array(0, 3, 4, 5, 0)
naming ThreadFactory GH
Adapt threads created by factory to be named
threadFactory.naming(i ⇒ s"Thread: $i").newThread(...).getName
Thread: 0
+++= mutable.Builder[A, B] GH
Adds the elements of several traversables
(new ListBuffer[Int] +++= List(List(1, 2), List(3), List(4))).result()
List(1, 2, 3, 4)
on mutable.Builder[A, B] GH
Change the type of element consumed by the builder
(new ListBuffer[Double].on[Int](_.toDouble)) += 3).result()
List(3.0)
reset mutable.Builder[A, B] GH
Return result & clear
run mutable.Builder[A, B] GH
Update the builder & produce a result
new ListBufer[Int].run(_ += 1, _ ++= List(2, 3)
List(1, 2, 3)
collectHistogram GTL[A] GH
Calculate how many occurences of a property of each element
List("foo", "food", "bar", "oo").collectAttributeCounts {
case word if word.size > 2 ⇒ word.size
}
// 2 words of length 3, 1 of length 4
Map(3 → 2, 4 → 1)
optHistogram GTL[A] GH
Calculate how many occurences of a property of each element
List("foo", "food", "bar", "oo").optAttributeCounts(
word ⇒ if (word.size <= 2) None else Some(word.size)
)
// 2 words of length 3, 1 of length 4
Map(3 → 2, 4 → 1)
histogram GTL[A] GH
Calculate how many occurences of a property of each element
List("foo", "food", "bar", "oo").attributeCounts(
word ⇒ word.size
)
// 1 word length 1, 2 of length 3, 1 of length 4
Map(2 → 1, 3 → 2, 4 → 1)
onlyOption GTL[A] GH
Head if gtl has 1 element, None otherwise
Nil.onlyOption
None
Set(1).onlyOption
Some(1)
Vector(1, 2).onlyOption
None
onlyOrThrow GTL[A] GH
Head if list gtl 1 element, throws otherwise
Nil.onlyOrThrow(l ⇒ new Throwable("Not singleton: "l.length)
throws "Not singleton: 0"
Set(1).onlyOrThrow(s ⇒ new Throwable("Not singleton: "s.length)
1
Vector(1, 2).onlyOrThrow(v ⇒ new Throwable("Not singleton: "v.length)
throws "Not singleton: 2"
onlyEither GTL[A] GH
Right if gtl has 1 element, Left otherwise
Nil.onlyEither
Left(Nil)
Set(1).onlyEither
Right(1)
Vector(1, 2).onlyEither
Left(Vector(1, 2))
asMap.withEntries GTL[A] GH
Build a map by specifying entries
List(2, 4).asMap.withEntries(i ⇒ (i/2, i*2))
Map(1 → 4, 2 → 8)
asMap.withEntries GTL[A] GH
Build a map by specifying keys & values
List(2, 4).asMap.withEntries(i ⇒ i/2, i ⇒ i*2)
Map(1 → 4, 2 → 8)
asMap.withEntries GTL[A] GH
Build a nested map by specifying keys & values
List(2, 4).asMap.withEntries(i ⇒ i/2, i ⇒ i, i ⇒ i*2)
Map(1 → Map(2 → 4), 2 → Map(4 → 8))
asMap.withEntries GTL[A] GH
Build a nested map by specifying keys & values
List(2, 4).asMap.withEntries(
i ⇒ i/2, i ⇒ i, i ⇒ i*10, i ⇒ i*2
)
Map(
1 → Map(2 → Map(20 → 4)),
2 → Map(4 → Map(40 → 8))
)
asMap.withSomeEntries GTL[A] GH
Build a map by optionally specifying entries
List(2, 4).asMap.withSomeEntries(i ⇒ if (i == 2) Some((i/2, i*2)) else None)
Map(1, 4)
asMap.withSomeEntries GTL[A] GH
Build a map by optionally specifying keys & values
List(3, 5, 15).asMap.withSomeEntries(
i ⇒ if (i%3 == 0) Some(i/3) else None,
i ⇒ if (i%5 == 0) Some(i/5) else None
)
Map(5 → 3)
asMap.withPFEntries GTL[A] GH
Build a map by partially specifying entries
List(2, 4).asMap.withPFEntries { case 2 ⇒ (22, 222) }
Map(22 → 222)
asMap.withPFEntries GTL[A] GH
Build a map by partially specifying keys & values
List(1, 2, 3).asMap.withPFEntries({
case 1 ⇒ 11
case 3 ⇒ 33
}, {
case 2 ⇒ 222
case 3 ⇒ 333
})
Map(33 → 333)
asMultiMap.withEntries GTL[A] GH
Build a multi map by specifying entries
List(1, 2, 3).asMultiMap[List].withEntries(i ⇒ (i%2, i))
Map(0 → List(2), 1 → List(1, 3))
List(1, 2, 3).asMultiMap[Set].withEntries(i ⇒ (i%2, i))
Map(0 → Set(2), 1 → Set(1, 3))
asMultiMap.withEntries GTL[A] GH
Build a multi map by specifying keys & values
List(1, 2, 3).asMultiMap[List].withEntries(i ⇒ i%2, i ⇒ i))
Map(0 → List(2), 1 → List(1, 3))
List(1, 2, 3).asMultiMap[Set].withEntries(i ⇒ i%2, i ⇒ i))
Map(0 → Set(2), 1 → Set(1, 3))
asMultiMap.withEntries GTL[A] GH
Builds a nested multi map by specifying keys & values
List(1, 2, 3, 4).asMultiMap[List].withEntries(
i ⇒ i%2, i ⇒ i/2, i ⇒ i
)
Map(
0 -> Map(1 -> List(2), 2 -> List(4)),
1 -> Map(0 -> List(1), 1 -> List(3))
)
asMultiMap.withEntries GTL[A] GH
Builds a nested multi map by specifying keys & values...
List(1, 2, 3, 4).asMultiMap[List].withEntries(
i ⇒ i%2, i ⇒ i/2, i ⇒ i*10, i ⇒ i
)
Map(
0 -> Map(2 -> Map(40 -> List(4)), 1 -> Map(20 -> List(2))),
1 -> Map(1 -> Map(30 -> List(3)), 0 -> Map(10 -> List(1)))
)
List(1, 2, 3, 4).asMultiMap[Set].withEntries(
i ⇒ i%2, i ⇒ i/2, i ⇒ i*10, i ⇒ i
)
Map(
0 -> Map(2 -> Map(40 -> Set(4)), 1 -> Map(20 -> Set(2))),
1 -> Map(1 -> Map(30 -> Set(3)), 0 -> Map(10 -> Set(1)))
)
asMultiMap.withSomeEntries GTL[A] GH
asMultiMap.withSomeEntries GTL[A] GH
asMultiMap.withPFEntries GTL[A] GH
asMultiMap.withPFEntries GTL[A] GH
ungroupBy GTL[A] GH
partitionByPF GTL[A] GH
all GTL[A] GH
none GTL[A] GH
seqFold GTL[A] GH
seqMap GTL[A] GH
apoFold GTL[A] GH
ifSome Predicate[A] GH
Lift predicate to apply to Option
((i: Int) ⇒ i == 2).ifSome.apply(None)
false
((i: Int) ⇒ i == 2).ifSome.apply(Some(1))
false
((i: Int) ⇒ i == 2).ifSome.apply(Some(2))
true
and Predicate[A] GH
A predicate that's true only when both input predicates are true
((i: Int) ⇒ i % 3 == 0).and((i: Int) ⇒ i % 5 == 0).apply(1)
false
((i: Int) ⇒ i % 3 == 0).and((i: Int) ⇒ i % 5 == 0).apply(3)
false
((i: Int) ⇒ i % 3 == 0).and((i: Int) ⇒ i % 5 == 0).apply(5)
false
((i: Int) ⇒ i % 3 == 0).and((i: Int) ⇒ i % 5 == 0).apply(15)
true
or Predicate[A] GH
A predicate that's true when either input predicates are
((i: Int) ⇒ i % 3 == 0).or((i: Int) ⇒ i % 5 == 0).apply(1)
false
((i: Int) ⇒ i % 3 == 0).or((i: Int) ⇒ i % 5 == 0).apply(3)
true
((i: Int) ⇒ i % 3 == 0).or((i: Int) ⇒ i % 5 == 0).apply(5)
true
((i: Int) ⇒ i % 3 == 0).or((i: Int) ⇒ i % 5 == 0).apply(15)
true
exists Predicate[A] GH
A predicate that's true when there exists an element that passes
((i: Int) ⇒ i == 2).exists.apply(Nil)
false
((i: Int) ⇒ i == 2).exists.apply(List(1))
false
((i: Int) ⇒ i == 2).exists.apply(List(2))
true
((i: Int) ⇒ i == 2).exists.apply(List(1, 2))
true
guard Predicate[A] GH
Limit a function by a predicate
((i: Int) ⇒ i == 2).guard(_ * 10).lift(1)
None
((i: Int) ⇒ i == 2).guard(_ * 10).lift(2)
Some(20)
cond Predicate[A] GH
tailOption Stream[A] GH
The tail of the stream if it is not empty, None otherwise
Stream.empty[Int].tailOption
None
uncons Stream[A] GH
Convert to B depending on whether the stream is empty or not
Stream.empty.uncons("[]", s ⇒ s"[${s.length} elements]"
"[]"
Stream(1, 2, 3).uncons("[]", s ⇒ s"[${s.length} elements]"
"[3 elements]"
unconsC Stream[A] GH
Convert to B with head & tail if non empty, default otherwise
Stream.empty.unconsC("[]", h ⇒ t ⇒ s"[$h .. ${t.length} more]"
"[]"
Stream(1, 2, 3).unconsC("[]", h ⇒ t ⇒ s"[$h .. ${t.length} more]"
"[1, 2 more]"
lazyScanLeft Stream[A] GH
scanLeft that works on infinite or blocking streams
(1 #:: {synchronized(wait(0)); Stream(2)}).lazyScanLeft(0)(_ + _).take(1).toList
List(1)
reverseInits Stream[A] GH
inits that works on infinite or blocking streams
Stream.iterate(0)(_ + 1).reverseInits.take(3)
Stream(Stream.empty, Stream(0), Stream(0, 1))
toMultiMap FilterMonadic[(K, V)] GH
Convert to MultiMap
List((1, 11), (2, 22), (1, 111)).toMultiMap[Set]
Map(1 → Set(11, 111), 2 → Set(22))
closeAfter InputStream GH
Close after applying function
new ByteArrayInputStream(Array(123)).closeAfter(_.read())
123
attemptClose InputStream GH
Close & catch exceptions
closeIf InputStream GH
Close if boolean is true
closeUnless InputStream GH
Close if boolean is false
drain InputStream GH
Drain all bytes into an OutputStream, optionally closing afterwards
>> InputStream GH
Drain all bytes into an OutputStream
buffered InputStream GH
Wrap in a BufferedInputStream
gunzip InputStream GH
Wrap in a GZIPInputStream
readN InputStream GH
Read n bytes into an OutputStream & throw if unable to
readUpToN InputStream GH
Read up to n bytes into an OutputStream
toByteArray InputStream GH
Convert to an array of bytes
isJar File GH
Check if file has '.jar' extension
isClass File GH
Check if file has '.class' extension
isJava File GH
Check if file has '.java' extension
isScala File GH
Check if file has '.scala' extension
missing File GH
Check if file is missing
isChildOf File GH
Check if file is a child of another
new File("/etc/password").isChildOf("/etc")
true
new File("/etc/password").isChildOf("/")
false
isParentOf File GH
Check if file is parent of another
new File("/etc").isParentOf("/etc/password")
true
new File("/").isParentOf("/etc/password")
false
isAncestorOf File GH
isContainedIn File GH
contains File GH
hasExtension File GH
/ File GH
named File GH
canon File GH
relativeTo File GH
writeLines File GH
writeBytes File GH
write File GH
deleteRecursively File GH
deleteRecursivelyOnExit File GH
changeToDirectory File GH
create File GH
touch File GH
children File GH
childDirs File GH
tree File GH
ancestors File GH
path File GH
outputStream File GH
source File GH
readString File GH
readBytes File GH
readLines File GH
className File GH
md5 File GH
batchBy List[A] GH
Split into batches whenever result of function changes
List(1, 2, -1, -2, 3, -3, -4).batchBy(_ >= 0)
List(List(1, 2), List(-1, -2), List(3), List(-3, -4))
countBy List[A] GH
Group by number of occurrences of function result
List(1, 2, -1, -2, 3, -3, -4).countBy(_ >= 0)
Map(3 → List(1, 2, 3), 4 → List(-1, -2, -3, -4))
distinctBy List[A] GH
Retain only the first occurrence of an element whose function result is repeated
List("foo", "food", "oof", "foods").distinctBy(_.length))
List("food", "foods")
duplicatesBy List[A] GH
Retain only those elements whose function result is repeated
List("foo", "food", "oof", "foods", "doof").duplicatesBy(_.length))
List("foo", "food", "oof", "doof")
duplicates List[A] GH
Retain only those elements which are repeated
List(1, 2, 3, 1, 4, 3).duplicates
LIst(1, 3)
const List[A] GH
Replace all elements with a constant value
List(1, 2, 3).const("foo")
List("foo", "foo", "foo")
lpair List[A] GH
Pair up each element with the result of f
List(1, 2, 3).lpair(_ * 2)
List((2,1), (4,2), (6,3)))
rpair List[A] GH
Pair up each element with the result of f
List(1, 2, 3).lpair(_ * 2)
List((1,2), (2,4), (3,6)))
countWithSize List[A] GH
Count number of times a predicate passes, along with the list size
Nil.countWithSize(_ >= 0)
None
List(1, 2, -2, 3, -4, 5).countWithSize(_ >= 0)
Some((4, 6))
sizeGT List[A] GH
Determine if the list size exceeds some value
List(1, 2, 3).sizeGT(2)
true
List(1, 2, 3).sizeGT(3)
false
fraction List[A] GH
Determine what fraction of the list passes some predicate
Nil.fraction(_ >= 0)
Double.NaN
List(1, 2, -2, 3, -4, 5).fracton(_ >= 0)
Some(0.667)
emptyTo List[A] GH
Replace empty list with supplied value
List(1, 2).emptyTo(List(3, 4))
List(1, 2)
Nil.emptyTo(List(3, 4))
List(3, 4)
headTail List[A] GH
The head & tail if the list is non empty, throws otherwise
List(1, 2, 3).headTail
(1, List(2, 3))
Nil.headTail
throws "headTail of empty list"
headTailOption List[A] GH
The head & tail if the list is non empty, None otherwise
List(1, 2, 3).headTailOPtion
Some((1, List(2, 3)))
Nil.headTailOption
None
initOption List[A] GH
The init if the list is non empty, None otherwise
List(1, 2, 3).initOption
Some(List(1, 2))
Nil.initOption
None
tailOption List[A] GH
The tail if the list is non empty, None otherwise
List(1, 2, 3).tailOption
Some(List(2, 3))
Nil.tailOption
None
initLast List[A] GH
The init & last if the list is non empty, throws otherwise
List(1, 2, 3).initLast
(List(1, 2), 3)
Nil.initLast
throws "initLast of empty list"
initLastOption List[A] GH
The init & last if the list is non empty, None otherwise
List(1, 2, 3).initLastOption
Some((List(1, 2), 3))
Nil.initLastOption
None
prefixPadTo List[A] GH
Prefix lists smaller than provide size with repetitions of the provided element
List(1, 2).prefixPadTo(1, 99)
List(1, 2)
List(1, 2).prefixPadTo(4, 99)
List(99, 99, 1, 2)
amass List[A] GH
filter andThen flatMap
List(1, 2, 3, 4).amass { case i if i % 2 == 0 ⇒ List(i, -i) }
List(2, -2, 4, -4)
calcIfNonEmpty List[A] GH
Calculate result if non empty, None otherwise
Nil.calcIfNonEmpty(_.length)
None
List(1, 2, 3).calcifNonEmpty(_.length)
Some(3)
mapIfNonEmpty List[A] GH
Map if non empty, None otherwise
Nil.mapIfNonEmpty(_ * 10)
None
List(1, 2, 3).mapIfNonEmpty(_ * 10)
Some(List(10, 20, 30))
onlyDisjunction List[A] GH
\/- if list has 1 element, -\/ otherwise
Nil.onlyDisjunction
-\/(Nil)
List(1).onlyDisjunction
\/-(1)
List(1, 2).onlyDisjunction
-\/(List(1, 2))
uncons List[A] GH
Convert to B depending on whether the list is empty or not
Nil.uncons("[]", l ⇒ s"[${l.length} elements]"
"[]"
List(1, 2, 3).uncons("[]", l ⇒ s"[${l.length} elements]"
"[3 elements]"
unconsC List[A] GH
Convert to B with head & tail if non empty, default otherwise
Nil.unconsC("[]", h ⇒ t ⇒ s"[$h .. ${t.length} more]"
"[]"
List(1, 2, 3).unconsC("[]", h ⇒ t ⇒ s"[$h .. ${t.length} more]"
"[1, 2 more]"
unsnocC List[A] GH
Convert to B with init & last if non empty, default otherwise
Nil.unsnocC("[]", i ⇒ l ⇒ s"[${i.length} previous, $l]"
"[]"
List(1, 2, 3).unsnocC("[]", i ⇒ l ⇒ s"[${i.length} previous, $l]"
"[2 previous, 3]"
tapNonEmpty List[A] GH
Perform an action if the list is non empty
Nil.tapNonEmpty(l ⇒ print("non-empty: " + l))
Does nothing
List(1).tapNonEmpty(l ⇒ print("non-empty: " + l))
Prints "non-empty: List(1)"
tapEmpty List[A] GH
Perform an action if the list is empty
Nil.tapEmpty(print("empty"))
Prints "empty"
List(1).tapEmpty(print("empty"))
Does nothing
tap List[A] GH
Perform an action depending on whether the list is empty or not
Nil.tap(print("empty"), l ⇒ print("non-empty: " + l))
Prints "empty"
List(1).tap(print("empty"), l ⇒ print("non-empty: " + l))
Prints "non-empty: List(1)"
zipWith List[A] GH
Combine with another list element-wise
List(1, 2).zipWith(List('z', 'x')) { case (i, c) ⇒ s"i: $i, c: $c"}
List("i: 1, c: z", "i: 2, c: x")
List(1).zipWith(List('z', 'x')) { case (i, c) ⇒ s"i: $i, c: $c"}
List("i: 1, c: z")
List(1, 2).zipWith(List('z')) { case (i, c) ⇒ s"i: $i, c: $c"}
List("i: 1, c: z")
zipToMap List[A] GH
Combine with another list element-wise to form a Map
List(1, 2).zipToMap(List('z', 'x'))
Map(1 → 'z', 2 → 'x')
List(1).zipToMap(List('z', 'x'))
Map(1 → 'z')
List(1, 2).zipToMap(List('z'))
Map(1 → 'z')
zipExact List[A] GH
Losslessly combine with another list element-wise
List(1, 2).zipExact(List('z', 'x'))
(List((1, 'z'), (2, 'x')), None)
List(1).zipExact(List('z', 'x'))
(List((1, 'z')), Some(Right('x')))
List(1, 2).zipExact(List('z'))
(List((1, 'z')), Some(Left(1)))
zipExactWith List[A] GH
Losslessly combine with another list element-wise
List(1, 2).zipExactWith(List(10.0, 20.0))(_ + _)
(List(11.0, 22.0), None)
List(1).zipExactWith(List(10.0, 20.0))(_ + _)
(List(11.0), Some(Right(20.0))
List(1, 2).zipExactWith(List(10.0 ))(_ + _)
(List(11.0), Some(Left(2)))
sortPromoting List[A] GH
When sorting promote specified elements, otherwise use existing ordering
List("red", "green", "blue", "cyan").sortPromoting("cyan", "green")
List("cyan", "green", "blue", "red")
sortDemoting List[A] GH
When sorting demote specified elements, otherwise use existing ordering
List("blue", "red", "cyan", "green").sortDemoting("green", "blue")
List("cyan", "red", "green", "blue")
toNel List[A] GH
Convert to non-empty list, if possible
Nil.toNel
None
List(1, 2).toNel
Some(NonEmptyList(1, 2))
max NonEmptyList[A: Order] GH
Maximum value
NonEmptyList(3, 1, 4).max
4
min NonEmptyList[A: Order] GH
Minimum value
NonEmptyList(3, 1, 4).min
1
toLeft PartialFunction[A, B] GH
toRight PartialFunction[A, B] GH
either PartialFunction[A, B] GH
partition PartialFunction[A, B] GH
isUndefinedAt PartialFunction[A, B] GH
first PartialFunction[A, B] GH
second PartialFunction[A, B] GH
unify PartialFunction[A, B] GH
map PartialFunction[A, B] GH
contramap PartialFunction[A, B] GH
PartialFunction[C, B]
*** PartialFunction[A, B] GH
&&& PartialFunction[A, B] GH
||| PartialFunction[A, B] GH
\/ PartialFunction[A, B] GH
toMultiMap GTL[(K, V)] GH
beforeDecode DecodeJson[A] GH
Pre-processes json before decoding
compose DecodeJson[A] GH
Pre-processes json before decoding
upcast DecodeJson[A] GH
Upcasts results after decoding
asMap.withValues GTL[K] GH
asMap.withSomeValues GTL[K] GH
asMap.withPFValues GTL[K] GH
asMap.withConstValue GTL[K] GH
asMultiMap.withValues GTL[K] GH
asMultiMap.withSomeValues GTL[K] GH
asMultiMap.withPFValues GTL[K] GH
asMultiMap.withConstValue GTL[K] GH
afterEncode EncodeJson[A] GH
Post-processes json after encoding
andThen EncodeJson[A] GH
Post-processes json after encoding
downcast EncodeJson[A] GH
Downcasts values before encoding
toHex Array[Byte] GH
Convert to hex string
Array[Byte](126, 87, -85, 30).toHex
7e57ab1e
toHex Array[Byte] GH
Convert to hex & prefix up to a certain length
Array[Byte](126, 87, -85, 30).toHex(10)
007e57ab1e
copyUpToN Array[Byte] GH
Use array as buffer to copy up to n bytes from an InputStream to an OutputStream
readUpToN Array[Byte] GH
Read up to n bytes from an InputStream
unlift (A ⇒ Option[B]) GH
Create partial function
addTo (A, B) GH
Adds values into growables
(1, "foo").addTo(ints, strings)
ints += 1; strings += "foo"
removeFrom (A, B) GH
Removes values from a shrinkables
(1, "foo").removeFrom(ints, strings)
ints -= 1; strings -= "foo"
tap (A, B) GH
Performs an action
(1, "foo").tap(i ⇒ s ⇒ println(s"int: $i, string: $s")
Prints "int: 1, string: foo"
calc (A, B) GH
Applies a function
(1, "foo").calc { case (i, s) ⇒ s"int: $i, string: $s" }
"int: 1, string: foo"
calcC (A, B) GH
Applies a curried function
(1, "foo").calc(i ⇒ s ⇒ s"int: $i, string: $s")
"int: 1, string: foo"
to (A, B) GH
Converts all elements to a common type
(123, 456.0).to[String]
("123", "456.0")
tmap (A, B) GH
Applies functions to each element
(1, "foo").tmap(_ * 2, _.reverse)
(2, "oof")
notContains Set[A] GH
Tests if some element is absent in this set
Set(1, 2).notContains(1)
false
Set(1, 2).notContains(3)
true
mutable Set[A] GH
Convert to mutable set
toMutable Set[A] GH
Convert to mutable set
powerSet Set[A] GH
All possble subsets of the set
Set(1, 2, 3).powerSet
Set(1, 2, 3), Set(1, 2), Set(1, 3), Set(2, 3), Set(1), Set(2), Set(3), Set())
partitionDisjunctions GTL[L \/ R] GH
Partition disjunctions into lefts & rights
List(\/-(3.0), -\/(1), \/-(4.0), -\/(1)).partitionDisjunctions
(List(1, 1), List(3.0, 4.0))
flatten (L \/ (L \/ R)) GH
Flattens two level disjunction into one
-\/(1).flatten
-\/(1)
\/-(-\/(2)).flatten
-\/(2)
\/-(\/-("s"))).flatten
\/-("s")
addDay Date GH
Adds n days to date
Date().addDay(2)
mapC List[(A, B) GH
Curried map method
List((1, 2), (2, 3)).mapC(a ⇒ b ⇒ a * b)
List(2, 6)
mapKeys DecodeJson[Map[K, V]] GH
Converts map keys after decoding
mapDecoder.mapKeys(_.reverse).decodeJson({ "foo" → "bar" })
Map("oof" → "bar")
mapValues DecodeJson[Map[K, V]] GH
Converts map values after decoding
mapDecoder.mapValues(_.reverse).decodeJson({ "foo" → "bar" })
Map("foo" → "rab")
attempt Callable[A] GH
Wrap result in Try
cartesianProduct List[List[A]] GH
Every permutation of elements choosen from each list
List(List(1,2,3), List(8,9)).cartesianProduct
List(List(1,8), List(1,9), List(2,8), List(2,9), List(3,8), List(3,9))
flatten ((L \/ R) \/ R) GH
Flattens two level disjunction into one
-\/(-\/(1)).flatten
-\/(1)
-\/(\/-("s")).flatten
\/-("s")
\/-("s").flatten
\/-("s")
asMap.withKeys GTL[V] GH
asMap.withSomeKeys GTL[V] GH
asMap.withManyKeys GTL[V] GH
asMap.withUniqueKeys GTL[V] GH
asMap.withPFKeys GTL[V] GH
asMultiMap.withKeys GTL[V] GH
asMultiMap.withSomeKeys GTL[V] GH
asMultiMap.withManyKeys GTL[V] GH
asMultiMap.withUniqueKeys GTL[V] GH
asMultiMap.withPFKeys GTL[V] GH
select MultiMap[F, K, V] GH
Choose a slice of the multimap, equivalent to Map[K, F[V]].mapValuesEagerly
Map(1 → List(1, 11), 2 → List(2, 22)).select(_.last)
Map(1 → 11, 2 → 22)
merge MultiMap[F, K, V] GH
Combines two multimaps by concatenating their values
Map(1 → List(1), 3 → List(3)).merge(Map(2 → List(2), 3 → List(33))
Map(1 → List(1), 2 → List(2), 3 → List(3, 33))
append MultiMap[F, K, V] GH
Appends a single entry, concatenating if already present
Map(1 → List(11)).append(2, List(22))
Map(1 → List(11), 2 → List(22))
Map(1 → List(11)).append(1, List(111))
Map(1 → List(11, 111))
multiMap.head MultiMap[F, K, V] GH
Selects the head element of each value
Map(1 → List(11), 2 → List(22, 222)).multiMap.head
Map(1 → 11, 2 → 22)
multiMap.tail MultiMap[F, K, V] GH
Selects the tail of each value, only retains non-empty values
Map(1 → List(1, 11), 2 → List(22), 3 → Nil).multiMap.tail
Map(1 → List(11))
multiMap.reverse MultiMap[F, K, V] GH
Reverses the multimap
Map('a' → List(1, 2), 'b' → List(2, 3)).reverse
Map(1 → List('a'), 2 → List('a', 'b'), 3 → List('b'))
multiMap.mapEntries MultiMap[F, K, V] GH
Map over each entry to produce another multimap
Map(2 → List(2, 22)).mapEntries(key ⇒ values ⇒ (key * 10, List(values.sum)))
Map(20 → List(24))
multiMap.mapEntriesU MultiMap[F, K, V] GH
Map over each entry to produce another type of multimap
Map(2 → List(2, 22)).mapEntriesU(key ⇒ values ⇒ (key * 10, Set(values.sum)))
Map(20 → Set(24))
multiMap.values MultiMap[F, K, V] GH
Concatenate values
Map(1 → List(1), 2 → List(2, 22)).multiMap.values
List(1, 2, 22)
multiMap.sliding MultiMap[F, K, V] GH
Produce a sequence of multimaps that slide across the original
Map(1 → List(11, 12, 13), 2 → List(21, 22, 23)).multiMap.sliding(2)
List(Map(1 → List(11, 12), 2 → List(21, 22)), Map(1 → List(12, 13), 2 → List(22, 23)))
pop MultiMap[F, K, V] GH
Removes head value associated with key, discarding empty values entirely
Map(1 → List(2, 3), 2 → List(3)).pop(1)
Map(1 → List(3), 2 → List(3))
Map(1 → List(2, 3), 2 → List(3)).pop(2)
Map(1 → List(2, 3))
Map(1 → List(2, 3), 2 → List(3)).pop(3)
Map(1 → List(2, 3), 2 → List(3)))
sequence MultiMap[F, K, V] GH
Convert a multimap to a sequence of maps
Map(1 → List(10, 11), 2 → List(20, 21)).sequence
List(Map(1 → 10, 2 → 20), Map(1 → 11, 2 → 21))
headTailOption MultiMap[F, K, V] GH
The head & tail if the multimap is non empty, None otherwise
Map(1 → List(10, 11), 2 → List(20)).headTailOption
Some(Map(1 → 10, 2 → 20), Map(1 → List(11)))
Map(1 → Nil, 2 → List(20)).headTailOption
Some(Map(2 → 20), Map())
Map(1 → (Nil: List[Int])).headTailOption
None
MultiMap.empty[List, Int, Int]
None
flatMapValues MultiMap[F, K, V] GH
Expand each value to a collection of values
Map(0 → List(1, 2)).flatMapValues(v ⇒ List(v, -v))
Map(0 → List(1, -1, 2, -2))
flatMapValuesU MultiMap[F, K, V] GH
Expand each value to a different type of collection of values
Map(0 → List(1, 2)).flatMapValuesU(v ⇒ Set(v, -v))
Map(0 → Set(1, -1, 2, -2))
getOrEmpty MultiMap[F, K, V] GH
Retrive the values associated with a key or an empty collection
Map(1 → List(2)).getOrEmpty(1)
List(2)
Map(1 → List(2)).getOrEmpty(2)
Nil
onlyOption MultiMap[F, K, V] GH
Returns Some map if the multimap only contains empty or singleton containers, None otherwise
Map(1 → Nil, 2 → List(22)).onlyOption
Some(Map(2 → 22))
Map(1 → List(1, 11)).onlyOption
None
string Traversal[Json, Json] GH
compose with string prism
Traversal.id[Json].string.getAll(Json.jString("foo"))
List("foo")
Traversal.id[Json].string.getAll(Json.jNumber(3))
Nil
int Traversal[Json, Json] GH
compose with int prism
Traversal.id[Json].int.getAll(Json.jString("foo"))
Nil
Traversal.id[Json].int.getAll(Json.jNumber(3))
List(3)
filterNulls Json GH
Recursively removes null values
null
null
{ "a": null, "b": 3 }
{ "b": 3 }
[ "a", null, "b" ]
[ "a", "b" ]
{ "o": [ "a", null, "b" ] }
{ "o": [ "a", "b" ] }
[ { "a": null, "b": 3 } ]
[ { "b": 3 } ]
as[F] NonEmptyList[K] GH
unique NonEmptyList[A] GH
Remove duplicates
NonEmptyList(3, 1, 4, 3, 4).unique
NonEmptyList(3, 1, 4)
uniqueBy NonEmptyList[A] GH
Remove items with duplicate properties
NonEmptyList("foo", "bar", "bare", "food").uniqueBy(_.length)
NonEmptyList("foo", "bare")
filter NonEmptyList[A] GH
filters the NonEmptyList
NonEmptyList(1).filter(_ % 2 == 0)
None
NonEmptyList(1, 2).filter(_ % 2 == 0)
Some(NonEmptyList(2))
filterNot NonEmptyList[A] GH
filters the NonEmptyList
NonEmptyList(2).filterNot(_ % 2 == 0)
None
NonEmptyList(1, 2).filterNot(_ % 2 == 0)
Some(NonEmptyList(1))
onlyOption NonEmptyList[A] GH
Head if non-empty list has 1 element, None otherwise
NonEmptyList(1).onlyOption
Some(1)
NonEmptyList(1, 2).onlyOption
None
onlyEither NonEmptyList[A] GH
Right if non-empty list has 1 element, Left otherwise
NonEmptyList(1).onlyEither
Right(1)
NonEmptyList(1, 2).onlyEither
Left(NonEmptyList(1, 2))
onlyDisjunction NonEmptyList[A] GH
\/- if list has 1 element, -\/ otherwise
NonEmptyList(1).onlyDisjunction
\/-(1)
NonEmptyList(1, 2).onlyDisjunction
-\/(NonEmptyList(1, 2))
attempt (A ⇒ B) GH
guardWith (A ⇒ B) GH
beforeDecode CodecJson[A] GH
Pre-processes json before decoding
afterDecode CodecJson[A] GH
Converts after decoding
beforeEncode CodecJson[A] GH
Converts before encoding
afterEncode CodecJson[A] GH
Post-processes json after encoding
andThen CodecJson[A] GH
Post-processes json after encoding
compose CodecJson[A] GH
Pre-processes json before decoding
emptyTo String GH
Convert empty strings to another
"".emptyTo("replacement")
"replacement"
"non-empty".emptyTo("replacement")
"non-empty"
prefixPadTo String GH
suffixWith String GH
Add suffix to string if absent
"file".suffixWith(".txt")
"file.txt"
"file.txt".suffixWith(".txt")
"file.txt"
prefixWith String GH
Add prefix to string if absent
"file".prefixWith("dir/")
"dir/file"
"dir/file".prefixWith("dir/")
"dir/file"
affixWith String GH
Add prefix & suffix to string if absent
"file".affixWith("dir/", ".txt")
"dir/file.txt"
"file.txt".affixWith("dir/", ".txt")
"dir/file.txt"
"dir/file".affixWith("dir/", ".txt")
"dir/file.txt"
"dir/file.txt".affixWith("dir/", ".txt")
"dir/file.txt"
stripAffixes String GH
Remove prefix & suffix from string
"file".stripAffixes("dir/", ".txt")
"file"
"file.txt".stripAffixes("dir/", ".txt")
"file"
"dir/file".stripAffixes("dir/", ".txt")
"file"
"dir/file.txt".stripAffixes("dir/", ".txt")
"file"
md5 String GH
toByteArray String GH
toByteArray String GH
tap (L \/ R) GH
Perform one action or another
-\/(1).tap(l ⇒ print("left: " + l), r ⇒ print("right: " + r))
Prints "left: 1"
\/-(true).tap(l ⇒ print("left: " + l), r ⇒ print("right: " + r))
Prints "right: true"
tapLeft (L \/ R) GH
Perform action if Left
-\/(1).tapLeft(l ⇒ print("left: " + l))
Prints "left: 1"
\/-(true).tapLeft(l ⇒ print("left: " + l))
Does nothing
tapRight (L \/ R) GH
Perform action if Right
-\/(1).tap(r ⇒ print("right: " + r))
Does nothing
\/-(true).tap(r ⇒ print("right: " + r))
Prints "right: true"
addTo (L \/ R) GH
Adds values into growables
-\/(1).addTo(ints, strings)
ints += 1
\/-("foo").addTo(ints, strings)
strings += "foo"
removeFrom (L \/ R) GH
Removes values from a shrinkables
-\/(1).removeFrom(ints, strings)
ints -= 1
\/-("foo").removeFrom(ints, strings)
strings -= "foo"
leftFlatMap (L \/ R) GH
flatMap over the left, equivalent to swap.flatMap.swap
\/-(123).leftFlatMap(in => in match { case "left" => \/-(100); case _ => -\/(in) }
\/-(123)
-\/("left").leftFlatMap(in => in match { case "left" => \/-(100); case _ => -\/(in) }
\/-(100)
-\/("101").leftFlatMap(in => in match { case "left" => \/-(100); case _ => -\/(in) }
-\/("101")
fold Try[A] GH
Convert to B
Failure(Throwable("boom")).fold(_.getMessage, "message: " + _)
"boom"
Success(123).fold(_.getMessage, "message: " + _)
"message: 123"
getMessage Try[A] GH
None if Success, Some if Failure
Failure(Throwable("boom")).getMessage
Some("boom")
Success(123).getMessage
None
toEither Try[A] GH
Convert to Either
Failure(Throwable("boom")).toEither
Left(Throwable("boom"))
Success(123).toEither
Right(123)
toDisjunction Try[A] GH
Convert to Disjunction
Failure(Throwable("boom")).toDisjunction
-\/(Throwable("boom"))
Success(123).toDisjunction
\/-(123)