Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Utils.vala « src - github.com/jangernert/FeedReader.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c9c9a4ae281f73f8f3b69d730f20f9de3be9fe9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
 * libdecsync-vala - Utils.vala
 *
 * Copyright (C) 2018 Aldo Gunsing
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, see <http://www.gnu.org/licenses/>.
 */

public Gee.List<string> toList(string[] input)
{
	return new Gee.ArrayList<string>.wrap(input);
}

public Gee.Predicate<Json.Node> stringEquals(string input)
{
    return json => {
        return json.get_string() == input;
    };
}

public Json.Node boolToNode(bool input)
{
	var node = new Json.Node(Json.NodeType.VALUE);
	node.set_boolean(input);
	return node;
}

public Json.Node stringToNode(string? input)
{
	Json.Node node;
	if (input == null) {
		node = new Json.Node(Json.NodeType.NULL);
	} else {
		node = new Json.Node(Json.NodeType.VALUE);
		node.set_string(input);
	}
	return node;
}

public Json.Node objectToNode(Json.Object input)
{
	var node = new Json.Node(Json.NodeType.OBJECT);
	node.set_object(input);
	return node;
}

public Gee.MultiMap<K, V> groupBy<T, K, V>(Gee.Collection<T> inputs, Gee.MapFunc<K, T> k, Gee.MapFunc<V, T>? f = null)
{
	var resultsMap = new Gee.HashMultiMap<K, V>();
	foreach (var input in inputs)
	{
		var key = k(input);
		var value = f == null ? input : f(input);
		resultsMap.@set(key, value);
	}

	return resultsMap;
}