Escolar Documentos
Profissional Documentos
Cultura Documentos
ub
itH
G
en
rk
fo
tu
English version
é
ac
H
Exception
Base class for all Exceptions. Every exception and its subclasses
indicates conditions that a reasonable application might want to catch.
author jfernandes
since 1.0
Constructors
constructor()
Constructs a new exception with no detailed message.
constructor(_message)
Constructs a new exception with the speci ed detail message.
constructor(_message, _cause)
Constructs a new exception with the speci ed detail message and cause.
Behavior
Method Description
createStackTraceElement private
( D i i
https://www.wollok.org/documentacion/wollokdoc/ 1/42
12/11/2018 WollokDoc · Wollok
(contextDescription,
Method
location) Description
printStackTrace (printer) Prints this exception and its backtrace to the speci ed
printer
printStackTraceWithPre x private
(pre x, printer)
StackOver owException
inherits from Exception
Thrown when a stack over ow occurs because an application recurses too deeply.
author jfernandes
since 1.5.1
ElementNotFoundException
inherits from Exception
Constructors
constructor(_message)
constructor(_message, _cause)
https://www.wollok.org/documentacion/wollokdoc/ 2/42
12/11/2018 WollokDoc · Wollok
MessageNotUnderstoodException
inherits from Exception
Constructors
constructor()
constructor(_message)
constructor(_message, _cause)
StackTraceElement
An element in a stack trace, represented by a context and a location
of a method where a message was sent
Constructors
constructor(_contextDescription, _location)
Object
Representation of Wollok Object
author jfernandes
since 1.0
Behavior
Method Description
generateDoesNotUnderstandMessage private
(target, messageName,
parametersSize) native internal method: generates a does not
understand message
parametersSize must be an integer value
messageNotUnderstood private
(messageName, parameters)
void
Representation for methods that only have side effects
Pair
Representation of a Key/Value Association.
It is also useful if you want to model a Point.
Constructors
constructor(_x, _y)
Behavior
Method Description
key ()
value ()
https://www.wollok.org/documentacion/wollokdoc/ 5/42
12/11/2018 WollokDoc · Wollok
Collection
The root class in the collection hierarchy.
A collection represents a group of objects, known as its elements.
Behavior
Method Description
Example:
[1, 2] + [3] => Answers [1, 2, 3]
[1, 2] + #{3} => supports concatenation between lists and
sets, answers [1, 2, 3]
#{} + [] => Answers #{}
addAll (elements) Adds all elements from the given collection parameter to
self collection.
This is a side effect operation.
Example:
const list = []
list.addAll(#{2, 4}) => list == [2, 4], always pointing to a list
all (predicate) Answers whether all the elements of self collection satisfy a
https://www.wollok.org/documentacion/wollokdoc/ i 6/42
12/11/2018 WollokDoc · Wollok
given
Method Description
condition. The condition is a closure argument that takes a
single
element and answers a boolean value.
returns true/false
Example:
plants.all({ plant => plant.hasFlowers() })
[1, 3, 5].all { number => number.odd() } => Answers true
[].all { number => number.odd() } => Answers true
Example:
plants.any({ plant => plant.hasFlowers() })
[1, 2, 3].any { number => number.even() } ==> Answers true
[].any { number => number.even() } ==> Answers false
Example:
[].contains(3) => Answers false
[1, 2, 3].contains(2) => Answers true
copy () Answers a new collection of the same type and with the
same content
as self. Supports empty collections.
Example:
const usersCopy = users.copy()
count (predicate) Counts all elements of self collection that satis es a given
https://www.wollok.org/documentacion/wollokdoc/ di i 7/42
12/11/2018 WollokDoc · Wollok
condition
Method Description
The condition is a closure argument that takes a single
element and
answers a number.
returns an integer number
Example:
plants.count { plant => plant.hasFlowers() }
#{1, 2, 3, 4, 5}.count { number => number.odd() } => Answers
3
#{}.count { number => number.odd() } => Answers 0
lter (closure) Answers a new collection that contains the elements that
meet a given condition. The condition is a closure
argument that
takes a single element and answers a boolean.
returns another collection (same type as self one)
Example:
const overageUsers = users. lter({ user => user.age() >= 18 })
#{1, 2, 3, 4, 5}. lter { number => number.even() } => Answers
#{2, 4}
#{}. lter { number => number.even() } => Answers #{}
Example:
users. nd { user => user.name() == "Cosme Fulanito" }
#{1, 4, 5}. nd { number => number.even() } => Answers 4
#{1, 3}. nd { number => number.even() } => Throws
ElementNotFoundException
#{}. nd { number => number.even() } => Throws
ElementNotFoundException
Example:
users. ndOrDefault({ user => user.name() == "Cosme
Fulanito" }, homer)
[1, 3, 5]. ndOrDefault({ number => number.even() }, 0) =>
Answers 0
[]. ndOrDefault({ number => number.even() }, 0) =>
Answers 0
ndOrElse (predicate, Answers the element of self collection that satis es a given
continuation) native condition,
or the the result of evaluating the given continuation.
If more than one element satis es the condition then it
depends on the
speci c collection class which element will be returned.
Example:
users. ndOrElse({ user => user.name() == "Cosme Fulanito"
}, { homer })
[1, 3, 5]. ndOrElse({ number => number.even() }, { 6.max(4) })
=> Answers 6
[]. ndOrElse({ number => number.even() }, { false }) =>
Answers false
Example
object klaus {
method languages() = ["c", "cobol", "pascal"]
}
object fritz {
method languages() = ["java", "perl"]
}
program abc {
console.println([klaus, fritz]. atMap({ person =>
person.languages() }))
=> Answers ["c", "cobol", "pascal", "java", "perl"]
}
Example:
[ [1, 2], [3], [4, 0], [] ]. atten() => Answers [1, 2, 3, 4, 0]
Example:
plants.forEach { plant => plant.takeSomeWater() }
internalToSmartString private
(alreadyShown)
Example:
[1, 6, 5].isEmpty() => Answers false
[].isEmpty() => Answers true
Example:
const ages = users.map({ user => user.age() })
[1, 2, 3].map { number => number.odd() } => Answers [true,
false, true]
[].map { number => number.odd() } => Answers []
Example:
["a", "ab", "abc", "d" ].max({ e => e.length() })
=> Answers "abc"
Example:
[11, 1, 4, 8, 3, 15, 6].max() => Answers 15
[].max() => Throws error, list must not be empty
Example:
["ab", "abc", "hello", "wollok world"].min({ e => e.length() })
=> Answers "ab"
Example:
[11, 1, 4, 8, 3, 15, 6].min() => Answers 1
[].min() => Throws error, list must not be empty
newInstance () abstract Answers a new, empty collection of the same type as self.
returns a new collection
Example:
const newCollection = users.newInstance()
Example:
[1, 8, 4, 1].occurrencesOf(1) => Answers 2
[].occurrencesOf(2) => Answers 0
Example:
const list = [1, 6, 5]
list.removeAll([6]) => list == [1, 5]
Example:
const list = [1, 6, 5]
list.removeAllSuchThat { e => e.even() } => list == [1, 5]
sortedBy (closure) Answers a new List that contains the elements of self
collection
sorted by a criteria given by a closure. The closure receives
two objects
X and Y and answers a boolean, true if X should come
before Y in the
resulting collection. Supports empty collections.
Example:
const usersByAge = users.sortedBy({ a, b => a.age() < b.age()
})
const studentsByNameDesc = students.sortedBy({ a, b =>
a.name() > b.name() })
[1, 5, 9, 2, 4].sortedBy { a, b => a < b } => Answers [1, 2, 4, 5, 9]
[1, 5, 9, 2, 4].sortedBy { a, b => a > b } => Answers [9, 5, 4, 2, 1]
[].sortedBy { a, b => a > b } => Answers []
sum (closure) Collects the sum of each value for all elements.
This is similar to call a map {} to transform each element
into a
number object and then adding all those numbers.
The condition is a closure argument that takes a single
element and
answers a boolean value.
returns an integer
Example:
const totalNumberOfFlowers = plants.sum{ plant =>
plant.numberOfFlowers() }
[].sum { employee => employee.salary() } => Answers 0
Set
inherits from Collection
author jfernandes
since 1.3
Constructors
constructor(elements)
Behavior
Method Description
see Object#==
add (element) native Adds the speci ed element to this set if it is not already
https://www.wollok.org/documentacion/wollokdoc/ 14/42
12/11/2018 WollokDoc · Wollok
present.
Method Description
Example:
const set = #{}
set.add(3) => set = #{3}
set.add(2) => set = #{2, 3}
set.add(2) => set = #{2, 3}, second add produces no effect
Examples
#{1, 2, 3}.anyOne() => Answers 1, for example
#{}.anyOne() => Throws error, set must not be empty
Examples
#{1, 2, 3}.asList() => Answers [1, 2, 3]
#{}.asList() => Answers []
see List
Examples
#{1, 2, 3}.asSet() => Answers #{1, 2, 3}
#{}.asSet() => Answers #{}
clear () native Removes all of the elements from this set. This is a side
effect operation.
Example:
const set = #{2, 3}
set.clear() => set = #{}
difference (another) Answers a new Set with the elements of self that don't exist
in another collection
Examples
#{1, 2}.difference(#{5, 2}) => #{1}
#{3}.difference(#{}) => #{3}
returns a Set
equals (other) native Two sets are equals if they have the same elements
https://www.wollok.org/documentacion/wollokdoc/ 15/42
12/11/2018 WollokDoc · Wollok
Method Description
Examples:
#{}.equals(#{}) => Answers true
#{1, 2}.equals(#{2, 1}) => Answers true
#{3, 2}.equals(#{2, 1}) => Answers false
Examples:
#{1, 9, 3, 8}. ndOrElse({ n => n.even() }, { 100 }) => Answers 8
#{1, 5, 3, 7}. ndOrElse({ n => n.even() }, { 100 }) => Answers 100
Examples
#{1, 9, 3, 8}.fold(0, {acum, each => acum + each})
=> Answers 21, the sum of all elements
intersection (another) Answers a new Set with the elements of self that exist in
another collection
Examples
#{1, 2}.intersection(#{5, 2}) => #{2}
#{}.intersection(#{3}) => #{}
returns a Set
Examples:
#{1, 5, 3, 7}.join(":") => Answers "1:5:3:7"
#{"you","will","love","wollok"}.join(" ") => Answers "love will
wollok you"
#{}.join(",") => Answers ""
Example:
#{"you","will","love","wollok"}.join() => Answers
"love,will,wollok,you"
newInstance () private
remove (element) Removes the speci ed element from this set if it is present.
native
Example:
const set = #{2, 3}
set.remove(3) => set = #{2}
set.remove(4) => set = #{2}, remove operation produces no
effect
size () native Answers the number of elements in this set (its cardinality).
Example:
#{2, 3}.size() => Answers 2
#{}.size() => Answers 0
toStringPre x () private
toStringSuf x () private
union (another) Answers a new Set with the elements of both self and
another collection.
Examples
#{1, 2}.union(#{5, 2}) => #{1, 2, 5}
#{}.union(#{3}) => #{3}
returns a Set
https://www.wollok.org/documentacion/wollokdoc/ 17/42
12/11/2018 WollokDoc · Wollok
List
inherits from Collection
author jfernandes
since 1.3
Constructors
constructor()
constructor(head, tail)
Behavior
Method Description
== (other) native A list is == another list if all elements are equal (de ned by
== message)
Examples:
[].equals([]) => Answers true
[1, 2].equals([2, 1]) => Answers false
[1, 2].equals([1, 2]) => Answers true
Method Description
Example:
const list = []
list.add(3) => list = [3]
list.add(2) => list = [3, 2]
list.add(2) => list = [3, 2, 2]
Examples
#[1, 2, 3].anyOne() => Answers 3, for example
#[].anyOne() => Throws error, list must not be empty
see List
Examples:
[1, 2, 3].asSet() => Answers #{1, 2, 3}
[].asSet() => Answers #{}
[1, 2, 1, 1, 2].asSet() => Answers #{1, 2}
see Set
Example:
const list = [2, 3]
list.clear() => list = []
Examples:
[1, 9, 2, 3].drop(3) ==> Answers [3]
[1, 9, 2, 3].drop(1) ==> Answers [9, 2, 3]
[1, 9, 2, 3].drop(-2) ==> Answers [1, 9, 2, 3]
[].drop(2) ==> Answers []
ndOrElse (predicate, Finds the rst element matching the boolean closure,
i i )
https://www.wollok.org/documentacion/wollokdoc/ l h i i bl k l if l i 19/42
12/11/2018 WollokDoc · Wollok
continuation) native or evaluates the continuation block closure if no element is
Method Description
found
Examples:
[1, 9, 3, 8]. ndOrElse({ n => n.even() }, { 100 }) => Answers 8
[1, 5, 3, 7]. ndOrElse({ n => n.even() }, { 100 }) => Answers 100
Example:
[1, 2, 3, 4]. rst() => Answers 1
[]. rst() => Throws error, list must not be empty
Examples
#{1, 9, 3, 8}.fold(0, {acum, each => acum + each})
=> Answers 21, the sum of all elements
get (index) native Answers the element at the speci ed position in this non-
empty list.
Examples:
[].get(0) => Throws error, list must not be empty
[1].get(-1) => Throws error, index must be 0 or positive
[1, 2, 3].get(3) => Throws error, index exceeds list size
[5, 2, 7].get(0) => Answers 5
Examples:
[1, 5, 3, 7].join(":") => Answers "1:5:3:7"
["you","will","love","wollok"].join(" ") => Answers "you will love
wollok"
Examples:
["you","will","love","wollok"].join() => Answers
"you,will,love,wollok"
Examples:
[1, 2, 3, 4].last() => Answers 4
[].last() => Throws error, list must not be empty
Example:
[1, 9, 2, 3].reverse() ==> Answers [3, 2, 9, 1]
[1, 2].reverse() ==> Answers [2, 1]
[].reverse() ==> Answers []
Method Description
Example:
[2, 3].size() => Answers 2
[].size() => Answers 0
Examples:
const list = [2, 9, 3]
list.sortBy { el1, el2 => el1 > el2 }
list.get(0) => Answers 9
see List#sortedBy
subList (start, end) Answers a view of the portion of this list between the
speci ed fromIndex
and toIndex, both inclusive. Remember rst element is
position 0,
second is position 1, and so on.
If toIndex exceeds length of list, no error is thrown.
Example:
[1, 5, 3, 2, 7, 9].subList(2, 3) => Answers [3, 2]
[1, 5, 3, 2, 7, 9].subList(4, 6) => Answers [7, 9]
[].subList(1, 2) => Answers []
Examples:
[1,9,2,3].take(5) ==> Answers [1, 9, 2, 3]
[1,9,2,3].take(2) ==> Answers [1, 9]
[1,9,2,3].take(-2) ==> Answers []
[].take(2) ==> Answers []
toStringPre x () private
toStringSuf x () private
Dictionary
Represents a set of key -> values
Behavior
Method Description
basicGet (_key) native Answers the value to which the speci ed key is mapped,
or null if this Dictionary contains no mapping for the key.
Example:
const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.clear() => phones == empty dictionary
containsValue (_value) Answers whether if this Dictionary maps one or more keys
https://www.wollok.org/documentacion/wollokdoc/ h i d l 23/42
12/11/2018 WollokDoc · Wollok
to the speci ed value.
Method Description
Example:
const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.containsValue(2) => Answers true
numbers.containsValue(5) => Answers false
new Dictionary().containsValue(3) => Answers false
forEach (closure) native Performs the given action for each entry in this Dictionary
until all entries have been processed or the action throws
an exception.
Example:
mapaTelefonos.forEach({ k, v => result += k.size() + v.size() })
get (_key) Answers the value to which the speci ed key is mapped.
If this Dictionary contains no mapping for the key, an error
is thrown.
getOrElse (_key, Answers the value to which the speci ed key is mapped,
_closure) or evaluates a non-parameter closure otherwise.
Method Description
Example:
const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.keys() => ["one", "two"]
Example:
const phones = new Dictionary()
phones.put("4004-4004", rolo)
=> phones == a Dictionary ["4004-4004" -> rolo]
remove (_key) native Removes the mapping for a key from this Dictionary if it is
present.
If key is not present nothing happens.
This is a side effect operation.
Example:
const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.remove("one") => numbers is a dictionary ("two" ->
2)
numbers.remove("three") => nothing happens
Example:
const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
=> Answers a Dictionary ["one" -> 1, "two" -> 2]
Method Description
Example:
const numbers = new Dictionary()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.values() => [1, 2]
Number
In Wollok we have numbers as immutable representation. You can customize
how many decimals you want to work with, and printing strategies. So
number two could be printed as "2", "2,00000", "2,000", etc.
author jfernandes
author dodain (uni cation between Double and Integer in a single Number class)
since 1.3
noInstantiate
Behavior
Method Description
* (other) native
Example:
3.2 ** 2 ==> Answers 10.24
3 ** 2 ==> Answers 9
+ (other) native
- (other) native
https://www.wollok.org/documentacion/wollokdoc/ 26/42
12/11/2018 WollokDoc · Wollok
Method
.. (end) Description
Builds a Range between self and end
Example:
1..4 Answers ==> a new Range object from 1 to 4
/ (other) native
<= (other)
=== (other) native Two references are identical if they are the same number
>= (other)
Example:
2.abs() ==> 2
(-3).abs() ==> 3 (be careful with parentheses)
2.7.abs() ==> Answers 2.7
(-3.2).abs() ==> Answers 3.2 (be careful with parentheses)
between (min, max) Answers whether self is between min and max
Example:
2.between(2, 3) ==> Answers true
6.between(4, 6) ==> Answers true
3.between(4, 6) ==> Answers false
coerceToInteger () private
native
Applies coercing strategy to integer. If it is an integer,
nothing happens.
Otherwise, if it is a decimal, de ned coercing algorithm is
applied
(see de nition of class Number)
Method Description
Examples:
600.digits() ==> Answers 3
6.00012.digits() ==> Answers 6
-100.digits() ==> Answers -3
Example:
8.div(3) ==> Answers 2
15.div(5) ==> Answers 3
8.2.div(3.3) ==> Answers 2
Example:
8.gcd(12) ==> Answers 4
5.gcd(10) ==> Answers 5
internalToSmartString private
(alreadyShown)
Example:
3.invert() ==> Answers -3
(-2).invert() ==> Answers 2 (be careful with parentheses)
3.2.invert() ==> -3.2
(-2.4).invert() ==> 2.4 (be careful with parentheses)
Method Description
Examples:
2.isInteger() ==> Answers true
(2.0).isInteger() ==> Answers true
(2.3).isInteger() ==> Answers false
Example:
3.lcm(4) ==> Answers 12
6.lcm(12) ==> Answers 12
Examples
4.limitBetween(2, 10) ==> Answers 4, because 4 is in the
range
4.limitBetween(6, 10) ==> Answers 6, because 4 is not in
range 6..10, and 6 is nearest value to 4
4.limitBetween(1, 2) ==> Answers 2, because 4 is not in
range 1..2, but 2 is nearest value to 4
min (other) Answers the lower number between two. see max
Example:
5.min(8) ==> Answers 5
Example:
5.rem(3) ==> Answers 2
5.5.rem(3) ==> Answers 2
Example:
1.223445.roundUp(3) ==> 1.224
-1.223445.roundUp(3) ==> -1.224
14.6165.roundUp(3) ==> 14.617
5.roundUp(3) ==> 5
Example:
3.square() => Answers 9
Example:
9.squareRoot() => Answers 3
Method Description
Self must be a positive integer value.
The closure must have one argument (index goes from 1 to
self)
Example:
4.times({ i => console.println(i) }) ==> Answers
1
2
3
4
Example:
1.223445.truncate(3) ==> 1.223
14.6165.truncate(3) ==> 14.616
-14.6165.truncate(3) ==> -14.616
5.truncate(3) ==> 5
String
Strings are constant;
their values cannot be changed after they are created.
author jfernandes
noInstantiate
Behavior
Method Description
+ (other) native Concatenates the speci ed string to the end of this string.
Example:
"cares" + "s" => Answers "caress"
<= (aString)
>= (aString)
Example:
"javier fernandes".capitalize() ==> Answers "Javier
Fernandes"
charAt (index) native Answers the char value at the speci ed index. An index
ranges
from 0 to length() - 1. The rst char value of the sequence is
at index 0, the next at index 1, and so on, as for array
indexing.
Parameter index must be a positive integer value.
contains (other) native Answers whether this string contains the speci ed
sequence of char values.
It is a case sensitive test.
Examples:
"unusual".contains("usual") ==> Answers true
"become".contains("CO") ==> Answers false
Examples:
"caption".drop(4) ==> Answers "ion"
"caption".drop(0) ==> Answers "caption"
"caption".drop(-1) ==> Throws error
"".drop(2) ==> Answers ""
endsWith (other) native Tests if this string ends with the speci ed suf x.
It is case sensitive.
see startsWith
indexOf (other) native Answers the index within this string of the rst occurrence
of the speci ed character.
If character is not present, Answers -1
Examples:
"pototo".indexOf("o") ==> Answers 1
"unpredictable".indexOf("o") ==> Answers -1
lastIndexOf (other) Answers the index within this string of the last
native occurrence of the speci ed character.
If character is not present, Answers -1
Examples:
"pototo".lastIndexOf("o") ==> Answers 5
"unpredictable".lastIndexOf("o") ==> Answers -1
Example:
"stupid is what stupid does".replace("stupid", "genius")
==> Answers "genius is what genius does"
split (expression) Splits this string around matches of the given string.
Answers a list of strings.
Example:
"this,could,be,a,list".split(",")
==> Answers ["this", "could", "be", "a", "list"]
startsWith (other) Tests if this string starts with the speci ed pre x.
https://www.wollok.org/documentacion/wollokdoc/ I i i i 33/42
12/11/2018 WollokDoc · Wollok
native It is case sensitive.
Method Description
Examples:
"mother".startsWith("moth") ==> Answers true
"mother".startsWith("Moth") ==> Answers false
Examples:
"substitute".substring(6) ==> Answers "tute", second "t" is in
position 6
"effect".substring(0) ==> Answers "effect", has no effect at all
Examples:
"walking".substring(2, 4) ==> Answers "lk"
"walking".substring(3, 5) ==> Answers "ki"
"walking".substring(0, 5) ==> Answers "walki"
"walking".substring(0, 45) ==> throws an out of range
exception
Examples:
"lowercase".take(3) ==> Answers "low"
"lowercase".take(0) ==> Answers ""
"lowercase".take(-1) ==> Throws error
"".take(2) ==> Answers ""
toLowerCase () native Converts all of the characters in this String to lower case
Examples:
"Fer".toLowerCase() ==> Answers "fer"
"".toLowerCase() ==> Answers ""
toSmartString private
(alreadyShown) native
toUpperCase () native Converts all of the characters in this String to upper case
https://www.wollok.org/documentacion/wollokdoc/ 34/42
12/11/2018 WollokDoc · Wollok
Method Description
Examples:
"Fer".toUpperCase() ==> Answers "FER"
"".toUpperCase() ==> Answers ""
Example:
" emptySpace ".trim() ==> "emptySpace"
Examples:
"how does words work?".words()
==> Answers ["how", "does", "words", "work?"]
Boolean
Represents a Boolean value (true or false)
author jfernandes
noInstantiate
Behavior
Method Description
and (other) native Answers the result of applying the logical AND operator
to the speci ed boolean operands self and other
toSmartString private
( l d Sh )
https://www.wollok.org/documentacion/wollokdoc/ 35/42
12/11/2018 WollokDoc · Wollok
(alreadyShown) native
Method Description
toString () native Answers a String object representing this Boolean's value.
Range
Represents a nite arithmetic progression
of integer numbers with optional step
If start = 1, end = 8, Range will represent [1, 2, 3, 4, 5, 6, 7, 8]
If start = 1, end = 8, step = 3, Range will represent [1, 4, 7]
author jfernandes
since 1.3
Constructors
constructor(_start, _end)
Instantiates a Range.
Both _start and _end must be integer values.
Behavior
Method Description
Example:
new Range(1, 3).anyOne() ==> Answers 1 or 2 or 3
asList () private
Examples:
new Range(2, 5).contains(4) ==> Answers true
new Range(2, 5).contains(0) ==> Answers false
count (closure) Counts how many elements match the boolean closure
https://www.wollok.org/documentacion/wollokdoc/ 36/42
12/11/2018 WollokDoc · Wollok
Method Description
Example:
(1..9).count({ i => i.even() }) ==> Answers 4 (2, 4, 6 and 8 are
even)
forEach (closure) native Iterates over a Range from start to end, based on step.
Example:
new Range(1, 3).forEach { value => console.println(value) }
=> prints 1, 2, 3
internalToSmartString private
(alreadyShown)
Example:
(1..10).map({ n => n * 2}) ==> Answers [2, 4, 6, 8, 10, 12, 14, 16, 18,
20]
Method Description
Examples:
new Range(0, 2).size() ==> Answers 3
new Range(-2, 2).size() ==> Answers 5
sum (closure) Sums all elements that match the boolean closure
Example:
(1..9).sum({ i => if (i.even()) i else 0 }) ==> Answers 20
Closure
Represents an executable piece of code. You can create a closure,
assign it to a reference, evaluate it many times,
send it as parameter to another object, and many useful things.
author jfernandes
since 1.3
noInstantiate
Behavior
Method Description
Date
Represents a Date (without time). A Date is immutable, once created you can not
change it.
https://www.wollok.org/documentacion/wollokdoc/ 38/42
12/11/2018 WollokDoc · Wollok
since 1.4.5
Constructors
constructor()
Default constructor instantiates the current day
Behavior
Method Description
Examples:
new Date().plusDays(4) - new Date() ==> Answers 4
new Date() - new Date().plusDays(2) ==> Answers -2
<= (_aDate)
== (_aDate) native Two dates are equals if they represent the same date
>= (_aDate)
between (_startDate, Answers whether self is between two dates (both inclusive
_endDate) comparison)
Example:
new Date(2, 4, 2018).between(new Date(1, 4, 2018), new
Date(2, 4, 2018))
==> Answers true
Example:
new Date(12, 7, 2019).day() ==> Answers 12
Example:
new Date(24, 2, 2018).dayOfWeek() ==> Answers 6
(SATURDAY)
isLeapYear () native Checks if the year is a leap year, like 2000, 2004, 2008...
Example:
new Date(12, 5, 2018).isLeapYear() ==> Answers false
minusDays (_days) Answers a copy of this date with the speci ed number of
native days subtracted.
This instance is immutable and unaffected by this method
call.
Parameter must be an integer value.
This operation has no side effect (a new date is returned).
Examples:
new Date(1, 1, 2009).minusDays(1)
==> Answers a Date[day = 31, month = 12, year = 2008], a day
back
minusMonths (_months) Answers a copy of this date with the speci ed number of
https://www.wollok.org/documentacion/wollokdoc/ h b d 40/42
12/11/2018 WollokDoc · Wollok
native months subtracted.
Method Description
Parameter must be an integer value.
This operation has no side effect (a new date is returned).
Examples:
new Date(1, 1, 2009).minusMonths(1)
==> Answers a Date[day = 1, month = 12, year = 2008], a
month back
minusYears (_years) Answers a copy of this date with the speci ed number of
native years subtracted.
Parameter must be an integer value.
This operation has no side effect (a new date is returned).
Examples:
new Date(1, 1, 2009).minusYears(1)
==> Answers a Date[day = 1, month = 1, year = 2008], a year
back
Example:
new Date(12, 7, 2019).month() ==> Answers 7
plusDays (_days) native Answers a copy of this Date with the speci ed number of
days added.
Parameter must be an integer value.
This operation has no side effect (a new date is returned).
Example:
new Date(12, 5, 2018).plusDays(1)
==> Answers a Date[day = 13, month = 5, year = 2018], a day
forward
plusMonths (_months) Answers a copy of this Date with the speci ed number of
https://www.wollok.org/documentacion/wollokdoc/ h dd d 41/42
12/11/2018 WollokDoc · Wollok
native months added.
Method Description
Parameter must be an integer value.
This operation has no side effect (a new date is returned).
Example:
new Date(31, 1, 2018).plusMonths(1)
==> Answers a Date[day = 28, month = 2, year = 2018], a
month forward
plusYears (_years) native Answers a copy of this Date with the speci ed number of
years added.
Parameter must be an integer value.
This operation has no side effect (a new date is returned).
Example:
new Date(31, 1, 2018).plusYears(1)
==> Answers a Date[day = 31, month = 1, year = 2019], a year
forward
Example:
new Date(12, 7, 2019).year() ==> Answers 2019
https://www.wollok.org/documentacion/wollokdoc/ 42/42