/**
 * Copyright (c) 2016-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */ import * as Immutable from 'immutable' ; import * as Maybe from './maybe' ; export interface Map < K , V > { map : Immutable . Map < K , V > ; } export function Empty < K , V > ( ) { return { map : Immutable . Map < K , V > ( ) } ; } export function Map < K , V > ( array ) { return { map : Immutable . Map < K , V > ( array ) } ; } export function get < K , V > ( key , map ) { const immutableMap = map . map ; const value = immutableMap . get ( key ) ; return value ? value : null ; } function returnTrue ( ) { return true ; } function returnFalse ( ) { return false ; } export function containsKey < K , V > ( key , map ) { return Maybe . match ( returnTrue , returnFalse , get ( key , map ) ) ; } export function insert < K , V > ( key , value , map ) { const newMap = map . map . set ( key , value ) ; return { map : newMap } ; } export function remove < K , V > ( key , map ) { const newMap = map . map . remove ( key ) ; return { map : newMap } ; } export function foldl < K , V , R > ( f , initialValue , map ) { var currentValue = initialValue ; const immutableMap = map . map ; immutableMap . forEach ( function ( value ? , key ? ) { if ( value != undefined && key != undefined ) { currentValue = f ( currentValue , key , value ) ; } } ) ; return currentValue ; }